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