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.

AbstractEmptyExtendingTestGenerator::generate()   B
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 57

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 36
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 0
dl 0
loc 57
ccs 36
cts 36
cp 1
crap 3
rs 8.9381
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\Tools\ResourceGenerator\FileGeneratorInterface;
6
use ApiClients\Tools\ResourceTestUtilities\AbstractEmptyResourceTest;
7
use PhpParser\BuilderFactory;
8
use PhpParser\Node;
9
10
abstract class AbstractEmptyExtendingTestGenerator implements FileGeneratorInterface
11
{
12
    /**
13
     * @var array
14
     */
15
    protected $yaml;
16
17
    /**
18
     * InterfaceGenerator constructor.
19
     * @param array $yaml
20
     */
21 1
    public function __construct(array $yaml)
22
    {
23 1
        $this->yaml = $yaml;
24 1
    }
25
26
    /**
27
     * @return string
28
     */
29 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...
30
    {
31 1
        $classChunks = explode('\\', $this->yaml['class']);
32 1
        $className = array_pop($classChunks);
33 1
        $className = 'Empty' . $className;
34 1
        $namespace = '';
35 1
        if (count($classChunks) > 0) {
36 1
            $namespace .= '\\' . implode('\\', $classChunks);
37 1
            $namespace = str_replace('\\\\', '\\', $namespace);
38
        }
39
40 1
        return $this->yaml['tests']['path'] .
41 1
            DIRECTORY_SEPARATOR .
42
            static::NAMESPACE .
43 1
            DIRECTORY_SEPARATOR .
44 1
            str_replace(
45 1
                '\\',
46 1
                DIRECTORY_SEPARATOR,
47 1
                $namespace . '\\' . $className
48
            ) .
49 1
            'Test.php'
50
        ;
51
    }
52
53
    /**
54
     * @return Node
55
     */
56 1
    public function generate(): Node
57
    {
58 1
        $emptyClassChunks = explode('\\', $this->yaml['class']);
59 1
        $emptyBaseClass = array_pop($emptyClassChunks);
60 1
        $emptyClassName = 'Empty' . $emptyBaseClass;
61
        $emptyNamespace = $this->yaml['src']['namespace'] . '\\' . static::NAMESPACE;
62 1
        if (count($emptyClassChunks) > 0) {
63 1
            $emptyNamespace .= '\\' . implode('\\', $emptyClassChunks);
64 1
            $emptyNamespace = str_replace('\\\\', '\\', $emptyNamespace);
65
        }
66
67 1
        $classChunks = explode('\\', $this->yaml['class']);
68 1
        $baseClass = array_pop($classChunks);
69 1
        $className = 'Empty' . $baseClass . 'Test';
70
        $namespace = $this->yaml['tests']['namespace'] . '\\' . static::NAMESPACE;
71 1
        if (count($classChunks) > 0) {
72 1
            $namespace .= '\\' . implode('\\', $classChunks);
73 1
            $namespace = str_replace('\\\\', '\\', $namespace);
74
        }
75
76 1
        $factory = new BuilderFactory();
77
78 1
        $class = $factory->class($className)
79 1
            ->makeFinal()
80 1
            ->extend('AbstractEmptyResourceTest');
81
82 1
        $class->addStmt($factory->method('getSyncAsync')
83 1
            ->makePublic()
84 1
            ->setReturnType('string')
85 1
            ->addStmt(
86 1
                new Node\Stmt\Return_(
87 1
                    new Node\Scalar\String_(
88
                        static::NAMESPACE
89
                    )
90
                )
91
            ));
92
93 1
        $class->addStmt($factory->method('getClass')
94 1
            ->makePublic()
95 1
            ->setReturnType('string')
96 1
            ->addStmt(
97 1
                new Node\Stmt\Return_(
98 1
                    new Node\Expr\ClassConstFetch(
99 1
                        new Node\Name($emptyClassName),
100 1
                        'class'
101
                    )
102
                )
103
            ));
104
105 1
        return $factory->namespace($namespace)
106 1
            ->addStmt($factory->use(AbstractEmptyResourceTest::class)->as('AbstractEmptyResourceTest'))
107 1
            ->addStmt($factory->use($emptyNamespace . '\\' . $emptyClassName)->as($emptyClassName))
108 1
            ->addStmt($class)
109
110 1
            ->getNode()
111
        ;
112
    }
113
}
114