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.

AbstractEmptyExtendingClassGenerator::generate()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 0
dl 0
loc 30
ccs 18
cts 18
cp 1
crap 3
rs 9.44
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
abstract class AbstractEmptyExtendingClassGenerator implements FileGeneratorInterface
10
{
11
    /**
12
     * @var array
13
     */
14
    protected $yaml;
15
16
    /**
17
     * InterfaceGenerator constructor.
18
     * @param array $yaml
19
     */
20 1
    public function __construct(array $yaml)
21
    {
22 1
        $this->yaml = $yaml;
23 1
    }
24
25
    /**
26
     * @return string
27
     */
28 1 View Code Duplication
    public function getFilename(): string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
29
    {
30 1
        $classChunks = explode('\\', $this->yaml['class']);
31 1
        $className = array_pop($classChunks);
32 1
        $className = 'Empty' . $className;
33 1
        $namespace = '';
34 1
        if (count($classChunks) > 0) {
35 1
            $namespace .= '\\' . implode('\\', $classChunks);
36 1
            $namespace = str_replace('\\\\', '\\', $namespace);
37
        }
38
39 1
        return $this->yaml['src']['path'] .
40 1
            DIRECTORY_SEPARATOR .
41
            static::NAMESPACE .
42 1
            DIRECTORY_SEPARATOR .
43 1
            str_replace(
44 1
                '\\',
45 1
                DIRECTORY_SEPARATOR,
46 1
                $namespace . '\\' . $className
47
            ) .
48 1
            '.php'
49
        ;
50
    }
51
52
    /**
53
     * @return Node
54
     */
55 1
    public function generate(): Node
56
    {
57 1
        $classChunks = explode('\\', $this->yaml['class']);
58 1
        $baseClass = array_pop($classChunks);
59 1
        $className = 'Empty' . $baseClass;
60 1
        $baseNamespace = $this->yaml['src']['namespace'];
61 1
        if (count($classChunks) > 0) {
62 1
            $baseNamespace .= '\\' . implode('\\', $classChunks);
63 1
            $baseNamespace = str_replace('\\\\', '\\', $baseNamespace);
64
        }
65
        $namespace = $this->yaml['src']['namespace'] . '\\' . static::NAMESPACE;
66 1
        if (count($classChunks) > 0) {
67 1
            $namespace .= '\\' . implode('\\', $classChunks);
68 1
            $namespace = str_replace('\\\\', '\\', $namespace);
69
        }
70
71 1
        $factory = new BuilderFactory();
72
73 1
        $stmt = $factory->namespace($namespace)->
74 1
            addStmt($factory->use($baseNamespace . '\\' . $className)->as('Base' . $className))->
75 1
            addStmt(
76 1
                $factory->class($className)
77 1
                ->extend('Base' . $className)
78
            )
79
        ;
80
81
        return $stmt
82 1
            ->getNode()
83
        ;
84
    }
85
}
86