|
@@ -57,7 +57,7 @@ discard block |
|
|
block discarded – undo |
|
57
|
57
|
*/ |
|
58
|
58
|
public function getPropertyDocblockTypeHint(\ReflectionProperty $reflectionProperty): ?string |
|
59
|
59
|
{ |
|
60
|
|
- if (!$reflectionProperty->getDocComment()) { |
|
|
60
|
+ if ( ! $reflectionProperty->getDocComment()) { |
|
61
|
61
|
return null; |
|
62
|
62
|
} |
|
63
|
63
|
|
|
@@ -92,25 +92,25 @@ discard block |
|
|
block discarded – undo |
|
92
|
92
|
if ($type instanceof ArrayTypeNode) { |
|
93
|
93
|
$resolvedType = $this->resolveTypeFromTypeNode($type->type, $reflectionProperty); |
|
94
|
94
|
|
|
95
|
|
- return 'array<' . $resolvedType . '>'; |
|
|
95
|
+ return 'array<'.$resolvedType.'>'; |
|
96
|
96
|
} |
|
97
|
97
|
|
|
98
|
98
|
// Generic array syntax: array<Product> | array<\Foo\Bar\Product> | array<int,Product> |
|
99
|
99
|
if ($type instanceof GenericTypeNode) { |
|
100
|
100
|
if ($this->isSimpleType($type->type, 'array')) { |
|
101
|
|
- $resolvedTypes = array_map(function (TypeNode $node) use ($reflectionProperty) { |
|
|
101
|
+ $resolvedTypes = array_map(function(TypeNode $node) use ($reflectionProperty) { |
|
102
|
102
|
return $this->resolveTypeFromTypeNode($node, $reflectionProperty); |
|
103
|
103
|
}, $type->genericTypes); |
|
104
|
104
|
|
|
105
|
|
- return 'array<' . implode(',', $resolvedTypes) . '>'; |
|
|
105
|
+ return 'array<'.implode(',', $resolvedTypes).'>'; |
|
106
|
106
|
} |
|
107
|
107
|
|
|
108
|
108
|
if ($this->isSimpleType($type->type, 'list')) { |
|
109
|
|
- $resolvedTypes = array_map(function (TypeNode $node) use ($reflectionProperty) { |
|
|
109
|
+ $resolvedTypes = array_map(function(TypeNode $node) use ($reflectionProperty) { |
|
110
|
110
|
return $this->resolveTypeFromTypeNode($node, $reflectionProperty); |
|
111
|
111
|
}, $type->genericTypes); |
|
112
|
112
|
|
|
113
|
|
- return 'array<int, ' . implode(',', $resolvedTypes) . '>'; |
|
|
113
|
+ return 'array<int, '.implode(',', $resolvedTypes).'>'; |
|
114
|
114
|
} |
|
115
|
115
|
|
|
116
|
116
|
throw new \InvalidArgumentException(sprintf("Can't use non-array generic type %s for collection in %s:%s", (string) $type->type, $reflectionProperty->getDeclaringClass()->getName(), $reflectionProperty->getName())); |
|
@@ -133,7 +133,7 @@ discard block |
|
|
block discarded – undo |
|
133
|
133
|
return []; |
|
134
|
134
|
} |
|
135
|
135
|
|
|
136
|
|
- return array_merge(...array_map(static function (VarTagValueNode $node) { |
|
|
136
|
+ return array_merge(...array_map(static function(VarTagValueNode $node) { |
|
137
|
137
|
if ($node->type instanceof UnionTypeNode) { |
|
138
|
138
|
return $node->type->types; |
|
139
|
139
|
} |
|
@@ -151,7 +151,7 @@ discard block |
|
|
block discarded – undo |
|
151
|
151
|
*/ |
|
152
|
152
|
private function filterNullFromTypes(array $types): array |
|
153
|
153
|
{ |
|
154
|
|
- return array_values(array_filter(array_map(function (TypeNode $node) { |
|
|
154
|
+ return array_values(array_filter(array_map(function(TypeNode $node) { |
|
155
|
155
|
return $this->isNullType($node) ? null : $node; |
|
156
|
156
|
}, $types))); |
|
157
|
157
|
} |
|
@@ -194,7 +194,7 @@ discard block |
|
|
block discarded – undo |
|
194
|
194
|
*/ |
|
195
|
195
|
private function resolveTypeFromTypeNode(TypeNode $typeNode, \ReflectionProperty $reflectionProperty): string |
|
196
|
196
|
{ |
|
197
|
|
- if (!($typeNode instanceof IdentifierTypeNode)) { |
|
|
197
|
+ if ( ! ($typeNode instanceof IdentifierTypeNode)) { |
|
198
|
198
|
throw new \InvalidArgumentException(sprintf("Can't use unsupported type %s for collection in %s:%s", (string) $typeNode, $reflectionProperty->getDeclaringClass()->getName(), $reflectionProperty->getName())); |
|
199
|
199
|
} |
|
200
|
200
|
|
|
@@ -207,7 +207,7 @@ discard block |
|
|
block discarded – undo |
|
207
|
207
|
return $typeHint; |
|
208
|
208
|
} |
|
209
|
209
|
|
|
210
|
|
- $expandedClassName = $declaringClass->getNamespaceName() . '\\' . $typeHint; |
|
|
210
|
+ $expandedClassName = $declaringClass->getNamespaceName().'\\'.$typeHint; |
|
211
|
211
|
if ($this->isClassOrInterface($expandedClassName)) { |
|
212
|
212
|
return $expandedClassName; |
|
213
|
213
|
} |
|
@@ -230,7 +230,7 @@ discard block |
|
|
block discarded – undo |
|
230
|
230
|
|
|
231
|
231
|
if ($declaringClass->getDocComment()) { |
|
232
|
232
|
preg_match_all(self::PHPSTAN_ARRAY_SHAPE, $declaringClass->getDocComment(), $foundPhpstanArrayShape); |
|
233
|
|
- $phpstanArrayShapes = array_map(static function (string $phpstanArrayType) { |
|
|
233
|
+ $phpstanArrayShapes = array_map(static function(string $phpstanArrayType) { |
|
234
|
234
|
return $phpstanArrayType; |
|
235
|
235
|
}, $foundPhpstanArrayShape[1]); |
|
236
|
236
|
|
|
@@ -244,7 +244,7 @@ discard block |
|
|
block discarded – undo |
|
244
|
244
|
|
|
245
|
245
|
private function endsWith(string $statementClassToCheck, string $typeHintToSearchFor): bool |
|
246
|
246
|
{ |
|
247
|
|
- $typeHintToSearchFor = '\\' . $typeHintToSearchFor; |
|
|
247
|
+ $typeHintToSearchFor = '\\'.$typeHintToSearchFor; |
|
248
|
248
|
|
|
249
|
249
|
return substr($statementClassToCheck, -strlen($typeHintToSearchFor)) === $typeHintToSearchFor; |
|
250
|
250
|
} |
|
@@ -265,7 +265,7 @@ discard block |
|
|
block discarded – undo |
|
265
|
265
|
preg_match_all(self::GROUP_USE_STATEMENTS_REGEX, $classContents, $foundGroupUseStatements); |
|
266
|
266
|
for ($useStatementIndex = 0; $useStatementIndex < count($foundGroupUseStatements[0]); $useStatementIndex++) { |
|
267
|
267
|
foreach (explode(',', $foundGroupUseStatements[2][$useStatementIndex]) as $singleUseStatement) { |
|
268
|
|
- $foundUseStatements[] = trim($foundGroupUseStatements[1][$useStatementIndex]) . trim($singleUseStatement); |
|
|
268
|
+ $foundUseStatements[] = trim($foundGroupUseStatements[1][$useStatementIndex]).trim($singleUseStatement); |
|
269
|
269
|
} |
|
270
|
270
|
} |
|
271
|
271
|
|
|
@@ -298,7 +298,7 @@ discard block |
|
|
block discarded – undo |
|
298
|
298
|
|
|
299
|
299
|
private function resolveType(string $typeHint, \ReflectionProperty $reflectionProperty): string |
|
300
|
300
|
{ |
|
301
|
|
- if (!$this->hasGlobalNamespacePrefix($typeHint) && !$this->isPrimitiveType($typeHint)) { |
|
|
301
|
+ if ( ! $this->hasGlobalNamespacePrefix($typeHint) && ! $this->isPrimitiveType($typeHint)) { |
|
302
|
302
|
$typeHint = $this->expandClassNameUsingUseStatements($typeHint, $this->getDeclaringClassOrTrait($reflectionProperty), $reflectionProperty); |
|
303
|
303
|
} |
|
304
|
304
|
|