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.

SyncClassGenerator::generate()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 82

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 47
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 82
ccs 47
cts 47
cp 1
crap 2
rs 8.3927
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
        if (count($classChunks) > 0) {
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
                        [
45 1
                            new Node\Expr\MethodCall(
46 1
                                new Node\Expr\MethodCall(
47 1
                                    new Node\Expr\Variable('this'),
48 1
                                    'handleCommand',
49
                                    [
50 1
                                        new Node\Expr\New_(
51 1
                                            new Node\Name('BuildAsyncFromSyncCommand'),
52
                                            [
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
                                [
64 1
                                    new Node\Expr\Closure(
65
                                        [
66
                                            'params' => [
67 1
                                                new Node\Param(
68 1
                                                    Inflector::camelize($className),
69 1
                                                    null,
70 1
                                                    $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