GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — improvement-chop-down-code-x-m... ( 69d8d1 )
by Cees-Jan
02:08
created

SyncClassGenerator::callCommandBus()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 10
ccs 5
cts 5
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Tools\ResourceGenerator\FileGenerators;
4
5
use ApiClients\Foundation\Hydrator\CommandBus\Command\BuildAsyncFromSyncCommand;
6
use ApiClients\Tools\ResourceGenerator\FileGeneratorInterface;
7
use Doctrine\Common\Inflector\Inflector;
8
use PhpParser\BuilderFactory;
9
use PhpParser\Node;
10
11
final class SyncClassGenerator extends AbstractExtendingClassGenerator implements FileGeneratorInterface
12
{
13
    const NAMESPACE = 'Sync';
14
15
    /**
16
     * @return Node
17
     */
18 1
    public function generate(): Node
19
    {
20 1
        $classChunks = explode('\\', $this->yaml['class']);
21 1
        $className = array_pop($classChunks);
22 1
        $interfaceName = $className . 'Interface';
23
        $namespace = $this->yaml['src']['namespace'] . '\\' . static::NAMESPACE;
24 1 View Code Duplication
        if (count($classChunks) > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25 1
            $namespace .= '\\' . implode('\\', $classChunks);
26 1
            $namespace = str_replace('\\\\', '\\', $namespace);
27
        }
28 1
        $baseClass = $this->yaml['src']['namespace'] . '\\' . $this->yaml['class'];
29 1
        $interfaceFQName = $this->yaml['src']['namespace'] . '\\' . $this->yaml['class'] . 'Interface';
30
31 1
        $factory = new BuilderFactory();
32
33 1
        $class = $factory->class($className)
34 1
            ->extend('Base' . $className);
35
36 1
        $class->addStmt($factory->method('refresh')
37 1
            ->makePublic()
38 1
            ->setReturnType($className)
39 1
            ->addStmt(
40 1
                new Node\Stmt\Return_(
41 1
                    new Node\Expr\MethodCall(
42 1
                        new Node\Expr\Variable('this'),
43 1
                        'wait',
44
                        [
0 ignored issues
show
Documentation introduced by
array(new \PhpParser\Nod...ame, $interfaceName)))) is of type array<integer,object<Php...e\\Expr\\MethodCall>"}>, but the function expects a array<integer,object<PhpParser\Node\Arg>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
45 1
                            new Node\Expr\MethodCall(
46 1
                                $this->callCommandBus(),
47 1
                                'then',
48
                                [
0 ignored issues
show
Documentation introduced by
array($this->createRefre...sName, $interfaceName)) is of type array<integer,object<Php...Node\\Expr\\Closure>"}>, but the function expects a array<integer,object<PhpParser\Node\Arg>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
49 1
                                   $this->createRefreshClosure($className, $interfaceName),
50
                                ]
51
                            ),
52
                        ]
53
                    )
54
                )
55
            ));
56
57 1
        return $factory->namespace($namespace)
58 1
            ->addStmt($factory->use(BuildAsyncFromSyncCommand::class))
59 1
            ->addStmt($factory->use($baseClass)->as('Base' . $className))
60 1
            ->addStmt($factory->use($interfaceFQName))
61 1
            ->addStmt($class)
62 1
            ->getNode()
63
            ;
64
    }
65
66 1
    protected function callCommandBus(): Node\Expr\MethodCall
67
    {
68 1
        return new Node\Expr\MethodCall(
69 1
            new Node\Expr\Variable('this'),
70 1
            'handleCommand',
71
            [
0 ignored issues
show
Documentation introduced by
array($this->createCommand()) is of type array<integer,object<Php...r\\Node\\Expr\\New_>"}>, but the function expects a array<integer,object<PhpParser\Node\Arg>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
72 1
                $this->createCommand(),
73
            ]
74
        );
75
    }
76
77 1
    protected function createCommand(): Node\Expr\New_
78
    {
79 1
        return new Node\Expr\New_(
80 1
            new Node\Name('BuildAsyncFromSyncCommand'),
81
            [
0 ignored issues
show
Documentation introduced by
array(new \PhpParser\Nod...\Expr\Variable('this')) is of type array<integer,object<Php...ode\\Expr\\Variable>"}>, but the function expects a array<integer,object<PhpParser\Node\Arg>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
82 1
                new Node\Expr\ClassConstFetch(
83 1
                    new Node\Name('self'),
84 1
                    'HYDRATE_CLASS'
85
                ),
86 1
                new Node\Expr\Variable('this'),
87
            ]
88
        );
89
    }
90
91 1
    protected function createRefreshClosure(string $className, string $interfaceName): Node\Expr\Closure
92
    {
93 1
        return new Node\Expr\Closure(
94
            [
95
                'params' => [
96 1
                    new Node\Param(
97 1
                        Inflector::camelize($className),
98 1
                        null,
99
                        $interfaceName
100
                    )
101
                ],
102
                'stmts' => [
103 1
                    new Node\Stmt\Return_(
104 1
                        new Node\Expr\MethodCall(
105 1
                            new Node\Expr\Variable(
106 1
                                Inflector::camelize($className)
107
                            ),
108 1
                            'refresh'
109
                        )
110
                    )
111
                ],
112
            ]
113
        );
114
    }
115
}
116