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
Pull Request — master (#209)
by joseph
22:34
created

CreateDtosForAllEntitiesAction   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 66
ccs 0
cts 40
cp 0
rs 10
c 0
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 7 2
A setProjectRootDirectory() 0 6 1
A setProjectRootNamespace() 0 6 1
A findAllEntityFqns() 0 15 2
A __construct() 0 4 1
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Action;
4
5
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Creation\Src\Entity\DataTransferObjects\DtoCreator;
6
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\NamespaceHelper;
7
use Symfony\Component\Finder\Finder;
8
9
class CreateDtosForAllEntitiesAction implements ActionInterface
10
{
11
    /**
12
     * @var DtoCreator
13
     */
14
    private $dataTransferObjectCreator;
15
    /**
16
     * @var string
17
     */
18
    private $projectRootNamespace;
19
    /**
20
     * @var string
21
     */
22
    private $projectRootDirectory;
23
    /**
24
     * @var NamespaceHelper
25
     */
26
    private $namespaceHelper;
27
28
    public function __construct(DtoCreator $dataTransferObjectCreator, NamespaceHelper $namespaceHelper)
29
    {
30
        $this->dataTransferObjectCreator = $dataTransferObjectCreator;
31
        $this->namespaceHelper           = $namespaceHelper;
32
    }
33
34
    public function run(): void
35
    {
36
        $entityFqns = $this->findAllEntityFqns();
37
        foreach ($entityFqns as $entityFqn) {
38
            $this->dataTransferObjectCreator->setNewObjectFqnFromEntityFqn($entityFqn)
39
                                            ->createTargetFileObject()
40
                                            ->write();
41
        }
42
    }
43
44
    private function findAllEntityFqns()
45
    {
46
        $finder = new Finder();
47
        $finder->files()->in($this->projectRootDirectory . '/src/Entities')->name('*.php');
48
        $entityFqns = [];
49
        foreach ($finder as $splFileInfo) {
50
            $path         = $splFileInfo->getRealPath();
51
            $subPath      = \substr($path, \strpos($path, '/src/Entities/') + \strlen('/src/Entities/'));
52
            $subPath      = \str_replace('.php', '', $subPath);
53
            $entityFqns[] = $this->namespaceHelper->tidy(
54
                $this->projectRootNamespace . '\\Entities\\' . \str_replace('/', '\\', $subPath)
55
            );
56
        }
57
58
        return $entityFqns;
59
    }
60
61
    public function setProjectRootNamespace(string $projectRootNamespace): self
62
    {
63
        $this->projectRootNamespace = $projectRootNamespace;
64
        $this->dataTransferObjectCreator->setProjectRootNamespace($projectRootNamespace);
65
66
        return $this;
67
    }
68
69
    public function setProjectRootDirectory(string $projectRootDirectory): self
70
    {
71
        $this->projectRootDirectory = $projectRootDirectory;
72
        $this->dataTransferObjectCreator->setProjectRootDirectory($projectRootDirectory);
73
74
        return $this;
75
    }
76
}
77