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 (#199)
by joseph
21:04
created

EntityGenerator::setPrimaryKeyFieldTrait()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator;
4
5
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Action\CreateEntityAction;
6
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\NamespaceHelper;
7
use EdmondsCommerce\DoctrineStaticMeta\Config;
8
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\PrimaryKey\IdFieldTrait;
9
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\PrimaryKey\IntegerIdFieldTrait;
0 ignored issues
show
Bug introduced by
The type EdmondsCommerce\Doctrine...Key\IntegerIdFieldTrait was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\PrimaryKey\NonBinaryUuidFieldTrait;
11
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\PrimaryKey\UuidFieldTrait;
12
use EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException;
13
14
/**
15
 * Class EntityGenerator
16
 *
17
 * @package EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator
18
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
19
 */
20
class EntityGenerator
21
{
22
23
    /**
24
     * @var CreateEntityAction
25
     */
26
    private $action;
27
28
    public function __construct(
29
        CreateEntityAction $action,
30
        NamespaceHelper $namespaceHelper,
31
        Config $config
32
    ) {
33
        $this->action = $action;
34
        $this->setProjectRootNamespace($namespaceHelper->getProjectRootNamespaceFromComposerJson());
35
        $this->setPathToProjectRoot($config::getProjectRootDirectory());
36
    }
37
38
    /**
39
     * @param string $projectRootNamespace
40
     *
41
     * @return $this
42
     */
43
    public function setProjectRootNamespace(string $projectRootNamespace): self
44
    {
45
        $this->action->setProjectRootNamespace($projectRootNamespace);
46
47
        return $this;
48
    }
49
50
    /**
51
     * @param string $pathToProjectRoot
52
     *
53
     * @return $this
54
     * @throws \RuntimeException
55
     */
56
    public function setPathToProjectRoot(string $pathToProjectRoot): self
57
    {
58
        $realPath = \realpath($pathToProjectRoot);
59
        if (false === $realPath) {
60
            throw new \RuntimeException('Invalid path to project root ' . $pathToProjectRoot);
61
        }
62
        $this->action->setProjectRootDirectory($realPath);
63
64
        return $this;
65
    }
66
67
    /**
68
     * @param string $entityFqn
69
     * @param bool   $generateSpecificEntitySaver
70
     *
71
     * @return string absolute path to created entity file
72
     * @throws DoctrineStaticMetaException
73
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
74
     */
75
    public function generateEntity(
76
        string $entityFqn,
77
        bool $generateSpecificEntitySaver = false
78
    ): string {
79
        try {
80
            $this->action->setEntityFqn($entityFqn);
81
            $this->action->setGenerateSaver($generateSpecificEntitySaver);
82
            $this->action->run();
83
84
            return $this->action->getCreatedEntityFilePath();
85
        } catch (\Exception $e) {
86
            throw new DoctrineStaticMetaException(
87
                'Exception in ' . __METHOD__ . ': ' . $e->getMessage(),
88
                $e->getCode(),
89
                $e
90
            );
91
        }
92
    }
93
94
    /**
95
     * @param int $idType
96
     *
97
     * @return EntityGenerator
98
     * @deprecated
99
     * @see setPrimaryKeyFieldTrait
100
     */
101
    public function setPrimaryKeyType(int $idType): self
102
    {
103
        switch ($idType) {
104
            case 1:
105
                return $this->setPrimaryKeyFieldTrait(IdFieldTrait::class);
106
            case 4:
107
                return $this->setPrimaryKeyFieldTrait(NonBinaryUuidFieldTrait::class);
108
            case 8:
109
                return $this->setPrimaryKeyFieldTrait(UuidFieldTrait::class);
110
            default:
111
                throw new \LogicException('Unknown trait selected');
112
        }
113
    }
114
115
    public function setPrimaryKeyFieldTrait(string $primaryKeyTraitFqn): self
116
    {
117
        $this->action->setPrimaryKeyTraitFqn($primaryKeyTraitFqn);
118
119
        return $this;
120
    }
121
}
122