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

AbstractEmptyExtendingClassGenerator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 15.79 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 12
loc 76
ccs 37
cts 37
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFilename() 4 22 2
B generate() 8 30 3

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\Resource\EmptyResourceInterface;
6
use ApiClients\Tools\ResourceGenerator\FileGeneratorInterface;
7
use Doctrine\Common\Inflector\Inflector;
8
use PhpParser\BuilderFactory;
9
use PhpParser\Node;
10
use function ApiClients\Tools\ResourceGenerator\exists;
11
12
abstract class AbstractEmptyExtendingClassGenerator implements FileGeneratorInterface
13
{
14
    /**
15
     * @var array
16
     */
17
    protected $yaml;
18
19
    /**
20
     * InterfaceGenerator constructor.
21
     * @param array $yaml
22
     */
23 1
    public function __construct(array $yaml)
24
    {
25 1
        $this->yaml = $yaml;
26 1
    }
27
28
    /**
29
     * @return string
30
     */
31 1
    public function getFilename(): string
32
    {
33 1
        $classChunks = explode('\\', $this->yaml['class']);
34 1
        $className = array_pop($classChunks);
35 1
        $className = 'Empty' . $className;
36 1
        $namespace = '';
37 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...
38 1
            $namespace .= '\\' . implode('\\', $classChunks);
39 1
            $namespace = str_replace('\\\\', '\\', $namespace);
40
        }
41 1
        return $this->yaml['src']['path'] .
42 1
            DIRECTORY_SEPARATOR .
43
            static::NAMESPACE .
44 1
            DIRECTORY_SEPARATOR .
45 1
            str_replace(
46 1
                '\\',
47 1
                DIRECTORY_SEPARATOR,
48 1
                $namespace . '\\' . $className
49
            ) .
50 1
            '.php'
51
        ;
52
    }
53
54
    /**
55
     * @return Node
56
     */
57 1
    public function generate(): Node
58
    {
59 1
        $classChunks = explode('\\', $this->yaml['class']);
60 1
        $baseClass = array_pop($classChunks);
61 1
        $className = 'Empty' . $baseClass;
62 1
        $baseNamespace = $this->yaml['src']['namespace'];
63 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...
64 1
            $baseNamespace .= '\\' . implode('\\', $classChunks);
65 1
            $baseNamespace = str_replace('\\\\', '\\', $baseNamespace);
66
        }
67
        $namespace = $this->yaml['src']['namespace'] . '\\' . static::NAMESPACE;
68 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...
69 1
            $namespace .= '\\' . implode('\\', $classChunks);
70 1
            $namespace = str_replace('\\\\', '\\', $namespace);
71
        }
72
73 1
        $factory = new BuilderFactory();
74
75 1
        $stmt = $factory->namespace($namespace)->
76 1
            addStmt($factory->use($baseNamespace . '\\' . $className)->as('Base' . $className))->
77 1
            addStmt(
78 1
                $factory->class($className)
79 1
                ->extend('Base' . $className)
80
            )
81
        ;
82
83
        return $stmt
84 1
            ->getNode()
85
        ;
86
    }
87
}
88