Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1539,12 +1539,6 @@ parameters:
count: 16
path: src/Type/Php/BcMathStringOrNullReturnTypeExtension.php

-
rawMessage: 'Doing instanceof PHPStan\Type\Constant\ConstantStringType is error-prone and deprecated. Use Type::getConstantStrings() instead.'
identifier: phpstanApi.instanceofType
count: 1
path: src/Type/Php/ClassExistsFunctionTypeSpecifyingExtension.php

-
rawMessage: 'Doing instanceof PHPStan\Type\Constant\ConstantArrayType is error-prone and deprecated. Use Type::getConstantArrays() instead.'
identifier: phpstanApi.instanceofType
Expand Down Expand Up @@ -1593,24 +1587,12 @@ parameters:
count: 1
path: src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php

-
rawMessage: 'Doing instanceof PHPStan\Type\Constant\ConstantStringType is error-prone and deprecated. Use Type::getConstantStrings() instead.'
identifier: phpstanApi.instanceofType
count: 1
path: src/Type/Php/IsAFunctionTypeSpecifyingExtension.php

-
rawMessage: 'Doing instanceof PHPStan\Type\Constant\ConstantStringType is error-prone and deprecated. Use Type::getConstantStrings() instead.'
identifier: phpstanApi.instanceofType
count: 1
path: src/Type/Php/MbSubstituteCharacterDynamicReturnTypeExtension.php

-
rawMessage: 'Doing instanceof PHPStan\Type\Constant\ConstantStringType is error-prone and deprecated. Use Type::getConstantStrings() instead.'
identifier: phpstanApi.instanceofType
count: 1
path: src/Type/Php/MethodExistsTypeSpecifyingExtension.php

-
rawMessage: 'Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.'
identifier: phpstanApi.instanceofType
Expand All @@ -1635,12 +1617,6 @@ parameters:
count: 1
path: src/Type/Php/NumberFormatFunctionDynamicReturnTypeExtension.php

-
rawMessage: 'Doing instanceof PHPStan\Type\Constant\ConstantStringType is error-prone and deprecated. Use Type::getConstantStrings() instead.'
identifier: phpstanApi.instanceofType
count: 1
path: src/Type/Php/PropertyExistsTypeSpecifyingExtension.php

-
rawMessage: 'Doing instanceof PHPStan\Type\Constant\ConstantStringType is error-prone and deprecated. Use Type::getConstantStrings() instead.'
identifier: phpstanApi.instanceofType
Expand Down
11 changes: 7 additions & 4 deletions src/Type/Php/ClassExistsFunctionTypeSpecifyingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
use PHPStan\Type\BooleanType;
use PHPStan\Type\ClassStringType;
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\FunctionTypeSpecifyingExtension;
use PHPStan\Type\Generic\GenericClassStringType;
use PHPStan\Type\ObjectType;
use function count;
use function in_array;
use function ltrim;

Expand Down Expand Up @@ -49,14 +49,17 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n
{
$args = $node->getArgs();
$argType = $scope->getType($args[0]->value);
if ($argType instanceof ConstantStringType) {

// class_exists() will only assure one of the classes to exist.
$constantStrings = $argType->getConstantStrings();
if (count($constantStrings) === 1) {
if ($functionReflection->getName() === '') {
throw new ShouldNotHappenException();
}
return $this->typeSpecifier->create(
new AlwaysRememberedExpr(
new FuncCall(new FullyQualified($functionReflection->getName()), [
new Arg(new String_(ltrim($argType->getValue(), '\\'))),
new Arg(new String_(ltrim($constantStrings[0]->getValue(), '\\'))),
]),
new BooleanType(),
new BooleanType(),
Expand All @@ -68,7 +71,7 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n
$this->typeSpecifier->create(
new AlwaysRememberedExpr(
new FuncCall(new FullyQualified('class_exists'), [
new Arg(new String_(ltrim($argType->getValue(), '\\'))),
new Arg(new String_(ltrim($constantStrings[0]->getValue(), '\\'))),
]),
new BooleanType(),
new BooleanType(),
Expand Down
22 changes: 8 additions & 14 deletions src/Type/Php/FunctionExistsFunctionTypeSpecifyingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,14 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n

$constantStrings = $argType->getConstantStrings();
if (count($constantStrings) === 1) {
$specifiedTypes = new SpecifiedTypes();

foreach ($constantStrings as $constantString) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to loop, since we know size=1

$specifiedTypes = $specifiedTypes->unionWith($this->typeSpecifier->create(
new FuncCall(new FullyQualified('function_exists'), [
new Arg(new String_(ltrim($constantString->getValue(), '\\'))),
]),
new ConstantBooleanType(true),
$context,
$scope,
));
}

return $specifiedTypes;
return $this->typeSpecifier->create(
new FuncCall(new FullyQualified('function_exists'), [
new Arg(new String_(ltrim($constantStrings[0]->getValue(), '\\'))),
]),
new ConstantBooleanType(true),
$context,
$scope,
);
}

return $this->typeSpecifier->create(
Expand Down
4 changes: 2 additions & 2 deletions src/Type/Php/IsAFunctionTypeSpecifyingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use PHPStan\DependencyInjection\AutowiredService;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\FunctionTypeSpecifyingExtension;
use function count;
use function strtolower;
Expand Down Expand Up @@ -42,7 +41,8 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n
}
$classType = $scope->getType($args[1]->value);

if (!$classType instanceof ConstantStringType && !$context->true()) {
// is_a() will only assure one of the classes to exist.
if (count($classType->getConstantStrings()) !== 1 && !$context->true()) {
return new SpecifiedTypes([], []);
}

Expand Down
6 changes: 4 additions & 2 deletions src/Type/Php/MethodExistsTypeSpecifyingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use PHPStan\Type\Accessory\HasMethodType;
use PHPStan\Type\ClassStringType;
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\FunctionTypeSpecifyingExtension;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\ObjectWithoutClassType;
Expand Down Expand Up @@ -52,9 +51,12 @@ public function specifyTypes(
{
$args = $node->getArgs();
$methodNameType = $scope->getType($args[1]->value);
if (!$methodNameType instanceof ConstantStringType) {
$constantStringTypes = $methodNameType->getConstantStrings();
// method_exists() will only assure one of the methods to exist.
if (count($constantStringTypes) !== 1) {
return $this->createFuncCallSpec($node, $context, $scope);
}
$methodNameType = $constantStringTypes[0];

$objectOrStringType = $scope->getType($args[0]->value);
if ($objectOrStringType->isString()->yes()) {
Expand Down
6 changes: 4 additions & 2 deletions src/Type/Php/PropertyExistsTypeSpecifyingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use PHPStan\Type\Accessory\HasPropertyType;
use PHPStan\Type\ClassStringType;
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\FunctionTypeSpecifyingExtension;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\ObjectWithoutClassType;
Expand Down Expand Up @@ -59,9 +58,12 @@ public function specifyTypes(
{
$args = $node->getArgs();
$propertyNameType = $scope->getType($args[1]->value);
if (!$propertyNameType instanceof ConstantStringType) {
$constantStringTypes = $propertyNameType->getConstantStrings();
// property_exists() will only assure one of the properties to exist.
if (count($constantStringTypes) !== 1) {
return $this->createFuncCallSpec($node, $context, $scope);
}
$propertyNameType = $constantStringTypes[0];

if ($propertyNameType->getValue() === '') {
return new SpecifiedTypes([], []);
Expand Down
Loading