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.

AbstractExtendingTestGenerator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
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 ApiClients\Tools\ResourceTestUtilities\AbstractResourceTest;
7
use PhpParser\BuilderFactory;
8
use PhpParser\Node;
9
10
abstract class AbstractExtendingTestGenerator 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
        return $this->yaml['tests']['path'] .
32 1
            DIRECTORY_SEPARATOR .
33
            static::NAMESPACE .
34 1
            DIRECTORY_SEPARATOR .
35 1
            str_replace('\\', DIRECTORY_SEPARATOR, $this->yaml['class']) .
36 1
            'Test.php'
37
        ;
38
    }
39
40
    /**
41
     * @return Node
42
     */
43 1
    public function generate(): Node
44
    {
45 1
        $classChunks = explode('\\', $this->yaml['class']);
46 1
        $baseClass = array_pop($classChunks);
47 1
        $className = $baseClass . 'Test';
48
        $namespace = $this->yaml['tests']['namespace'] . '\\' . static::NAMESPACE;
49 1
        if (count($classChunks) > 0) {
50 1
            $namespace .= '\\' . implode('\\', $classChunks);
51 1
            $namespace = str_replace('\\\\', '\\', $namespace);
52
        }
53 1
        $baseClassFQCN = $this->yaml['src']['namespace'] . '\\' . $this->yaml['class'];
54
55 1
        $factory = new BuilderFactory();
56
57 1
        $class = $factory->class($className)
58 1
            ->extend('AbstractResourceTest');
59
60 1
        $class->addStmt($factory->method('getSyncAsync')
61 1
            ->makePublic()
62 1
            ->setReturnType('string')
63 1
            ->addStmt(
64 1
                new Node\Stmt\Return_(
65 1
                    new Node\Scalar\String_(
66
                        static::NAMESPACE
67
                    )
68
                )
69
            ));
70
71 1
        $class->addStmt($factory->method('getClass')
72 1
            ->makePublic()
73 1
            ->setReturnType('string')
74 1
            ->addStmt(
75 1
                new Node\Stmt\Return_(
76 1
                    new Node\Expr\ClassConstFetch(
77 1
                        new Node\Name($baseClass),
78 1
                        'class'
79
                    )
80
                )
81
            ));
82
83 1
        $class->addStmt($factory->method('getNamespace')
84 1
            ->makePublic()
85 1
            ->setReturnType('string')
86 1
            ->addStmt(
87 1
                new Node\Stmt\Return_(
88 1
                    new Node\Expr\ClassConstFetch(
89 1
                        new Node\Name('ApiSettings'),
90 1
                        'NAMESPACE'
91
                    )
92
                )
93
            ));
94
95 1
        return $factory->namespace($namespace)
96 1
            ->addStmt($factory->use(AbstractResourceTest::class)->as('AbstractResourceTest'))
97 1
            ->addStmt($factory->use($this->yaml['api_settings'])->as('ApiSettings'))
98 1
            ->addStmt($factory->use($baseClassFQCN)->as($baseClass))
99 1
            ->addStmt($class)
100
101 1
            ->getNode()
102
        ;
103
    }
104
}
105