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 ( cb99ed...fe9772 )
by Cees-Jan
10s
created

SyncClassGenerator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 90
Duplicated Lines 4.44 %

Coupling/Cohesion

Components 1
Dependencies 15

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 4
loc 90
ccs 46
cts 46
cp 1
rs 9.1666
c 1
b 0
f 0
wmc 2
lcom 1
cbo 15

1 Method

Rating   Name   Duplication   Size   Complexity  
B generate() 4 82 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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...me)), 'refresh')))))))) 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
                                new Node\Expr\MethodCall(
47 1
                                    new Node\Expr\Variable('this'),
48 1
                                    'handleCommand',
49
                                    [
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...
50 1
                                        new Node\Expr\New_(
51 1
                                            new Node\Name('BuildAsyncFromSyncCommand'),
52
                                            [
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...
53 1
                                                new Node\Expr\ClassConstFetch(
54 1
                                                    new Node\Name('self'),
55 1
                                                    'HYDRATE_CLASS'
56
                                                ),
57 1
                                                new Node\Expr\Variable('this'),
58
                                            ]
59
                                        ),
60
                                    ]
61
                                ),
62 1
                                'then',
63
                                [
0 ignored issues
show
Documentation introduced by
array(new \PhpParser\Nod...Name)), 'refresh')))))) 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...
64 1
                                    new Node\Expr\Closure(
65
                                        [
66
                                            'params' => [
67 1
                                                new Node\Param(
68 1
                                                    Inflector::camelize($className),
69 1
                                                    null,
70
                                                    $interfaceName
71
                                                )
72
                                            ],
73
                                            'stmts' => [
74 1
                                                new Node\Stmt\Return_(
75 1
                                                    new Node\Expr\MethodCall(
76 1
                                                        new Node\Expr\Variable(
77 1
                                                            Inflector::camelize($className)
78
                                                        ),
79 1
                                                        'refresh'
80
                                                    )
81
                                                )
82
                                            ],
83
                                        ]
84
                                    )
85
                                ]
86
                            ),
87
                        ]
88
                    )
89
                )
90
            ));
91
92 1
        return $factory->namespace($namespace)
93 1
            ->addStmt($factory->use(BuildAsyncFromSyncCommand::class))
94 1
            ->addStmt($factory->use($baseClass)->as('Base' . $className))
95 1
            ->addStmt($factory->use($interfaceFQName))
96 1
            ->addStmt($class)
97 1
            ->getNode()
98
            ;
99
    }
100
}
101