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   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 93.94%

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 56
ccs 31
cts 33
cp 0.9394
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 7 2
A setEntityFqn() 0 10 2
A setEntitySubNamespaceFromEntityFqn() 0 12 2
A replaceEntities() 0 5 1
A replaceEntity() 0 7 1
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