Skip to content

Commit

Permalink
Generic ignore of some BC promises
Browse files Browse the repository at this point in the history
  • Loading branch information
janedbal committed May 14, 2024
1 parent fd5d1c4 commit 630c8f5
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 17 deletions.
6 changes: 6 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ parameters:
message: '#^Call to function method_exists\(\) with PHPStan\\Analyser\\Scope and ''getKeepVoidType'' will always evaluate to true\.$#'
path: src/Rule/ForbidUnusedMatchResultRule.php
reportUnmatched: false # fails only for PHPStan > 1.10.49

# ignore BC promises
- identifier: phpstanApi.class
- identifier: phpstanApi.method
- identifier: phpstanApi.interface
- identifier: phpstanApi.instanceofAssumption
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private function combineCallbackAndCallThrowTypes(
Scope $scope
): ?Type
{
if (!$scope instanceof MutatingScope) { // @phpstan-ignore-line ignore bc promise
if (!$scope instanceof MutatingScope) {
throw new LogicException('Unexpected scope implementation');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rule/EnforceClosureParamNativeTypehintRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function processNode(
Scope $scope
): array
{
if (!$node instanceof InClosureNode && !$node instanceof InArrowFunctionNode) { // @phpstan-ignore-line bc promise
if (!$node instanceof InClosureNode && !$node instanceof InArrowFunctionNode) {
return [];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rule/EnforceListReturnRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function processNode(Node $node, Scope $scope): array

$methodReflection = $scope->getFunction();

if ($methodReflection === null || $node instanceof ClosureReturnStatementsNode) { // @phpstan-ignore-line ignore bc promise
if ($methodReflection === null || $node instanceof ClosureReturnStatementsNode) {
return [];
}

Expand Down
16 changes: 8 additions & 8 deletions src/Rule/ForbidCheckedExceptionInCallableRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ public function processNode(
): array
{
if (
$node instanceof MethodCallableNode // @phpstan-ignore-line ignore bc promise
|| $node instanceof StaticMethodCallableNode // @phpstan-ignore-line ignore bc promise
|| $node instanceof FunctionCallableNode // @phpstan-ignore-line ignore bc promise
$node instanceof MethodCallableNode
|| $node instanceof StaticMethodCallableNode
|| $node instanceof FunctionCallableNode
) {
return $this->processFirstClassCallable($node->getOriginalNode(), $scope);
}

if ($node instanceof ClosureReturnStatementsNode) { // @phpstan-ignore-line ignore bc promise
if ($node instanceof ClosureReturnStatementsNode) {
return $this->processClosure($node, $scope);
}

Expand Down Expand Up @@ -206,26 +206,26 @@ public function processArrowFunction(
Scope $scope
): array
{
if (!$scope instanceof MutatingScope) { // @phpstan-ignore-line ignore BC promise
if (!$scope instanceof MutatingScope) {
throw new LogicException('Unexpected scope implementation');
}

if ($this->isAllowedToThrowCheckedException($node, $scope)) {
return [];
}

$result = $this->nodeScopeResolver->processExprNode( // @phpstan-ignore-line ignore BC promise
$result = $this->nodeScopeResolver->processExprNode(
new Expression($node->expr),
$node->expr,
$scope->enterArrowFunction($node),
static function (): void {
},
ExpressionContext::createDeep(), // @phpstan-ignore-line ignore BC promise
ExpressionContext::createDeep(),
);

$errors = [];

foreach ($result->getThrowPoints() as $throwPoint) { // @phpstan-ignore-line ignore BC promise
foreach ($result->getThrowPoints() as $throwPoint) {
if (!$throwPoint->isExplicit()) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Rule/ForbidReturnValueInYieldingMethodRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function processNode(
? 'this approach is denied'
: 'but this method is not marked to return Generator';

$callType = $node instanceof MethodReturnStatementsNode // @phpstan-ignore-line ignore bc promise
$callType = $node instanceof MethodReturnStatementsNode
? 'method'
: 'function';

Expand All @@ -85,7 +85,7 @@ private function getReturnType(ReturnStatementsNode $node, Scope $scope): Type
{
$methodReflection = $scope->getFunction();

if ($node instanceof ClosureReturnStatementsNode) { // @phpstan-ignore-line ignore bc promise
if ($node instanceof ClosureReturnStatementsNode) {
return $scope->getFunctionType($node->getClosureExpr()->getReturnType(), false, false);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rule/ForbidUselessNullableReturnRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function processNode(Node $node, Scope $scope): array
$verbosity = VerbosityLevel::precise();
$methodReflection = $scope->getFunction();

if ($node instanceof ClosureReturnStatementsNode) { // @phpstan-ignore-line ignore bc promise
if ($node instanceof ClosureReturnStatementsNode) {
$declaredType = $scope->getFunctionType($node->getClosureExpr()->getReturnType(), false, false);
} elseif ($methodReflection !== null) {
$declaredType = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
Expand Down
6 changes: 3 additions & 3 deletions src/Rule/ForbidVariableTypeOverwritingRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private function removeNullAccessoryAndSubtractedTypes(Type $type): Type
$newInnerTypes = [];

foreach ($type->getTypes() as $innerType) {
if ($innerType instanceof AccessoryType) { // @phpstan-ignore-line ignore bc promise
if ($innerType instanceof AccessoryType) { // @phpstan-ignore phpstanApi.instanceofType
continue;
}

Expand All @@ -122,8 +122,8 @@ private function removeNullAccessoryAndSubtractedTypes(Type $type): Type
$type = TypeCombinator::intersect(...$newInnerTypes);
}

if ($type instanceof SubtractableType) { // @phpstan-ignore-line ignore bc promise
$type = $type->getTypeWithoutSubtractedType(); // @phpstan-ignore-line ignore bc promise
if ($type instanceof SubtractableType) {
$type = $type->getTypeWithoutSubtractedType();
}

return TypeCombinator::removeNull($type);
Expand Down

0 comments on commit 630c8f5

Please sign in to comment.