PHPackages                             bfg/comcode - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. bfg/comcode

ActiveBfg-app

bfg/comcode
===========

2.0.0(1y ago)012312MITPHPPHP ^8.0|^8.1|^8.2|^8.3|^8.4CI failing

Since May 29Pushed 1y ago2 watchersCompare

[ Source](https://github.com/bfg-s/comcode)[ Packagist](https://packagist.org/packages/bfg/comcode)[ RSS](/packages/bfg-comcode/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (54)Used By (2)

ComCode
=======

[](#comcode)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/533e388c9194246314a70b46a7a0407e5ebec72f3c9705ea732dcc96b4af9f5e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6266672f636f6d636f64652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bfg/comcode)

Install
-------

[](#install)

```
composer require bfg/comcode
```

Description
-----------

[](#description)

A special engine based on the [nikic/PHP-Parser](https://github.com/nikic/PHP-Parser)and [FriendsOfPHP/PHP-CS-Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer). This core describes the middle layer, this is neat control of the controlled nodes and the inviolability of its own.

Example
-------

[](#example)

```
use Bfg\Comcode\Comcode;
use Bfg\Comcode\Interfaces\AlwaysLastNodeInterface;
...
$class = php()->class(\Tests\TestedClass::class);
$class->extends(Comcode::class);
$class->implement(AlwaysLastNodeInterface::class);
$class->trait(Conditionable::class);
$class->protectedConst('const1', 1);
$class->protectedConst('const2', 1.1);
$class->protectedConst('const3', false);
$class->protectedConst('const3', ['success', 'error', 'warning']);

$class->publicProperty('array:tables', ['users', 'migrations']);
$class->protectedProperty('settings', false);
$class->privateProperty([Comcode::class, 'engine']);

$class->comment(function (DocSubject $docSubject) {
    $docSubject->description('Description of test class');
    $docSubject->tagMethod('static', 'get()');
});

$method1 = $class->protectedMethod('method1');

$method1->return()->real('text');

$method2 = $class->publicMethod('method2');

$method2->comment(function (DocSubject $doc) {
    $doc->name('Method 2');
    $doc->name('And him Description');
    $doc->tagReturn('string');
});

$method2->expectParams(['wait', Comcode::defineValueNode(null), Node::class]);

$method2->row('test row 1')
    ->var('wait')->assign('this')->methodWithProps(1, function (ClosureNode $q) {
        $q->expectParams(['param1', 'default text', 'string']);
        $q->row('inner test row 1')->var('param1')->concat(php()->real(' and true text'));
        $q->row('inner test row 2')->var('param1')->concat(php()->real(' and false text'));
        $q->return('param1');
    })->method()->property->someMethod()->methodWithProps(function (ClosureNode $q) {
        $q->row('inner test row 1.1')->var('param1')->assign(php()->real(100));
        $q->row('inner test row 1.2')->var('param1')->plus(php()->real(200));

        $q->return('param1')->func('func', function (ClosureNode $node) {
            $node->row('inner test row 1.2.1')->var('name')->concat(php()->real(' Xsaven'));
            $node->expectParams('name')->return('name');
        });
    }, fn(ClosureNode $node) => $node->expectParams('name')->return()->var('name'));

$method2->return('wait');

$method3 = $class->protectedMethod('method3');
$method3->comment('// Simple comment for method 3');

$method3->row('test row 1')
    ->var('text')
    ->assign('this')->property;

$method3->row('test row 2')
    ->var('text')
    ->plus(
        php()->real(2)
    );

$method3->row('test row 3')
    ->var('text')
    ->minus(
        php()->real(33)
    );

$method3->row('test row 4')
    ->var('text')
    ->concat(
        php()->real(2311)
    );

$method3->row('test row 5')
    ->var('text')
    ->plus(
        php()->real(1223)
    );

$method3->row('test row 6')
    ->var('text')
    ->minus(
        php()->real(311)
    );

$method3->row('test row 7')
    ->var('text')
    ->plus(
        php()->real(400)
    );

$method3->row('test row 8')
    ->var('text')
    ->plus(
        php()->real(100)
    );

$method3->return()->func('max', php('text'));

$class->save();
```

Result
------

[](#result)

```
