@@ -18,7 +18,7 @@ |
||
18 | 18 | |
19 | 19 | public function __toString(): string |
20 | 20 | { |
21 | - if ($this->alias) { |
|
21 | + if ($this->alias){ |
|
22 | 22 | return \sprintf('%s as %s', $this->name, $this->alias); |
23 | 23 | } |
24 | 24 |
@@ -18,7 +18,8 @@ |
||
18 | 18 | |
19 | 19 | public function __toString(): string |
20 | 20 | { |
21 | - if ($this->alias) { |
|
21 | + if ($this->alias) |
|
22 | + { |
|
22 | 23 | return \sprintf('%s as %s', $this->name, $this->alias); |
23 | 24 | } |
24 | 25 |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | { |
12 | 12 | public function __construct( |
13 | 13 | private readonly Sequences $sequences |
14 | - ) { |
|
14 | + ){ |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | public function resolve(ClassNode $definition): void |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | |
33 | 33 | private function getReservedNamespacesWithAlias(ClassNode $definition, array $namespaces): array |
34 | 34 | { |
35 | - foreach ($definition->getStmts() as $stmt) { |
|
36 | - if (!$stmt->alias) { |
|
35 | + foreach ($definition->getStmts() as $stmt){ |
|
36 | + if (!$stmt->alias){ |
|
37 | 37 | continue; |
38 | 38 | } |
39 | 39 | |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | |
46 | 46 | private function getReservedNamespacesWithoutAlias(ClassNode $definition, array $namespaces): array |
47 | 47 | { |
48 | - foreach ($definition->getStmts() as $stmt) { |
|
49 | - if ($stmt->alias || isset($namespaces[$stmt->shortName])) { |
|
48 | + foreach ($definition->getStmts() as $stmt){ |
|
49 | + if ($stmt->alias || isset($namespaces[$stmt->shortName])){ |
|
50 | 50 | continue; |
51 | 51 | } |
52 | 52 | |
@@ -59,12 +59,12 @@ discard block |
||
59 | 59 | private function initiateCounters(array $namespaces): array |
60 | 60 | { |
61 | 61 | $counters = []; |
62 | - foreach ($namespaces as $shortName => $fullName) { |
|
62 | + foreach ($namespaces as $shortName => $fullName){ |
|
63 | 63 | $namespace = $this->parseNamespace($shortName, $fullName); |
64 | 64 | |
65 | - if (isset($counters[$namespace->name])) { |
|
65 | + if (isset($counters[$namespace->name])){ |
|
66 | 66 | $counters[$namespace->name][$namespace->sequence] = $namespace; |
67 | - } else { |
|
67 | + }else{ |
|
68 | 68 | $counters[$namespace->name] = [$namespace->sequence => $namespace]; |
69 | 69 | } |
70 | 70 | } |
@@ -74,52 +74,52 @@ discard block |
||
74 | 74 | |
75 | 75 | private function resolveImportsNamespaces(ClassNode $definition, array $counters): void |
76 | 76 | { |
77 | - if (!$definition->hasConstructor && $definition->constructorParams) { |
|
78 | - foreach ($definition->constructorParams as $param) { |
|
77 | + if (!$definition->hasConstructor && $definition->constructorParams){ |
|
78 | + foreach ($definition->constructorParams as $param){ |
|
79 | 79 | //no type (or type is internal), do nothing |
80 | - if (empty($param->type) || $param->isBuiltIn()) { |
|
80 | + if (empty($param->type) || $param->isBuiltIn()){ |
|
81 | 81 | continue; |
82 | 82 | } |
83 | 83 | |
84 | 84 | $namespace = $this->parseNamespaceFromType($param->type); |
85 | - if (isset($counters[$namespace->name])) { |
|
86 | - if ($this->getAlreadyImportedNamespace($counters[$namespace->name], $namespace)) { |
|
85 | + if (isset($counters[$namespace->name])){ |
|
86 | + if ($this->getAlreadyImportedNamespace($counters[$namespace->name], $namespace)){ |
|
87 | 87 | continue; |
88 | 88 | } |
89 | 89 | |
90 | 90 | $sequence = $this->sequences->find(\array_keys($counters[$namespace->name]), $namespace->sequence); |
91 | - if ($sequence !== $namespace->sequence) { |
|
91 | + if ($sequence !== $namespace->sequence){ |
|
92 | 92 | $namespace->sequence = $sequence; |
93 | 93 | |
94 | 94 | $param->type->alias = $namespace->fullName(); |
95 | 95 | } |
96 | 96 | |
97 | 97 | $counters[$namespace->name][$sequence] = $namespace; |
98 | - } else { |
|
98 | + }else{ |
|
99 | 99 | $counters[$namespace->name] = [$namespace->sequence => $namespace]; |
100 | 100 | } |
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
104 | - foreach ($definition->dependencies as $dependency) { |
|
104 | + foreach ($definition->dependencies as $dependency){ |
|
105 | 105 | $namespace = $this->parseNamespaceFromType($dependency->type); |
106 | - if (isset($counters[$namespace->name])) { |
|
106 | + if (isset($counters[$namespace->name])){ |
|
107 | 107 | $alreadyImported = $this->getAlreadyImportedNamespace($counters[$namespace->name], $namespace); |
108 | - if ($alreadyImported !== null) { |
|
108 | + if ($alreadyImported !== null){ |
|
109 | 109 | $dependency->type->alias = $alreadyImported->fullName(); |
110 | 110 | |
111 | 111 | continue; |
112 | 112 | } |
113 | 113 | |
114 | 114 | $sequence = $this->sequences->find(\array_keys($counters[$namespace->name]), $namespace->sequence); |
115 | - if ($sequence !== $namespace->sequence) { |
|
115 | + if ($sequence !== $namespace->sequence){ |
|
116 | 116 | $namespace->sequence = $sequence; |
117 | 117 | |
118 | 118 | $dependency->type->alias = $namespace->fullName(); |
119 | 119 | } |
120 | 120 | |
121 | 121 | $counters[$namespace->name][$sequence] = $namespace; |
122 | - } else { |
|
122 | + }else{ |
|
123 | 123 | $counters[$namespace->name] = [$namespace->sequence => $namespace]; |
124 | 124 | } |
125 | 125 | } |
@@ -130,8 +130,8 @@ discard block |
||
130 | 130 | */ |
131 | 131 | private function getAlreadyImportedNamespace(array $counters, NamespaceEntity $namespace): ?NamespaceEntity |
132 | 132 | { |
133 | - foreach ($counters as $counter) { |
|
134 | - if ($counter->equals($namespace)) { |
|
133 | + foreach ($counters as $counter){ |
|
134 | + if ($counter->equals($namespace)){ |
|
135 | 135 | return $counter; |
136 | 136 | } |
137 | 137 | } |
@@ -146,9 +146,9 @@ discard block |
||
146 | 146 | |
147 | 147 | private function parseNamespace(string $shortName, string $fullName): NamespaceEntity |
148 | 148 | { |
149 | - if (\preg_match("/\d+$/", $shortName, $match)) { |
|
149 | + if (\preg_match("/\d+$/", $shortName, $match)){ |
|
150 | 150 | $sequence = (int)$match[0]; |
151 | - if ($sequence > 0) { |
|
151 | + if ($sequence > 0){ |
|
152 | 152 | return NamespaceEntity::createWithSequence( |
153 | 153 | Utils::trimTrailingDigits($shortName, $sequence), |
154 | 154 | $fullName, |
@@ -32,8 +32,10 @@ discard block |
||
32 | 32 | |
33 | 33 | private function getReservedNamespacesWithAlias(ClassNode $definition, array $namespaces): array |
34 | 34 | { |
35 | - foreach ($definition->getStmts() as $stmt) { |
|
36 | - if (!$stmt->alias) { |
|
35 | + foreach ($definition->getStmts() as $stmt) |
|
36 | + { |
|
37 | + if (!$stmt->alias) |
|
38 | + { |
|
37 | 39 | continue; |
38 | 40 | } |
39 | 41 | |
@@ -45,8 +47,10 @@ discard block |
||
45 | 47 | |
46 | 48 | private function getReservedNamespacesWithoutAlias(ClassNode $definition, array $namespaces): array |
47 | 49 | { |
48 | - foreach ($definition->getStmts() as $stmt) { |
|
49 | - if ($stmt->alias || isset($namespaces[$stmt->shortName])) { |
|
50 | + foreach ($definition->getStmts() as $stmt) |
|
51 | + { |
|
52 | + if ($stmt->alias || isset($namespaces[$stmt->shortName])) |
|
53 | + { |
|
50 | 54 | continue; |
51 | 55 | } |
52 | 56 | |
@@ -59,12 +63,16 @@ discard block |
||
59 | 63 | private function initiateCounters(array $namespaces): array |
60 | 64 | { |
61 | 65 | $counters = []; |
62 | - foreach ($namespaces as $shortName => $fullName) { |
|
66 | + foreach ($namespaces as $shortName => $fullName) |
|
67 | + { |
|
63 | 68 | $namespace = $this->parseNamespace($shortName, $fullName); |
64 | 69 | |
65 | - if (isset($counters[$namespace->name])) { |
|
70 | + if (isset($counters[$namespace->name])) |
|
71 | + { |
|
66 | 72 | $counters[$namespace->name][$namespace->sequence] = $namespace; |
67 | - } else { |
|
73 | + } |
|
74 | + else |
|
75 | + { |
|
68 | 76 | $counters[$namespace->name] = [$namespace->sequence => $namespace]; |
69 | 77 | } |
70 | 78 | } |
@@ -74,52 +82,66 @@ discard block |
||
74 | 82 | |
75 | 83 | private function resolveImportsNamespaces(ClassNode $definition, array $counters): void |
76 | 84 | { |
77 | - if (!$definition->hasConstructor && $definition->constructorParams) { |
|
78 | - foreach ($definition->constructorParams as $param) { |
|
85 | + if (!$definition->hasConstructor && $definition->constructorParams) |
|
86 | + { |
|
87 | + foreach ($definition->constructorParams as $param) |
|
88 | + { |
|
79 | 89 | //no type (or type is internal), do nothing |
80 | - if (empty($param->type) || $param->isBuiltIn()) { |
|
90 | + if (empty($param->type) || $param->isBuiltIn()) |
|
91 | + { |
|
81 | 92 | continue; |
82 | 93 | } |
83 | 94 | |
84 | 95 | $namespace = $this->parseNamespaceFromType($param->type); |
85 | - if (isset($counters[$namespace->name])) { |
|
86 | - if ($this->getAlreadyImportedNamespace($counters[$namespace->name], $namespace)) { |
|
96 | + if (isset($counters[$namespace->name])) |
|
97 | + { |
|
98 | + if ($this->getAlreadyImportedNamespace($counters[$namespace->name], $namespace)) |
|
99 | + { |
|
87 | 100 | continue; |
88 | 101 | } |
89 | 102 | |
90 | 103 | $sequence = $this->sequences->find(\array_keys($counters[$namespace->name]), $namespace->sequence); |
91 | - if ($sequence !== $namespace->sequence) { |
|
104 | + if ($sequence !== $namespace->sequence) |
|
105 | + { |
|
92 | 106 | $namespace->sequence = $sequence; |
93 | 107 | |
94 | 108 | $param->type->alias = $namespace->fullName(); |
95 | 109 | } |
96 | 110 | |
97 | 111 | $counters[$namespace->name][$sequence] = $namespace; |
98 | - } else { |
|
112 | + } |
|
113 | + else |
|
114 | + { |
|
99 | 115 | $counters[$namespace->name] = [$namespace->sequence => $namespace]; |
100 | 116 | } |
101 | 117 | } |
102 | 118 | } |
103 | 119 | |
104 | - foreach ($definition->dependencies as $dependency) { |
|
120 | + foreach ($definition->dependencies as $dependency) |
|
121 | + { |
|
105 | 122 | $namespace = $this->parseNamespaceFromType($dependency->type); |
106 | - if (isset($counters[$namespace->name])) { |
|
123 | + if (isset($counters[$namespace->name])) |
|
124 | + { |
|
107 | 125 | $alreadyImported = $this->getAlreadyImportedNamespace($counters[$namespace->name], $namespace); |
108 | - if ($alreadyImported !== null) { |
|
126 | + if ($alreadyImported !== null) |
|
127 | + { |
|
109 | 128 | $dependency->type->alias = $alreadyImported->fullName(); |
110 | 129 | |
111 | 130 | continue; |
112 | 131 | } |
113 | 132 | |
114 | 133 | $sequence = $this->sequences->find(\array_keys($counters[$namespace->name]), $namespace->sequence); |
115 | - if ($sequence !== $namespace->sequence) { |
|
134 | + if ($sequence !== $namespace->sequence) |
|
135 | + { |
|
116 | 136 | $namespace->sequence = $sequence; |
117 | 137 | |
118 | 138 | $dependency->type->alias = $namespace->fullName(); |
119 | 139 | } |
120 | 140 | |
121 | 141 | $counters[$namespace->name][$sequence] = $namespace; |
122 | - } else { |
|
142 | + } |
|
143 | + else |
|
144 | + { |
|
123 | 145 | $counters[$namespace->name] = [$namespace->sequence => $namespace]; |
124 | 146 | } |
125 | 147 | } |
@@ -130,8 +152,10 @@ discard block |
||
130 | 152 | */ |
131 | 153 | private function getAlreadyImportedNamespace(array $counters, NamespaceEntity $namespace): ?NamespaceEntity |
132 | 154 | { |
133 | - foreach ($counters as $counter) { |
|
134 | - if ($counter->equals($namespace)) { |
|
155 | + foreach ($counters as $counter) |
|
156 | + { |
|
157 | + if ($counter->equals($namespace)) |
|
158 | + { |
|
135 | 159 | return $counter; |
136 | 160 | } |
137 | 161 | } |
@@ -146,9 +170,11 @@ discard block |
||
146 | 170 | |
147 | 171 | private function parseNamespace(string $shortName, string $fullName): NamespaceEntity |
148 | 172 | { |
149 | - if (\preg_match("/\d+$/", $shortName, $match)) { |
|
173 | + if (\preg_match("/\d+$/", $shortName, $match)) |
|
174 | + { |
|
150 | 175 | $sequence = (int)$match[0]; |
151 | - if ($sequence > 0) { |
|
176 | + if ($sequence > 0) |
|
177 | + { |
|
152 | 178 | return NamespaceEntity::createWithSequence( |
153 | 179 | Utils::trimTrailingDigits($shortName, $sequence), |
154 | 180 | $fullName, |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | { |
12 | 12 | public function __construct( |
13 | 13 | private readonly Sequences $sequences |
14 | - ) { |
|
14 | + ){ |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | public function resolve(ClassNode $definition): void |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | private function getConstructorReservedNames(ClassNode $definition): array |
26 | 26 | { |
27 | 27 | $names = \array_values($definition->constructorVars); |
28 | - foreach ($definition->constructorParams as $param) { |
|
28 | + foreach ($definition->constructorParams as $param){ |
|
29 | 29 | $names[] = $param->name; |
30 | 30 | } |
31 | 31 | |
@@ -35,12 +35,12 @@ discard block |
||
35 | 35 | private function initiateCounters(array $names): array |
36 | 36 | { |
37 | 37 | $counters = []; |
38 | - foreach ($names as $name) { |
|
38 | + foreach ($names as $name){ |
|
39 | 39 | $name = $this->parseName($name); |
40 | 40 | |
41 | - if (isset($counters[$name->name])) { |
|
41 | + if (isset($counters[$name->name])){ |
|
42 | 42 | $counters[$name->name][$name->sequence] = $name->fullName(); |
43 | - } else { |
|
43 | + }else{ |
|
44 | 44 | $counters[$name->name] = [$name->sequence => $name->fullName()]; |
45 | 45 | } |
46 | 46 | } |
@@ -50,18 +50,18 @@ discard block |
||
50 | 50 | |
51 | 51 | private function addPostfixes(ClassNode $definition, array $counters): void |
52 | 52 | { |
53 | - foreach ($definition->dependencies as $dependency) { |
|
53 | + foreach ($definition->dependencies as $dependency){ |
|
54 | 54 | $name = $this->parseName($dependency->var); |
55 | - if (isset($counters[$name->name])) { |
|
55 | + if (isset($counters[$name->name])){ |
|
56 | 56 | $sequence = $this->sequences->find(\array_keys($counters[$name->name]), $name->sequence); |
57 | - if ($sequence !== $name->sequence) { |
|
57 | + if ($sequence !== $name->sequence){ |
|
58 | 58 | $name->sequence = $sequence; |
59 | 59 | |
60 | 60 | $dependency->var = $name->fullName(); |
61 | 61 | } |
62 | 62 | |
63 | 63 | $counters[$name->name][$sequence] = $name->fullName(); |
64 | - } else { |
|
64 | + }else{ |
|
65 | 65 | $counters[$name->name] = [$name->sequence => $name->fullName()]; |
66 | 66 | } |
67 | 67 | } |
@@ -69,9 +69,9 @@ discard block |
||
69 | 69 | |
70 | 70 | private function parseName(string $name): NameEntity |
71 | 71 | { |
72 | - if (\preg_match("/\d+$/", $name, $match)) { |
|
72 | + if (\preg_match("/\d+$/", $name, $match)){ |
|
73 | 73 | $sequence = (int)$match[0]; |
74 | - if ($sequence > 0) { |
|
74 | + if ($sequence > 0){ |
|
75 | 75 | return NameEntity::createWithSequence(Utils::trimTrailingDigits($name, $sequence), $sequence); |
76 | 76 | } |
77 | 77 | } |
@@ -25,7 +25,8 @@ discard block |
||
25 | 25 | private function getConstructorReservedNames(ClassNode $definition): array |
26 | 26 | { |
27 | 27 | $names = \array_values($definition->constructorVars); |
28 | - foreach ($definition->constructorParams as $param) { |
|
28 | + foreach ($definition->constructorParams as $param) |
|
29 | + { |
|
29 | 30 | $names[] = $param->name; |
30 | 31 | } |
31 | 32 | |
@@ -35,12 +36,16 @@ discard block |
||
35 | 36 | private function initiateCounters(array $names): array |
36 | 37 | { |
37 | 38 | $counters = []; |
38 | - foreach ($names as $name) { |
|
39 | + foreach ($names as $name) |
|
40 | + { |
|
39 | 41 | $name = $this->parseName($name); |
40 | 42 | |
41 | - if (isset($counters[$name->name])) { |
|
43 | + if (isset($counters[$name->name])) |
|
44 | + { |
|
42 | 45 | $counters[$name->name][$name->sequence] = $name->fullName(); |
43 | - } else { |
|
46 | + } |
|
47 | + else |
|
48 | + { |
|
44 | 49 | $counters[$name->name] = [$name->sequence => $name->fullName()]; |
45 | 50 | } |
46 | 51 | } |
@@ -50,18 +55,23 @@ discard block |
||
50 | 55 | |
51 | 56 | private function addPostfixes(ClassNode $definition, array $counters): void |
52 | 57 | { |
53 | - foreach ($definition->dependencies as $dependency) { |
|
58 | + foreach ($definition->dependencies as $dependency) |
|
59 | + { |
|
54 | 60 | $name = $this->parseName($dependency->var); |
55 | - if (isset($counters[$name->name])) { |
|
61 | + if (isset($counters[$name->name])) |
|
62 | + { |
|
56 | 63 | $sequence = $this->sequences->find(\array_keys($counters[$name->name]), $name->sequence); |
57 | - if ($sequence !== $name->sequence) { |
|
64 | + if ($sequence !== $name->sequence) |
|
65 | + { |
|
58 | 66 | $name->sequence = $sequence; |
59 | 67 | |
60 | 68 | $dependency->var = $name->fullName(); |
61 | 69 | } |
62 | 70 | |
63 | 71 | $counters[$name->name][$sequence] = $name->fullName(); |
64 | - } else { |
|
72 | + } |
|
73 | + else |
|
74 | + { |
|
65 | 75 | $counters[$name->name] = [$name->sequence => $name->fullName()]; |
66 | 76 | } |
67 | 77 | } |
@@ -69,9 +79,11 @@ discard block |
||
69 | 79 | |
70 | 80 | private function parseName(string $name): NameEntity |
71 | 81 | { |
72 | - if (\preg_match("/\d+$/", $name, $match)) { |
|
82 | + if (\preg_match("/\d+$/", $name, $match)) |
|
83 | + { |
|
73 | 84 | $sequence = (int)$match[0]; |
74 | - if ($sequence > 0) { |
|
85 | + if ($sequence > 0) |
|
86 | + { |
|
75 | 87 | return NameEntity::createWithSequence(Utils::trimTrailingDigits($name, $sequence), $sequence); |
76 | 88 | } |
77 | 89 | } |
@@ -14,21 +14,21 @@ discard block |
||
14 | 14 | */ |
15 | 15 | public function find(array $sequences, int $originSequence): int |
16 | 16 | { |
17 | - if (empty($sequences) || $originSequence > \max($sequences)) { |
|
17 | + if (empty($sequences) || $originSequence > \max($sequences)){ |
|
18 | 18 | return $originSequence; |
19 | 19 | } |
20 | 20 | |
21 | 21 | $gaps = $this->skippedSequences($sequences); |
22 | 22 | |
23 | - if (isset($gaps[$originSequence])) { |
|
23 | + if (isset($gaps[$originSequence])){ |
|
24 | 24 | return $originSequence; |
25 | 25 | } |
26 | 26 | |
27 | 27 | //we do not add "1" as postfix: $var, $var2, $var3, etc |
28 | 28 | unset($gaps[1]); |
29 | - if (empty($gaps)) { |
|
29 | + if (empty($gaps)){ |
|
30 | 30 | $max = \max($sequences); |
31 | - if ($max === 0) { |
|
31 | + if ($max === 0){ |
|
32 | 32 | return 2; |
33 | 33 | } |
34 | 34 | |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | { |
43 | 43 | $skipped = []; |
44 | 44 | $max = \max($sequences); |
45 | - for ($i = 0; $i < $max; $i++) { |
|
46 | - if (!\in_array($i, $sequences, true)) { |
|
45 | + for ($i = 0; $i < $max; $i++){ |
|
46 | + if (!\in_array($i, $sequences, true)){ |
|
47 | 47 | $skipped[$i] = $i; |
48 | 48 | } |
49 | 49 | } |
@@ -14,21 +14,25 @@ discard block |
||
14 | 14 | */ |
15 | 15 | public function find(array $sequences, int $originSequence): int |
16 | 16 | { |
17 | - if (empty($sequences) || $originSequence > \max($sequences)) { |
|
17 | + if (empty($sequences) || $originSequence > \max($sequences)) |
|
18 | + { |
|
18 | 19 | return $originSequence; |
19 | 20 | } |
20 | 21 | |
21 | 22 | $gaps = $this->skippedSequences($sequences); |
22 | 23 | |
23 | - if (isset($gaps[$originSequence])) { |
|
24 | + if (isset($gaps[$originSequence])) |
|
25 | + { |
|
24 | 26 | return $originSequence; |
25 | 27 | } |
26 | 28 | |
27 | 29 | //we do not add "1" as postfix: $var, $var2, $var3, etc |
28 | 30 | unset($gaps[1]); |
29 | - if (empty($gaps)) { |
|
31 | + if (empty($gaps)) |
|
32 | + { |
|
30 | 33 | $max = \max($sequences); |
31 | - if ($max === 0) { |
|
34 | + if ($max === 0) |
|
35 | + { |
|
32 | 36 | return 2; |
33 | 37 | } |
34 | 38 | |
@@ -42,8 +46,10 @@ discard block |
||
42 | 46 | { |
43 | 47 | $skipped = []; |
44 | 48 | $max = \max($sequences); |
45 | - for ($i = 0; $i < $max; $i++) { |
|
46 | - if (!\in_array($i, $sequences, true)) { |
|
49 | + for ($i = 0; $i < $max; $i++) |
|
50 | + { |
|
51 | + if (!\in_array($i, $sequences, true)) |
|
52 | + { |
|
47 | 53 | $skipped[$i] = $i; |
48 | 54 | } |
49 | 55 | } |
@@ -46,7 +46,8 @@ discard block |
||
46 | 46 | public function perform(): int |
47 | 47 | { |
48 | 48 | $prototyped = $this->locator->getTargetClasses(); |
49 | - if ($prototyped === []) { |
|
49 | + if ($prototyped === []) |
|
50 | + { |
|
50 | 51 | $this->writeln('<comment>No prototyped classes found.</comment>'); |
51 | 52 | |
52 | 53 | return self::SUCCESS; |
@@ -54,18 +55,23 @@ discard block |
||
54 | 55 | |
55 | 56 | $targets = []; |
56 | 57 | |
57 | - foreach ($prototyped as $class) { |
|
58 | + foreach ($prototyped as $class) |
|
59 | + { |
|
58 | 60 | $proto = $this->getPrototypeProperties($class, $prototyped); |
59 | - if (empty($proto)) { |
|
61 | + if (empty($proto)) |
|
62 | + { |
|
60 | 63 | $modified = $this->modify($class, $proto); |
61 | - if ($modified !== null) { |
|
64 | + if ($modified !== null) |
|
65 | + { |
|
62 | 66 | $targets[] = $modified; |
63 | 67 | } |
64 | 68 | continue; |
65 | 69 | } |
66 | 70 | |
67 | - foreach ($proto as $target) { |
|
68 | - if ($target instanceof \Throwable) { |
|
71 | + foreach ($proto as $target) |
|
72 | + { |
|
73 | + if ($target instanceof \Throwable) |
|
74 | + { |
|
69 | 75 | $targets[] = [ |
70 | 76 | $class->getName(), |
71 | 77 | $target->getMessage(), |
@@ -74,7 +80,8 @@ discard block |
||
74 | 80 | continue 2; |
75 | 81 | } |
76 | 82 | |
77 | - if ($target === null) { |
|
83 | + if ($target === null) |
|
84 | + { |
|
78 | 85 | continue 2; |
79 | 86 | } |
80 | 87 | } |
@@ -82,14 +89,17 @@ discard block |
||
82 | 89 | $targets[] = [$class->getName(), $this->mergeNames($proto), $this->mergeTargets($proto)]; |
83 | 90 | |
84 | 91 | $modified = $this->modify($class, $proto); |
85 | - if ($modified !== null) { |
|
92 | + if ($modified !== null) |
|
93 | + { |
|
86 | 94 | $targets[] = $modified; |
87 | 95 | } |
88 | 96 | } |
89 | 97 | |
90 | - if (!empty($targets)) { |
|
98 | + if (!empty($targets)) |
|
99 | + { |
|
91 | 100 | $grid = $this->table(['Class:', 'Property:', 'Target:']); |
92 | - foreach ($targets as $target) { |
|
101 | + foreach ($targets as $target) |
|
102 | + { |
|
93 | 103 | $grid->addRow($target); |
94 | 104 | } |
95 | 105 | |
@@ -102,7 +112,8 @@ discard block |
||
102 | 112 | private function modify(\ReflectionClass $class, array $proto): ?array |
103 | 113 | { |
104 | 114 | $classDefinition = $this->extractor->extract($class->getFileName(), $proto); |
105 | - try { |
|
115 | + try |
|
116 | + { |
|
106 | 117 | $modified = $this->injector->injectDependencies( |
107 | 118 | \file_get_contents($class->getFileName()), |
108 | 119 | $classDefinition, |
@@ -114,7 +125,9 @@ discard block |
||
114 | 125 | \file_put_contents($class->getFileName(), $modified); |
115 | 126 | |
116 | 127 | return null; |
117 | - } catch (\Throwable $e) { |
|
128 | + } |
|
129 | + catch (\Throwable $e) |
|
130 | + { |
|
118 | 131 | return [$class->getName(), $e->getMessage(), \sprintf('%s:L%s', $e->getFile(), $e->getLine())]; |
119 | 132 | } |
120 | 133 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | public function perform(): int |
36 | 36 | { |
37 | 37 | $prototyped = $this->locator->getTargetClasses(); |
38 | - if ($prototyped === []) { |
|
38 | + if ($prototyped === []){ |
|
39 | 39 | $this->writeln('<comment>No prototyped classes found.</comment>'); |
40 | 40 | |
41 | 41 | return self::SUCCESS; |
@@ -43,18 +43,18 @@ discard block |
||
43 | 43 | |
44 | 44 | $targets = []; |
45 | 45 | |
46 | - foreach ($prototyped as $class) { |
|
46 | + foreach ($prototyped as $class){ |
|
47 | 47 | $proto = $this->getPrototypeProperties($class, $prototyped); |
48 | - if (empty($proto)) { |
|
48 | + if (empty($proto)){ |
|
49 | 49 | $modified = $this->modify($class, $proto); |
50 | - if ($modified !== null) { |
|
50 | + if ($modified !== null){ |
|
51 | 51 | $targets[] = $modified; |
52 | 52 | } |
53 | 53 | continue; |
54 | 54 | } |
55 | 55 | |
56 | - foreach ($proto as $target) { |
|
57 | - if ($target instanceof \Throwable) { |
|
56 | + foreach ($proto as $target){ |
|
57 | + if ($target instanceof \Throwable){ |
|
58 | 58 | $targets[] = [ |
59 | 59 | $class->getName(), |
60 | 60 | $target->getMessage(), |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | continue 2; |
64 | 64 | } |
65 | 65 | |
66 | - if ($target === null) { |
|
66 | + if ($target === null){ |
|
67 | 67 | continue 2; |
68 | 68 | } |
69 | 69 | } |
@@ -71,14 +71,14 @@ discard block |
||
71 | 71 | $targets[] = [$class->getName(), $this->mergeNames($proto), $this->mergeTargets($proto)]; |
72 | 72 | |
73 | 73 | $modified = $this->modify($class, $proto); |
74 | - if ($modified !== null) { |
|
74 | + if ($modified !== null){ |
|
75 | 75 | $targets[] = $modified; |
76 | 76 | } |
77 | 77 | } |
78 | 78 | |
79 | - if (!empty($targets)) { |
|
79 | + if (!empty($targets)){ |
|
80 | 80 | $grid = $this->table(['Class:', 'Property:', 'Target:']); |
81 | - foreach ($targets as $target) { |
|
81 | + foreach ($targets as $target){ |
|
82 | 82 | $grid->addRow($target); |
83 | 83 | } |
84 | 84 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | private function modify(\ReflectionClass $class, array $proto): ?array |
92 | 92 | { |
93 | 93 | $classDefinition = $this->extractor->extract($class->getFileName(), $proto); |
94 | - try { |
|
94 | + try{ |
|
95 | 95 | $modified = $this->injector->injectDependencies( |
96 | 96 | \file_get_contents($class->getFileName()), |
97 | 97 | $classDefinition, |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | \file_put_contents($class->getFileName(), $modified); |
102 | 102 | |
103 | 103 | return null; |
104 | - } catch (\Throwable $e) { |
|
104 | + }catch (\Throwable $e){ |
|
105 | 105 | return [$class->getName(), $e->getMessage(), \sprintf('%s:L%s', $e->getFile(), $e->getLine())]; |
106 | 106 | } |
107 | 107 | } |
@@ -25,6 +25,6 @@ |
||
25 | 25 | */ |
26 | 26 | public function __construct( |
27 | 27 | public readonly string $property |
28 | - ) { |
|
28 | + ){ |
|
29 | 29 | } |
30 | 30 | } |
@@ -85,7 +85,7 @@ |
||
85 | 85 | ModelSchema::MUTATOR_SETTER => static::SETTERS |
86 | 86 | }; |
87 | 87 | |
88 | - if (isset($target[$field])) { |
|
88 | + if (isset($target[$field])){ |
|
89 | 89 | return $target[$field]; |
90 | 90 | } |
91 | 91 |
@@ -85,7 +85,8 @@ |
||
85 | 85 | ModelSchema::MUTATOR_SETTER => static::SETTERS |
86 | 86 | }; |
87 | 87 | |
88 | - if (isset($target[$field])) { |
|
88 | + if (isset($target[$field])) |
|
89 | + { |
|
89 | 90 | return $target[$field]; |
90 | 91 | } |
91 | 92 |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | public function __construct( |
13 | 13 | array $data, |
14 | 14 | private array $schema |
15 | - ) { |
|
15 | + ){ |
|
16 | 16 | parent::__construct($data); |
17 | 17 | } |
18 | 18 | |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | |
29 | 29 | protected function getMutator(string $field, string $type): mixed |
30 | 30 | { |
31 | - if (isset($this->schema[ModelSchema::MUTATORS][$type][$field])) { |
|
31 | + if (isset($this->schema[ModelSchema::MUTATORS][$type][$field])){ |
|
32 | 32 | return $this->schema[ModelSchema::MUTATORS][$type][$field]; |
33 | 33 | } |
34 | 34 |
@@ -28,7 +28,8 @@ |
||
28 | 28 | |
29 | 29 | protected function getMutator(string $field, string $type): mixed |
30 | 30 | { |
31 | - if (isset($this->schema[ModelSchema::MUTATORS][$type][$field])) { |
|
31 | + if (isset($this->schema[ModelSchema::MUTATORS][$type][$field])) |
|
32 | + { |
|
32 | 33 | return $this->schema[ModelSchema::MUTATORS][$type][$field]; |
33 | 34 | } |
34 | 35 |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | { |
16 | 16 | public function __construct( |
17 | 17 | private array $fields = [] |
18 | - ) { |
|
18 | + ){ |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | |
49 | 49 | public function hasField(string $name): bool |
50 | 50 | { |
51 | - if (!\array_key_exists($name, $this->fields)) { |
|
51 | + if (!\array_key_exists($name, $this->fields)){ |
|
52 | 52 | return false; |
53 | 53 | } |
54 | 54 | |
@@ -62,14 +62,14 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function setField(string $name, mixed $value, bool $filter = true): self |
64 | 64 | { |
65 | - if ($value instanceof ValueInterface) { |
|
65 | + if ($value instanceof ValueInterface){ |
|
66 | 66 | //In case of non scalar values filters must be bypassed (check accessor compatibility?) |
67 | 67 | $this->fields[$name] = clone $value; |
68 | 68 | |
69 | 69 | return $this; |
70 | 70 | } |
71 | 71 | |
72 | - if (!$filter || (\is_null($value) && $this->isNullable($name))) { |
|
72 | + if (!$filter || (\is_null($value) && $this->isNullable($name))){ |
|
73 | 73 | //Bypassing all filters |
74 | 74 | $this->fields[$name] = $value; |
75 | 75 | |
@@ -79,10 +79,10 @@ discard block |
||
79 | 79 | //Checking if field have accessor |
80 | 80 | $accessor = $this->getMutator($name, ModelSchema::MUTATOR_ACCESSOR); |
81 | 81 | |
82 | - if ($accessor !== null) { |
|
82 | + if ($accessor !== null){ |
|
83 | 83 | //Setting value thought associated accessor |
84 | 84 | $this->thoughValue($accessor, $name, $value); |
85 | - } else { |
|
85 | + }else{ |
|
86 | 86 | //Setting value thought setter filter (if any) |
87 | 87 | $this->setMutated($name, $value); |
88 | 88 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | { |
100 | 100 | $value = $this->hasField($name) ? $this->fields[$name] : $default; |
101 | 101 | |
102 | - if ($value instanceof ValueInterface || (\is_null($value) && $this->isNullable($name))) { |
|
102 | + if ($value instanceof ValueInterface || (\is_null($value) && $this->isNullable($name))){ |
|
103 | 103 | //Direct access to value when value is accessor or null and declared as nullable |
104 | 104 | return $value; |
105 | 105 | } |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | //Checking if field have accessor (decorator) |
108 | 108 | $accessor = $this->getMutator($name, ModelSchema::MUTATOR_ACCESSOR); |
109 | 109 | |
110 | - if (!empty($accessor)) { |
|
110 | + if (!empty($accessor)){ |
|
111 | 111 | return $this->fields[$name] = $this->createValue($accessor, $name, $value); |
112 | 112 | } |
113 | 113 | |
@@ -126,15 +126,15 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function setFields(iterable $fields = [], bool $all = false): self |
128 | 128 | { |
129 | - if (!\is_array($fields) && !$fields instanceof \Traversable) { |
|
129 | + if (!\is_array($fields) && !$fields instanceof \Traversable){ |
|
130 | 130 | return $this; |
131 | 131 | } |
132 | 132 | |
133 | - foreach ($fields as $name => $value) { |
|
134 | - if ($all || $this->isFillable($name)) { |
|
135 | - try { |
|
133 | + foreach ($fields as $name => $value){ |
|
134 | + if ($all || $this->isFillable($name)){ |
|
135 | + try{ |
|
136 | 136 | $this->setField($name, $value, true); |
137 | - } catch (AccessExceptionInterface) { |
|
137 | + }catch (AccessExceptionInterface){ |
|
138 | 138 | // We are suppressing field setting exceptions |
139 | 139 | } |
140 | 140 | } |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | public function getFields(bool $filter = true): array |
152 | 152 | { |
153 | 153 | $result = []; |
154 | - foreach (\array_keys($this->fields) as $name) { |
|
154 | + foreach (\array_keys($this->fields) as $name){ |
|
155 | 155 | $result[$name] = $this->getField($name, null, $filter); |
156 | 156 | } |
157 | 157 | |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | public function getValue(): array |
200 | 200 | { |
201 | 201 | $result = []; |
202 | - foreach ($this->fields as $field => $value) { |
|
202 | + foreach ($this->fields as $field => $value){ |
|
203 | 203 | $result[$field] = $value instanceof ValueInterface ? $value->getValue() : $value; |
204 | 204 | } |
205 | 205 | |
@@ -275,9 +275,9 @@ discard block |
||
275 | 275 | mixed $value, |
276 | 276 | array $context = [] |
277 | 277 | ): ValueInterface { |
278 | - if (!\is_string($type) || !\class_exists($type)) { |
|
278 | + if (!\is_string($type) || !\class_exists($type)){ |
|
279 | 279 | throw new EntityException( |
280 | - \sprintf('Unable to create accessor for field `%s` in ', $name) . static::class |
|
280 | + \sprintf('Unable to create accessor for field `%s` in ', $name).static::class |
|
281 | 281 | ); |
282 | 282 | } |
283 | 283 | |
@@ -292,10 +292,10 @@ discard block |
||
292 | 292 | { |
293 | 293 | $getter = $this->getMutator($name, ModelSchema::MUTATOR_GETTER); |
294 | 294 | |
295 | - if ($filter && !empty($getter)) { |
|
296 | - try { |
|
295 | + if ($filter && !empty($getter)){ |
|
296 | + try{ |
|
297 | 297 | return \call_user_func($getter, $value); |
298 | - } catch (\Exception) { |
|
298 | + }catch (\Exception){ |
|
299 | 299 | //Trying to filter null value, every filter must support it |
300 | 300 | return \call_user_func($getter, null); |
301 | 301 | } |
@@ -311,13 +311,13 @@ discard block |
||
311 | 311 | { |
312 | 312 | $setter = $this->getMutator($name, ModelSchema::MUTATOR_SETTER); |
313 | 313 | |
314 | - if (!empty($setter)) { |
|
315 | - try { |
|
314 | + if (!empty($setter)){ |
|
315 | + try{ |
|
316 | 316 | $this->fields[$name] = \call_user_func($setter, $value); |
317 | - } catch (\Exception) { |
|
317 | + }catch (\Exception){ |
|
318 | 318 | //Exceptional situation, we are choosing to keep original field value |
319 | 319 | } |
320 | - } else { |
|
320 | + }else{ |
|
321 | 321 | $this->fields[$name] = $value; |
322 | 322 | } |
323 | 323 | } |
@@ -327,11 +327,11 @@ discard block |
||
327 | 327 | * |
328 | 328 | * @param string|array $type Accessor definition (implementation specific). |
329 | 329 | */ |
330 | - private function thoughValue(array|string $type, string $name, mixed $value): void |
|
330 | + private function thoughValue(array | string $type, string $name, mixed $value): void |
|
331 | 331 | { |
332 | 332 | $field = $this->fields[$name] ?? null; |
333 | 333 | |
334 | - if (empty($field) || !($field instanceof ValueInterface)) { |
|
334 | + if (empty($field) || !($field instanceof ValueInterface)){ |
|
335 | 335 | //New field representation |
336 | 336 | $field = $this->createValue($type, $name, $value); |
337 | 337 |
@@ -48,7 +48,8 @@ discard block |
||
48 | 48 | |
49 | 49 | public function hasField(string $name): bool |
50 | 50 | { |
51 | - if (!\array_key_exists($name, $this->fields)) { |
|
51 | + if (!\array_key_exists($name, $this->fields)) |
|
52 | + { |
|
52 | 53 | return false; |
53 | 54 | } |
54 | 55 | |
@@ -62,14 +63,16 @@ discard block |
||
62 | 63 | */ |
63 | 64 | public function setField(string $name, mixed $value, bool $filter = true): self |
64 | 65 | { |
65 | - if ($value instanceof ValueInterface) { |
|
66 | + if ($value instanceof ValueInterface) |
|
67 | + { |
|
66 | 68 | //In case of non scalar values filters must be bypassed (check accessor compatibility?) |
67 | 69 | $this->fields[$name] = clone $value; |
68 | 70 | |
69 | 71 | return $this; |
70 | 72 | } |
71 | 73 | |
72 | - if (!$filter || (\is_null($value) && $this->isNullable($name))) { |
|
74 | + if (!$filter || (\is_null($value) && $this->isNullable($name))) |
|
75 | + { |
|
73 | 76 | //Bypassing all filters |
74 | 77 | $this->fields[$name] = $value; |
75 | 78 | |
@@ -79,10 +82,13 @@ discard block |
||
79 | 82 | //Checking if field have accessor |
80 | 83 | $accessor = $this->getMutator($name, ModelSchema::MUTATOR_ACCESSOR); |
81 | 84 | |
82 | - if ($accessor !== null) { |
|
85 | + if ($accessor !== null) |
|
86 | + { |
|
83 | 87 | //Setting value thought associated accessor |
84 | 88 | $this->thoughValue($accessor, $name, $value); |
85 | - } else { |
|
89 | + } |
|
90 | + else |
|
91 | + { |
|
86 | 92 | //Setting value thought setter filter (if any) |
87 | 93 | $this->setMutated($name, $value); |
88 | 94 | } |
@@ -99,7 +105,8 @@ discard block |
||
99 | 105 | { |
100 | 106 | $value = $this->hasField($name) ? $this->fields[$name] : $default; |
101 | 107 | |
102 | - if ($value instanceof ValueInterface || (\is_null($value) && $this->isNullable($name))) { |
|
108 | + if ($value instanceof ValueInterface || (\is_null($value) && $this->isNullable($name))) |
|
109 | + { |
|
103 | 110 | //Direct access to value when value is accessor or null and declared as nullable |
104 | 111 | return $value; |
105 | 112 | } |
@@ -107,7 +114,8 @@ discard block |
||
107 | 114 | //Checking if field have accessor (decorator) |
108 | 115 | $accessor = $this->getMutator($name, ModelSchema::MUTATOR_ACCESSOR); |
109 | 116 | |
110 | - if (!empty($accessor)) { |
|
117 | + if (!empty($accessor)) |
|
118 | + { |
|
111 | 119 | return $this->fields[$name] = $this->createValue($accessor, $name, $value); |
112 | 120 | } |
113 | 121 | |
@@ -126,15 +134,21 @@ discard block |
||
126 | 134 | */ |
127 | 135 | public function setFields(iterable $fields = [], bool $all = false): self |
128 | 136 | { |
129 | - if (!\is_array($fields) && !$fields instanceof \Traversable) { |
|
137 | + if (!\is_array($fields) && !$fields instanceof \Traversable) |
|
138 | + { |
|
130 | 139 | return $this; |
131 | 140 | } |
132 | 141 | |
133 | - foreach ($fields as $name => $value) { |
|
134 | - if ($all || $this->isFillable($name)) { |
|
135 | - try { |
|
142 | + foreach ($fields as $name => $value) |
|
143 | + { |
|
144 | + if ($all || $this->isFillable($name)) |
|
145 | + { |
|
146 | + try |
|
147 | + { |
|
136 | 148 | $this->setField($name, $value, true); |
137 | - } catch (AccessExceptionInterface) { |
|
149 | + } |
|
150 | + catch (AccessExceptionInterface) |
|
151 | + { |
|
138 | 152 | // We are suppressing field setting exceptions |
139 | 153 | } |
140 | 154 | } |
@@ -151,7 +165,8 @@ discard block |
||
151 | 165 | public function getFields(bool $filter = true): array |
152 | 166 | { |
153 | 167 | $result = []; |
154 | - foreach (\array_keys($this->fields) as $name) { |
|
168 | + foreach (\array_keys($this->fields) as $name) |
|
169 | + { |
|
155 | 170 | $result[$name] = $this->getField($name, null, $filter); |
156 | 171 | } |
157 | 172 | |
@@ -199,7 +214,8 @@ discard block |
||
199 | 214 | public function getValue(): array |
200 | 215 | { |
201 | 216 | $result = []; |
202 | - foreach ($this->fields as $field => $value) { |
|
217 | + foreach ($this->fields as $field => $value) |
|
218 | + { |
|
203 | 219 | $result[$field] = $value instanceof ValueInterface ? $value->getValue() : $value; |
204 | 220 | } |
205 | 221 | |
@@ -275,7 +291,8 @@ discard block |
||
275 | 291 | mixed $value, |
276 | 292 | array $context = [] |
277 | 293 | ): ValueInterface { |
278 | - if (!\is_string($type) || !\class_exists($type)) { |
|
294 | + if (!\is_string($type) || !\class_exists($type)) |
|
295 | + { |
|
279 | 296 | throw new EntityException( |
280 | 297 | \sprintf('Unable to create accessor for field `%s` in ', $name) . static::class |
281 | 298 | ); |
@@ -292,10 +309,14 @@ discard block |
||
292 | 309 | { |
293 | 310 | $getter = $this->getMutator($name, ModelSchema::MUTATOR_GETTER); |
294 | 311 | |
295 | - if ($filter && !empty($getter)) { |
|
296 | - try { |
|
312 | + if ($filter && !empty($getter)) |
|
313 | + { |
|
314 | + try |
|
315 | + { |
|
297 | 316 | return \call_user_func($getter, $value); |
298 | - } catch (\Exception) { |
|
317 | + } |
|
318 | + catch (\Exception) |
|
319 | + { |
|
299 | 320 | //Trying to filter null value, every filter must support it |
300 | 321 | return \call_user_func($getter, null); |
301 | 322 | } |
@@ -311,13 +332,19 @@ discard block |
||
311 | 332 | { |
312 | 333 | $setter = $this->getMutator($name, ModelSchema::MUTATOR_SETTER); |
313 | 334 | |
314 | - if (!empty($setter)) { |
|
315 | - try { |
|
335 | + if (!empty($setter)) |
|
336 | + { |
|
337 | + try |
|
338 | + { |
|
316 | 339 | $this->fields[$name] = \call_user_func($setter, $value); |
317 | - } catch (\Exception) { |
|
340 | + } |
|
341 | + catch (\Exception) |
|
342 | + { |
|
318 | 343 | //Exceptional situation, we are choosing to keep original field value |
319 | 344 | } |
320 | - } else { |
|
345 | + } |
|
346 | + else |
|
347 | + { |
|
321 | 348 | $this->fields[$name] = $value; |
322 | 349 | } |
323 | 350 | } |
@@ -331,7 +358,8 @@ discard block |
||
331 | 358 | { |
332 | 359 | $field = $this->fields[$name] ?? null; |
333 | 360 | |
334 | - if (empty($field) || !($field instanceof ValueInterface)) { |
|
361 | + if (empty($field) || !($field instanceof ValueInterface)) |
|
362 | + { |
|
335 | 363 | //New field representation |
336 | 364 | $field = $this->createValue($type, $name, $value); |
337 | 365 |