From 11848ccaf414584e1efb2386bd0f0ceea5192652 Mon Sep 17 00:00:00 2001 From: Brad <28307684+mad-briller@users.noreply.github.com> Date: Thu, 20 Oct 2022 17:55:53 +0100 Subject: [PATCH] Remove is_bool, is_countable and is_null type specifying extensions. --- conf/config.neon | 15 ----- .../IsBoolFunctionTypeSpecifyingExtension.php | 45 -------------- ...untableFunctionTypeSpecifyingExtension.php | 59 ------------------- .../IsNullFunctionTypeSpecifyingExtension.php | 46 --------------- stubs/typeCheckingFunctions.stub | 26 ++++++++ 5 files changed, 26 insertions(+), 165 deletions(-) delete mode 100644 src/Type/Php/IsBoolFunctionTypeSpecifyingExtension.php delete mode 100644 src/Type/Php/IsCountableFunctionTypeSpecifyingExtension.php delete mode 100644 src/Type/Php/IsNullFunctionTypeSpecifyingExtension.php diff --git a/conf/config.neon b/conf/config.neon index 8ead873aa1..4c1b40a61a 100644 --- a/conf/config.neon +++ b/conf/config.neon @@ -1627,11 +1627,6 @@ services: tags: - phpstan.typeSpecifier.functionTypeSpecifyingExtension - - - class: PHPStan\Type\Php\IsNullFunctionTypeSpecifyingExtension - tags: - - phpstan.typeSpecifier.functionTypeSpecifyingExtension - - class: PHPStan\Type\Php\IsArrayFunctionTypeSpecifyingExtension tags: @@ -1639,21 +1634,11 @@ services: arguments: explicitMixed: %featureToggles.explicitMixedViaIsArray% - - - class: PHPStan\Type\Php\IsBoolFunctionTypeSpecifyingExtension - tags: - - phpstan.typeSpecifier.functionTypeSpecifyingExtension - - class: PHPStan\Type\Php\IsCallableFunctionTypeSpecifyingExtension tags: - phpstan.typeSpecifier.functionTypeSpecifyingExtension - - - class: PHPStan\Type\Php\IsCountableFunctionTypeSpecifyingExtension - tags: - - phpstan.typeSpecifier.functionTypeSpecifyingExtension - - class: PHPStan\Type\Php\IsResourceFunctionTypeSpecifyingExtension tags: diff --git a/src/Type/Php/IsBoolFunctionTypeSpecifyingExtension.php b/src/Type/Php/IsBoolFunctionTypeSpecifyingExtension.php deleted file mode 100644 index 44a9b8b088..0000000000 --- a/src/Type/Php/IsBoolFunctionTypeSpecifyingExtension.php +++ /dev/null @@ -1,45 +0,0 @@ -getName()) === 'is_bool' - && !$context->null(); - } - - public function specifyTypes(FunctionReflection $functionReflection, FuncCall $node, Scope $scope, TypeSpecifierContext $context): SpecifiedTypes - { - if (!isset($node->getArgs()[0])) { - return new SpecifiedTypes(); - } - if ($context->null()) { - throw new ShouldNotHappenException(); - } - - return $this->typeSpecifier->create($node->getArgs()[0]->value, new BooleanType(), $context, false, $scope); - } - - public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void - { - $this->typeSpecifier = $typeSpecifier; - } - -} diff --git a/src/Type/Php/IsCountableFunctionTypeSpecifyingExtension.php b/src/Type/Php/IsCountableFunctionTypeSpecifyingExtension.php deleted file mode 100644 index c05579be5a..0000000000 --- a/src/Type/Php/IsCountableFunctionTypeSpecifyingExtension.php +++ /dev/null @@ -1,59 +0,0 @@ -getName()) === 'is_countable' - && !$context->null(); - } - - public function specifyTypes(FunctionReflection $functionReflection, FuncCall $node, Scope $scope, TypeSpecifierContext $context): SpecifiedTypes - { - if ($context->null()) { - throw new ShouldNotHappenException(); - } - - if (!isset($node->getArgs()[0])) { - return new SpecifiedTypes(); - } - - return $this->typeSpecifier->create( - $node->getArgs()[0]->value, - new UnionType([ - new ArrayType(new MixedType(), new MixedType()), - new ObjectType(Countable::class), - ]), - $context, - false, - $scope, - ); - } - - public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void - { - $this->typeSpecifier = $typeSpecifier; - } - -} diff --git a/src/Type/Php/IsNullFunctionTypeSpecifyingExtension.php b/src/Type/Php/IsNullFunctionTypeSpecifyingExtension.php deleted file mode 100644 index 403ee6c337..0000000000 --- a/src/Type/Php/IsNullFunctionTypeSpecifyingExtension.php +++ /dev/null @@ -1,46 +0,0 @@ -getName()) === 'is_null' - && !$context->null(); - } - - public function specifyTypes(FunctionReflection $functionReflection, FuncCall $node, Scope $scope, TypeSpecifierContext $context): SpecifiedTypes - { - if ($context->null()) { - throw new ShouldNotHappenException(); - } - - if (!isset($node->getArgs()[0])) { - return new SpecifiedTypes(); - } - - return $this->typeSpecifier->create($node->getArgs()[0]->value, new NullType(), $context, false, $scope); - } - - public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void - { - $this->typeSpecifier = $typeSpecifier; - } - -} diff --git a/stubs/typeCheckingFunctions.stub b/stubs/typeCheckingFunctions.stub index eff0c2ec36..5714539bff 100644 --- a/stubs/typeCheckingFunctions.stub +++ b/stubs/typeCheckingFunctions.stub @@ -45,3 +45,29 @@ function is_numeric(mixed $value): bool } +/** + * @phpstan-assert-if-true null $value + * @phpstan-assert-if-false !null $value + */ +function is_null(mixed $value): bool +{ + +} + +/** + * @phpstan-assert-if-true bool $value + * @phpstan-assert-if-false !bool $value + */ +function is_bool(mixed $value): bool +{ + +} + +/** + * @phpstan-assert-if-true array|\Countable $value + * @phpstan-assert-if-false !(array|\Countable) $value + */ +function is_countable(mixed $value): bool +{ + +}