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

AsyncClassGenerator::generate()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 40
Code Lines 25

Duplication

Lines 4
Ratio 10 %

Code Coverage

Tests 24
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 25
nc 2
nop 0
dl 4
loc 40
ccs 24
cts 24
cp 1
crap 2
rs 8.8571
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Tools\ResourceGenerator\FileGenerators;
4
5
use ApiClients\Tools\ResourceGenerator\FileGeneratorInterface;
6
use PhpParser\BuilderFactory;
7
use PhpParser\Node;
8
9
final class AsyncClassGenerator extends AbstractExtendingClassGenerator implements FileGeneratorInterface
10
{
11
    const NAMESPACE = 'Async';
12
13
    /**
14
     * @return Node
15
     */
16 1
    public function generate(): Node
17
    {
18 1
        $classChunks = explode('\\', $this->yaml['class']);
19 1
        $className = array_pop($classChunks);
20
        $namespace = $this->yaml['src']['namespace'] . '\\' . static::NAMESPACE;
21 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...
22 1
            $namespace .= '\\' . implode('\\', $classChunks);
23 1
            $namespace = str_replace('\\\\', '\\', $namespace);
24
        }
25 1
        $baseClass = $this->yaml['src']['namespace'] . '\\' . $this->yaml['class'];
26
27 1
        $factory = new BuilderFactory();
28
29 1
        $class = $factory->class($className)
30 1
            ->extend('Base' . $className);
31
32 1
        $class->addStmt(
33 1
            $factory->method('refresh')
34 1
                ->makePublic()
35 1
                ->setReturnType($className)
36 1
                ->addStmt(
37 1
                    new Node\Stmt\Throw_(
38 1
                        new Node\Expr\New_(
39 1
                            new Node\Name('\Exception'),
40
                            [
0 ignored issues
show
Documentation introduced by
array(new \PhpParser\Nod...eate refresh method!')) is of type array<integer,object<Php...de\\Scalar\\String_>"}>, 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...
41 1
                                new Node\Scalar\String_(
42 1
                                    'TODO: create refresh method!'
43
                                )
44
                            ]
45
                        )
46
                    )
47
                )
48
        );
49
50 1
        return $factory->namespace($namespace)
51 1
            ->addStmt($factory->use($baseClass)->as('Base' . $className))
52 1
            ->addStmt($class)
53 1
            ->getNode()
54
            ;
55
    }
56
}
57