Skip to content

Commit e7c273a

Browse files
committed
Cleanup
1 parent 1207efc commit e7c273a

File tree

3 files changed

+48
-51
lines changed

3 files changed

+48
-51
lines changed

SlevomatCodingStandard/Sniffs/TypeHints/ParameterTypeHintSniff.php

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ private function checkTypeHints(File $phpcsFile, int $functionPointer, array $pa
144144
}
145145

146146
$typeHints = [];
147+
$nullableParameterTypeHint = false;
147148

148149
if (AnnotationTypeHelper::containsOneType($parameterTypeNode)) {
149150
/** @var ArrayTypeNode|ArrayShapeNode|IdentifierTypeNode|ThisTypeNode|GenericTypeNode|CallableTypeNode $parameterTypeNode */
@@ -162,6 +163,11 @@ private function checkTypeHints(File $phpcsFile, int $functionPointer, array $pa
162163

163164
$typeHint = AnnotationTypeHelper::getTypeHintFromOneType($typeNode);
164165

166+
if (strtolower($typeHint) === 'null') {
167+
$nullableParameterTypeHint = true;
168+
continue;
169+
}
170+
165171
if (
166172
!$typeNode instanceof ArrayTypeNode
167173
&& !$typeNode instanceof ArrayShapeNode
@@ -183,26 +189,19 @@ private function checkTypeHints(File $phpcsFile, int $functionPointer, array $pa
183189

184190
if (count($typeHints) === 1) {
185191
$possibleParameterTypeHint = $typeHints[0];
186-
$nullableParameterTypeHint = false;
187192
} elseif (count($typeHints) === 2) {
188-
if (strtolower($typeHints[0]) === 'null' || strtolower($typeHints[1]) === 'null') {
189-
$possibleParameterTypeHint = strtolower($typeHints[0]) === 'null' ? $typeHints[1] : $typeHints[0];
190-
$nullableParameterTypeHint = true;
191-
} else {
192-
/** @var UnionTypeNode|IntersectionTypeNode $parameterTypeNode */
193-
$parameterTypeNode = $parameterTypeNode;
194-
195-
$itemsSpecificationTypeHint = AnnotationTypeHelper::getItemsSpecificationTypeFromType($parameterTypeNode, $this->getTraversableTypeHints());
196-
if (!$itemsSpecificationTypeHint instanceof ArrayTypeNode) {
197-
continue;
198-
}
193+
/** @var UnionTypeNode|IntersectionTypeNode $parameterTypeNode */
194+
$parameterTypeNode = $parameterTypeNode;
199195

200-
$possibleParameterTypeHint = AnnotationTypeHelper::getTraversableTypeHintFromType($parameterTypeNode, $this->getTraversableTypeHints());
201-
$nullableParameterTypeHint = false;
196+
$itemsSpecificationTypeHint = AnnotationTypeHelper::getItemsSpecificationTypeFromType($parameterTypeNode, $this->getTraversableTypeHints());
197+
if (!$itemsSpecificationTypeHint instanceof ArrayTypeNode) {
198+
continue;
199+
}
202200

203-
if (!TypeHintHelper::isTraversableType(TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $functionPointer, $possibleParameterTypeHint), $this->getTraversableTypeHints())) {
204-
continue;
205-
}
201+
$possibleParameterTypeHint = AnnotationTypeHelper::getTraversableTypeHintFromType($parameterTypeNode, $this->getTraversableTypeHints());
202+
203+
if (!TypeHintHelper::isTraversableType(TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $functionPointer, $possibleParameterTypeHint), $this->getTraversableTypeHints())) {
204+
continue;
206205
}
207206
} else {
208207
continue;

SlevomatCodingStandard/Sniffs/TypeHints/PropertyTypeHintSniff.php

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ private function checkTypeHint(
146146
}
147147

148148
$typeHints = [];
149+
$nullableTypeHint = false;
149150

150151
if (AnnotationTypeHelper::containsOneType($typeNode)) {
151152
/** @var ArrayTypeNode|ArrayShapeNode|IdentifierTypeNode|ThisTypeNode|GenericTypeNode|CallableTypeNode $typeNode */
@@ -164,6 +165,11 @@ private function checkTypeHint(
164165

165166
$typeHint = AnnotationTypeHelper::getTypeHintFromOneType($innerTypeNode);
166167

168+
if (strtolower($typeHint) === 'null') {
169+
$nullableTypeHint = true;
170+
continue;
171+
}
172+
167173
if (
168174
!$innerTypeNode instanceof ArrayTypeNode
169175
&& !$innerTypeNode instanceof ArrayShapeNode
@@ -185,26 +191,19 @@ private function checkTypeHint(
185191

186192
if (count($typeHints) === 1) {
187193
$possibleTypeHint = $typeHints[0];
188-
$nullableTypeHint = false;
189194
} elseif (count($typeHints) === 2) {
190-
if (strtolower($typeHints[0]) === 'null' || strtolower($typeHints[1]) === 'null') {
191-
$possibleTypeHint = strtolower($typeHints[0]) === 'null' ? $typeHints[1] : $typeHints[0];
192-
$nullableTypeHint = true;
193-
} else {
194-
/** @var UnionTypeNode|IntersectionTypeNode $typeNode */
195-
$typeNode = $typeNode;
196-
197-
$itemsSpecificationTypeHint = AnnotationTypeHelper::getItemsSpecificationTypeFromType($typeNode, $this->getTraversableTypeHints());
198-
if (!$itemsSpecificationTypeHint instanceof ArrayTypeNode) {
199-
return;
200-
}
195+
/** @var UnionTypeNode|IntersectionTypeNode $typeNode */
196+
$typeNode = $typeNode;
201197

202-
$possibleTypeHint = AnnotationTypeHelper::getTraversableTypeHintFromType($typeNode, $this->getTraversableTypeHints());
203-
$nullableTypeHint = false;
198+
$itemsSpecificationTypeHint = AnnotationTypeHelper::getItemsSpecificationTypeFromType($typeNode, $this->getTraversableTypeHints());
199+
if (!$itemsSpecificationTypeHint instanceof ArrayTypeNode) {
200+
return;
201+
}
204202

205-
if (!TypeHintHelper::isTraversableType(TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $propertyPointer, $possibleTypeHint), $this->getTraversableTypeHints())) {
206-
return;
207-
}
203+
$possibleTypeHint = AnnotationTypeHelper::getTraversableTypeHintFromType($typeNode, $this->getTraversableTypeHints());
204+
205+
if (!TypeHintHelper::isTraversableType(TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $propertyPointer, $possibleTypeHint), $this->getTraversableTypeHints())) {
206+
return;
208207
}
209208
} else {
210209
return;

SlevomatCodingStandard/Sniffs/TypeHints/ReturnTypeHintSniff.php

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ private function checkFunctionTypeHint(
173173
}
174174

175175
$typeHints = [];
176+
$nullableReturnTypeHint = false;
176177

177178
$originalReturnTypeNode = $returnTypeNode;
178179
if ($returnTypeNode instanceof NullableTypeNode) {
@@ -196,6 +197,11 @@ private function checkFunctionTypeHint(
196197

197198
$typeHint = AnnotationTypeHelper::getTypeHintFromOneType($typeNode);
198199

200+
if (strtolower($typeHint) === 'null') {
201+
$nullableReturnTypeHint = true;
202+
continue;
203+
}
204+
199205
if (
200206
!$typeNode instanceof ArrayTypeNode
201207
&& !$typeNode instanceof ArrayShapeNode
@@ -217,26 +223,19 @@ private function checkFunctionTypeHint(
217223

218224
if (count($typeHints) === 1) {
219225
$possibleReturnTypeHint = $typeHints[0];
220-
$nullableReturnTypeHint = false;
221226
} elseif (count($typeHints) === 2) {
222-
if (strtolower($typeHints[0]) === 'null' || strtolower($typeHints[1]) === 'null') {
223-
$possibleReturnTypeHint = strtolower($typeHints[0]) === 'null' ? $typeHints[1] : $typeHints[0];
224-
$nullableReturnTypeHint = true;
225-
} else {
226-
/** @var UnionTypeNode|IntersectionTypeNode $returnTypeNode */
227-
$returnTypeNode = $returnTypeNode;
228-
229-
$itemsSpecificationTypeHint = AnnotationTypeHelper::getItemsSpecificationTypeFromType($returnTypeNode, $this->getTraversableTypeHints());
230-
if (!$itemsSpecificationTypeHint instanceof ArrayTypeNode) {
231-
return;
232-
}
227+
/** @var UnionTypeNode|IntersectionTypeNode $returnTypeNode */
228+
$returnTypeNode = $returnTypeNode;
233229

234-
$possibleReturnTypeHint = AnnotationTypeHelper::getTraversableTypeHintFromType($returnTypeNode, $this->getTraversableTypeHints());
235-
$nullableReturnTypeHint = false;
230+
$itemsSpecificationTypeHint = AnnotationTypeHelper::getItemsSpecificationTypeFromType($returnTypeNode, $this->getTraversableTypeHints());
231+
if (!$itemsSpecificationTypeHint instanceof ArrayTypeNode) {
232+
return;
233+
}
236234

237-
if (!TypeHintHelper::isTraversableType(TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $functionPointer, $possibleReturnTypeHint), $this->getTraversableTypeHints())) {
238-
return;
239-
}
235+
$possibleReturnTypeHint = AnnotationTypeHelper::getTraversableTypeHintFromType($returnTypeNode, $this->getTraversableTypeHints());
236+
237+
if (!TypeHintHelper::isTraversableType(TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $functionPointer, $possibleReturnTypeHint), $this->getTraversableTypeHints())) {
238+
return;
240239
}
241240
} else {
242241
return;

0 commit comments

Comments
 (0)