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
2 changes: 1 addition & 1 deletion src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1893,7 +1893,7 @@ function (MutatingScope $scope) use ($expr, $nodeCallback, $context): Expression
}
};

$constantArrays = TypeUtils::getOldConstantArrays($arrayType);
$constantArrays = $arrayType->getConstantArrays();
if (count($constantArrays) > 0) {
$newArrayTypes = [];
$prepend = $functionReflection->getName() === 'array_unshift';
Expand Down
4 changes: 2 additions & 2 deletions src/Reflection/InitializerExprTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -907,8 +907,8 @@ public function getPlusType(Expr $left, Expr $right, callable $getTypeCallback):
return TypeCombinator::union(...$resultTypes);
}

$leftConstantArrays = TypeUtils::getOldConstantArrays($leftType);
$rightConstantArrays = TypeUtils::getOldConstantArrays($rightType);
$leftConstantArrays = $leftType->getConstantArrays();
$rightConstantArrays = $rightType->getConstantArrays();

$leftCount = count($leftConstantArrays);
$rightCount = count($rightConstantArrays);
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Arrays/NonexistentOffsetInArrayDimFetchCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function check(
$hasOffsetValueType = $type->hasOffsetValueType($dimType);
$report = $hasOffsetValueType->no();
if ($hasOffsetValueType->maybe()) {
$constantArrays = TypeUtils::getOldConstantArrays($type);
$constantArrays = $type->getConstantArrays();
if (count($constantArrays) > 0) {
foreach ($constantArrays as $constantArray) {
if ($constantArray->hasOffsetValueType($dimType)->no()) {
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Comparison/ImpossibleCheckTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function findSpecifiedType(
return null;
}

$constantArrays = TypeUtils::getOldConstantArrays($haystackType);
$constantArrays = $haystackType->getConstantArrays();
$needleType = $scope->getType($node->getArgs()[0]->value);
$valueType = $haystackType->getIterableValueType();
$constantNeedleTypesCount = count(TypeUtils::getConstantScalars($needleType));
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/FunctionCallParametersCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function check(
$argumentName = $arg->name->toString();
}
if ($arg->unpack) {
$arrays = TypeUtils::getOldConstantArrays($type);
$arrays = $type->getConstantArrays();
if (count($arrays) > 0) {
$minKeys = null;
foreach ($arrays as $array) {
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Regexp/RegularExpressionPatternRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private function extractPatterns(FuncCall $functionCall, Scope $scope): array
$patternStrings[] = $constantStringType->getValue();
}

foreach (TypeUtils::getOldConstantArrays($patternType) as $constantArrayType) {
foreach ($patternType->getConstantArrays() as $constantArrayType) {
if (
in_array($functionName, [
'preg_replace',
Expand Down
4 changes: 2 additions & 2 deletions src/Rules/RuleLevelHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public function accepts(Type $acceptingType, Type $acceptedType, bool $strictTyp
$acceptedType->isArray()->yes()
&& $acceptingType->isArray()->yes()
&& !$acceptingType->isIterableAtLeastOnce()->yes()
&& count(TypeUtils::getOldConstantArrays($acceptedType)) === 0
&& count(TypeUtils::getOldConstantArrays($acceptingType)) === 0
&& count($acceptedType->getConstantArrays()) === 0
&& count($acceptingType->getConstantArrays()) === 0
) {
return self::accepts(
$acceptingType->getIterableKeyType(),
Expand Down
5 changes: 5 additions & 0 deletions src/Type/Accessory/AccessoryArrayListType.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public function getReferencedClasses(): array
return [];
}

public function getConstantArrays(): array
{
return [];
}

public function accepts(Type $type, bool $strictTypes): TrinaryLogic
{
if ($type instanceof CompoundType) {
Expand Down
5 changes: 5 additions & 0 deletions src/Type/Accessory/NonEmptyArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public function getReferencedClasses(): array
return [];
}

public function getConstantArrays(): array
{
return [];
}

public function accepts(Type $type, bool $strictTypes): TrinaryLogic
{
if ($type instanceof CompoundType) {
Expand Down
5 changes: 5 additions & 0 deletions src/Type/Accessory/OversizedArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public function getReferencedClasses(): array
return [];
}

public function getConstantArrays(): array
{
return [];
}

public function accepts(Type $type, bool $strictTypes): TrinaryLogic
{
if ($type instanceof CompoundType) {
Expand Down
5 changes: 5 additions & 0 deletions src/Type/ArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public function getReferencedClasses(): array
);
}

public function getConstantArrays(): array
{
return [];
}

public function accepts(Type $type, bool $strictTypes): TrinaryLogic
{
if ($type instanceof CompoundType) {
Expand Down
5 changes: 5 additions & 0 deletions src/Type/Constant/ConstantArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public function __construct(
);
}

public function getConstantArrays(): array
{
return [$this];
}

public function isEmpty(): bool
{
return count($this->keyTypes) === 0;
Expand Down
5 changes: 5 additions & 0 deletions src/Type/IntersectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public function getReferencedClasses(): array
return UnionTypeHelper::getReferencedClasses($this->types);
}

public function getConstantArrays(): array
{
return UnionTypeHelper::getConstantArrays($this->getTypes());
}

public function accepts(Type $otherType, bool $strictTypes): TrinaryLogic
{
foreach ($this->types as $type) {
Expand Down
5 changes: 5 additions & 0 deletions src/Type/MixedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public function getReferencedClasses(): array
return [];
}

public function getConstantArrays(): array
{
return [];
}

public function accepts(Type $type, bool $strictTypes): TrinaryLogic
{
return TrinaryLogic::createYes();
Expand Down
2 changes: 1 addition & 1 deletion src/Type/Php/ArrayColumnFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
$columnType = $scope->getType($functionCall->getArgs()[1]->value);
$indexType = $numArgs >= 3 ? $scope->getType($functionCall->getArgs()[2]->value) : null;

$constantArrayTypes = TypeUtils::getOldConstantArrays($arrayType);
$constantArrayTypes = $arrayType->getConstantArrays();
if (count($constantArrayTypes) === 1) {
$type = $this->handleConstantArray($constantArrayTypes[0], $columnType, $indexType, $scope);
if ($type !== null) {
Expand Down
3 changes: 1 addition & 2 deletions src/Type/Php/ArrayFillKeysFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use PHPStan\Type\NeverType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypeUtils;
use function count;

class ArrayFillKeysFunctionReturnTypeExtension implements DynamicFunctionReturnTypeExtension
Expand All @@ -33,7 +32,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,

$valueType = $scope->getType($functionCall->getArgs()[1]->value);
$keysType = $scope->getType($functionCall->getArgs()[0]->value);
$constantArrays = TypeUtils::getOldConstantArrays($keysType);
$constantArrays = $keysType->getConstantArrays();
if (count($constantArrays) === 0) {
if ($keysType->isArray()->yes()) {
$itemType = $keysType->getIterableValueType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private function filterByTruthyValue(Scope $scope, Error|Variable|null $itemVar,
throw new ShouldNotHappenException();
}

$constantArrays = TypeUtils::getOldConstantArrays($arrayType);
$constantArrays = $arrayType->getConstantArrays();
if (count($constantArrays) > 0) {
$results = [];
foreach ($constantArrays as $constantArray) {
Expand Down
3 changes: 1 addition & 2 deletions src/Type/Php/ArrayFlipFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypeUtils;
use function count;

class ArrayFlipFunctionReturnTypeExtension implements DynamicFunctionReturnTypeExtension
Expand All @@ -32,7 +31,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
$array = $functionCall->getArgs()[0]->value;
$argType = $scope->getType($array);

$constantArrays = TypeUtils::getOldConstantArrays($argType);
$constantArrays = $argType->getConstantArrays();
if (count($constantArrays) > 0) {
$flipped = [];
foreach ($constantArrays as $constantArray) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypeUtils;
use function array_slice;
use function count;

Expand Down Expand Up @@ -47,7 +46,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
return $firstArray;
}

$constantArrays = TypeUtils::getOldConstantArrays($firstArray);
$constantArrays = $firstArray->getConstantArrays();
if (count($constantArrays) === 0) {
return new ArrayType($firstArray->getIterableKeyType(), $firstArray->getIterableValueType());
}
Expand Down
3 changes: 1 addition & 2 deletions src/Type/Php/ArrayKeyFirstDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use PHPStan\Type\NullType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypeUtils;
use function count;

class ArrayKeyFirstDynamicReturnTypeExtension implements DynamicFunctionReturnTypeExtension
Expand All @@ -34,7 +33,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
return new NullType();
}

$constantArrays = TypeUtils::getOldConstantArrays($argType);
$constantArrays = $argType->getConstantArrays();
if (count($constantArrays) > 0) {
$keyTypes = [];
foreach ($constantArrays as $constantArray) {
Expand Down
3 changes: 1 addition & 2 deletions src/Type/Php/ArrayKeyLastDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PHPStan\Type\NullType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypeUtils;
use function count;

class ArrayKeyLastDynamicReturnTypeExtension implements DynamicFunctionReturnTypeExtension
Expand All @@ -33,7 +32,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
return new NullType();
}

$constantArrays = TypeUtils::getOldConstantArrays($argType);
$constantArrays = $argType->getConstantArrays();
if (count($constantArrays) > 0) {
$keyTypes = [];
foreach ($constantArrays as $constantArray) {
Expand Down
2 changes: 1 addition & 1 deletion src/Type/Php/ArrayMapFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
if ($callableIsNull) {
return $arrayType;
}
$constantArrays = TypeUtils::getOldConstantArrays($arrayType);
$constantArrays = $arrayType->getConstantArrays();
if (count($constantArrays) > 0) {
$arrayTypes = [];
foreach ($constantArrays as $constantArray) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypeUtils;
use function count;
use function in_array;

Expand Down Expand Up @@ -44,7 +43,7 @@ public function getTypeFromFunctionCall(
return new ConstantBooleanType(false);
}

$constantArrays = TypeUtils::getOldConstantArrays($argType);
$constantArrays = $argType->getConstantArrays();
if (count($constantArrays) > 0) {
$keyTypes = [];
foreach ($constantArrays as $constantArray) {
Expand Down
3 changes: 1 addition & 2 deletions src/Type/Php/ArrayPopFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PHPStan\Type\NullType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypeUtils;
use function count;

class ArrayPopFunctionReturnTypeExtension implements DynamicFunctionReturnTypeExtension
Expand All @@ -33,7 +32,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
return new NullType();
}

$constantArrays = TypeUtils::getOldConstantArrays($argType);
$constantArrays = $argType->getConstantArrays();
if (count($constantArrays) > 0) {
$valueTypes = [];
foreach ($constantArrays as $constantArray) {
Expand Down
3 changes: 1 addition & 2 deletions src/Type/Php/ArrayReduceFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use PHPStan\Type\NullType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypeUtils;
use function count;

class ArrayReduceFunctionReturnTypeExtension implements DynamicFunctionReturnTypeExtension
Expand Down Expand Up @@ -46,7 +45,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
}

$arraysType = $scope->getType($functionCall->getArgs()[0]->value);
$constantArrays = TypeUtils::getOldConstantArrays($arraysType);
$constantArrays = $arraysType->getConstantArrays();
if (count($constantArrays) > 0) {
$onlyEmpty = TrinaryLogic::createYes();
$onlyNonEmpty = TrinaryLogic::createYes();
Expand Down
3 changes: 1 addition & 2 deletions src/Type/Php/ArrayShiftFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PHPStan\Type\NullType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypeUtils;
use function count;

class ArrayShiftFunctionReturnTypeExtension implements DynamicFunctionReturnTypeExtension
Expand All @@ -33,7 +32,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
return new NullType();
}

$constantArrays = TypeUtils::getOldConstantArrays($argType);
$constantArrays = $argType->getConstantArrays();
if (count($constantArrays) > 0) {
$valueTypes = [];
foreach ($constantArrays as $constantArray) {
Expand Down
3 changes: 1 addition & 2 deletions src/Type/Php/CountFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use PHPStan\Type\IntegerRangeType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypeUtils;
use function count;
use function in_array;
use const COUNT_RECURSIVE;
Expand Down Expand Up @@ -42,7 +41,7 @@ public function getTypeFromFunctionCall(
}

$argType = $scope->getType($functionCall->getArgs()[0]->value);
$constantArrays = TypeUtils::getOldConstantArrays($scope->getType($functionCall->getArgs()[0]->value));
$constantArrays = $scope->getType($functionCall->getArgs()[0]->value)->getConstantArrays();
if (count($constantArrays) === 0) {
if ($argType->isIterableAtLeastOnce()->yes()) {
return IntegerRangeType::fromInterval(1, null);
Expand Down
5 changes: 5 additions & 0 deletions src/Type/StaticType.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public function getReferencedClasses(): array
return $this->getStaticObjectType()->getReferencedClasses();
}

public function getConstantArrays(): array
{
return $this->getStaticObjectType()->getConstantArrays();
}

public function accepts(Type $type, bool $strictTypes): TrinaryLogic
{
if ($type instanceof CompoundType) {
Expand Down
5 changes: 5 additions & 0 deletions src/Type/Traits/LateResolvableTypeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ trait LateResolvableTypeTrait

private ?Type $result = null;

public function getConstantArrays(): array
{
return $this->resolve()->getConstantArrays();
}

public function accepts(Type $type, bool $strictTypes): TrinaryLogic
{
return $this->resolve()->accepts($type, $strictTypes);
Expand Down
5 changes: 5 additions & 0 deletions src/Type/Traits/MaybeArrayTypeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
trait MaybeArrayTypeTrait
{

public function getConstantArrays(): array
{
return [];
}

public function isArray(): TrinaryLogic
{
return TrinaryLogic::createMaybe();
Expand Down
5 changes: 5 additions & 0 deletions src/Type/Traits/NonArrayTypeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
trait NonArrayTypeTrait
{

public function getConstantArrays(): array
{
return [];
}

public function isArray(): TrinaryLogic
{
return TrinaryLogic::createNo();
Expand Down
Loading