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 — master ( d01879...32d13b )
by Cees-Jan
218:57 queued 215:38
created

SyncClassGenerator::generate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 50
Code Lines 31

Duplication

Lines 4
Ratio 8 %

Code Coverage

Tests 30
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 31
nc 2
nop 0
dl 4
loc 50
ccs 30
cts 30
cp 1
crap 2
rs 9.3333
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 PhpParser\BuilderFactory;
8
use PhpParser\Node;
9
10
final class SyncClassGenerator extends AbstractExtendingClassGenerator implements FileGeneratorInterface
11
{
12
    const NAMESPACE = 'Sync';
13
14
    /**
15
     * @return Node
16
     */
17 1
    public function generate(): Node
18
    {
19 1
        $classChunks = explode('\\', $this->yaml['class']);
20 1
        $className = array_pop($classChunks);
21
        $namespace = $this->yaml['src']['namespace'] . '\\' . static::NAMESPACE;
22 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...
23 1
            $namespace .= '\\' . implode('\\', $classChunks);
24 1
            $namespace = str_replace('\\\\', '\\', $namespace);
25
        }
26 1
        $baseClass = $this->yaml['src']['namespace'] . '\\' . $this->yaml['class'];
27
28 1
        $factory = new BuilderFactory();
29
30 1
        $class = $factory->class($className)
31 1
            ->extend('Base' . $className);
32
33 1
        $class->addStmt($factory->method('refresh')
34 1
            ->makePublic()
35 1
            ->setReturnType($className)
36 1
            ->addStmt(
37 1
                new Node\Stmt\Return_(
38 1
                    new Node\Expr\MethodCall(
39 1
                        new Node\Expr\Variable('this'),
40 1
                        'wait',
41
                        [
0 ignored issues
show
Documentation introduced by
array(new \PhpParser\Nod...r\Variable('this')))))) 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...
42 1
                            new Node\Expr\MethodCall(
43 1
                                new Node\Expr\Variable('this'),
44 1
                                'handleCommand',
45
                                [
0 ignored issues
show
Documentation introduced by
array(new \PhpParser\Nod...xpr\Variable('this')))) 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...
46 1
                                    new Node\Expr\New_(
47 1
                                        new Node\Name('BuildAsyncFromSyncCommand'),
48
                                        [
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...
49 1
                                            new Node\Scalar\String_($this->yaml['class']),
50 1
                                            new Node\Expr\Variable('this'),
51
                                        ]
52
                                    ),
53
                                ]
54
                            ),
55
                        ]
56
                    )
57
                )
58
            ));
59
60 1
        return $factory->namespace($namespace)
61 1
            ->addStmt($factory->use(BuildAsyncFromSyncCommand::class))
62 1
            ->addStmt($factory->use($baseClass)->as('Base' . $className))
63 1
            ->addStmt($class)
64 1
            ->getNode()
65
            ;
66
    }
67
}
68