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 ( 75bdf9...8faa57 )
by joseph
83:56 queued 81:04
created

ReplaceEntitiesSubNamespaceProcess::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 5
cp 0.8
crap 2.032
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Creation\Process;
4
5
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Filesystem\File;
6
7
/**
8
 * This process handles updating the namespace for deeply nested Entities,
9
 * eg ones that are not in the root Entities namespace
10
 */
11
class ReplaceEntitiesSubNamespaceProcess implements ProcessInterface
12
{
13
    /**
14
     * @var string|null
15
     */
16
    private $entitySubNamespace;
17
18 3
    public function setEntityFqn(string $entityFqn)
19
    {
20 3
        if (false === \ts\stringContains($entityFqn, '\\Entities\\')) {
21 1
            throw new \RuntimeException(
22 1
                'This does not look like an Entity FQN: ' . $entityFqn
23
            );
24
        }
25 2
        $this->setEntitySubNamespaceFromEntityFqn($entityFqn);
26
27 2
        return $this;
28
    }
29
30 2
    private function setEntitySubNamespaceFromEntityFqn(string $entityFqn): void
31
    {
32 2
        $fromEntities = substr($entityFqn, \ts\strpos($entityFqn, '\\Entities\\'));
33 2
        $exploded     = explode('\\', $fromEntities);
34 2
        array_pop($exploded);
35 2
        array_shift($exploded);
36 2
        array_shift($exploded);
37 2
        $exploded = array_filter($exploded);
38 2
        if ([] === $exploded) {
39
            return;
40
        }
41 2
        $this->entitySubNamespace = implode('\\', $exploded);
42 2
    }
43
44 2
    public function run(File\FindReplace $findReplace): void
45
    {
46 2
        if (null === $this->entitySubNamespace) {
47
            return;
48
        }
49 2
        $this->replaceEntities($findReplace);
50 2
        $this->replaceEntity($findReplace);
51 2
    }
52
53 2
    private function replaceEntities(File\FindReplace $findReplace): void
54
    {
55 2
        $pattern     = $findReplace->convertForwardSlashesToBackSlashes('%/Entities(/|;)(?!Abstract)%');
56 2
        $replacement = '\\Entities\\' . $this->entitySubNamespace . '$1';
57 2
        $findReplace->findReplaceRegex($pattern, $replacement);
58 2
    }
59
60 2
    private function replaceEntity(File\FindReplace $findReplace)
61
    {
62 2
        $pattern     = $findReplace->convertForwardSlashesToBackSlashes(
63 2
            '%(.+?)/Entity/([^/]+?)(/|;)(?!Fixtures)(?!Abstract)%'
64
        );
65 2
        $replacement = '$1\\Entity\\\$2\\' . $this->entitySubNamespace . '$3';
66 2
        $findReplace->findReplaceRegex($pattern, $replacement);
67 2
    }
68
}
69