Skip to content

Commit

Permalink
Move explicit is_array mixed feature behind feature toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
herndlm committed Apr 12, 2022
1 parent 2fba73d commit 56207bd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions conf/bleedingEdge.neon
Expand Up @@ -3,6 +3,7 @@ parameters:
bleedingEdge: true
skipCheckGenericClasses: []
explicitMixedInUnknownGenericNew: true
explicitMixedViaIsArray: true
arrayFilter: true
stubFiles:
- ../stubs/bleedingEdge/Countable.stub
4 changes: 4 additions & 0 deletions conf/config.neon
Expand Up @@ -28,6 +28,7 @@ parameters:
- FilterIterator
- RecursiveCallbackFilterIterator
explicitMixedInUnknownGenericNew: false
explicitMixedViaIsArray: false
arrayFilter: false
fileExtensions:
- php
Expand Down Expand Up @@ -212,6 +213,7 @@ parametersSchema:
disableRuntimeReflectionProvider: bool(),
skipCheckGenericClasses: listOf(string()),
explicitMixedInUnknownGenericNew: bool(),
explicitMixedViaIsArray: bool(),
arrayFilter: bool(),
])
fileExtensions: listOf(string())
Expand Down Expand Up @@ -1424,6 +1426,8 @@ services:
class: PHPStan\Type\Php\IsArrayFunctionTypeSpecifyingExtension
tags:
- phpstan.typeSpecifier.functionTypeSpecifyingExtension
arguments:
explicitMixed: %featureToggles.explicitMixedViaIsArray%

-
class: PHPStan\Type\Php\IsBoolFunctionTypeSpecifyingExtension
Expand Down
7 changes: 6 additions & 1 deletion src/Type/Php/IsArrayFunctionTypeSpecifyingExtension.php
Expand Up @@ -20,6 +20,11 @@ class IsArrayFunctionTypeSpecifyingExtension implements FunctionTypeSpecifyingEx

private TypeSpecifier $typeSpecifier;

public function __construct(private bool $explicitMixed)
{
}


public function isFunctionSupported(FunctionReflection $functionReflection, FuncCall $node, TypeSpecifierContext $context): bool
{
return strtolower($functionReflection->getName()) === 'is_array'
Expand All @@ -35,7 +40,7 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n
throw new ShouldNotHappenException();
}

return $this->typeSpecifier->create($node->getArgs()[0]->value, new ArrayType(new MixedType(true), new MixedType(true)), $context, false, $scope);
return $this->typeSpecifier->create($node->getArgs()[0]->value, new ArrayType(new MixedType($this->explicitMixed), new MixedType($this->explicitMixed)), $context, false, $scope);
}

public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void
Expand Down

0 comments on commit 56207bd

Please sign in to comment.