[PHPStan] Update PHPStan to 0.12.95 (#724)

* [PHPStan] Update PHPStan to 0.12.95

* ignore new error message on explode and str_split

* Fixed 🎉

* phpstan
This commit is contained in:
Abdul Malik Ikhsan 2021-08-22 00:35:17 +07:00 committed by GitHub
parent a1395e5841
commit ea9cddd31b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 3 deletions

View File

@ -26,7 +26,7 @@ jobs:
- -
name: 'Along PHPStan' name: 'Along PHPStan'
install: composer require phpstan/phpstan:^0.12.94 --dev --ansi install: composer require phpstan/phpstan:^0.12.95 --dev --ansi
name: "PHP ${{ matrix.php_version }}" name: "PHP ${{ matrix.php_version }}"

View File

@ -7,7 +7,7 @@
], ],
"require": { "require": {
"php": "^7.1|^8.0", "php": "^7.1|^8.0",
"phpstan/phpstan": "0.12.94" "phpstan/phpstan": "0.12.95"
}, },
"autoload": { "autoload": {
"files": [ "files": [

View File

@ -20,7 +20,7 @@
"nette/utils": "^3.2", "nette/utils": "^3.2",
"nikic/php-parser": "4.12.0", "nikic/php-parser": "4.12.0",
"phpstan/phpdoc-parser": "^0.5.5", "phpstan/phpdoc-parser": "^0.5.5",
"phpstan/phpstan": "0.12.94", "phpstan/phpstan": "0.12.95",
"phpstan/phpstan-phpunit": "^0.12.21", "phpstan/phpstan-phpunit": "^0.12.21",
"rector/extension-installer": "^0.11.0", "rector/extension-installer": "^0.11.0",
"rector/rector-cakephp": "^0.11.3", "rector/rector-cakephp": "^0.11.3",

View File

@ -538,3 +538,15 @@ parameters:
- rules/Php70/Rector/FuncCall/MultiDirnameRector.php - rules/Php70/Rector/FuncCall/MultiDirnameRector.php
- src/Application/FileProcessor.php - src/Application/FileProcessor.php
- src/PhpParser/Node/BetterNodeFinder.php - src/PhpParser/Node/BetterNodeFinder.php
-
message: '#Parameter \#1 \$separator of function explode expects non\-empty\-string, string given#'
paths:
- rules/PSR4/FileRelocationResolver.php
- rules/Privatization/Rector/Class_/RepeatedLiteralToClassConstantRector.php
- rules/Php74/Rector/LNumber/AddLiteralSeparatorToNumberRector.php
-
message: '#Parameter \#2 \$length of function str_split expects int<1, max\>, int given#'
paths:
- rules/Php74/Rector/LNumber/AddLiteralSeparatorToNumberRector.php

View File

@ -5,7 +5,9 @@ declare(strict_types=1);
namespace Rector\Privatization\TypeManipulator; namespace Rector\Privatization\TypeManipulator;
use PhpParser\Node; use PhpParser\Node;
use PHPStan\Type\Accessory\NonEmptyArrayType;
use PHPStan\Type\ArrayType; use PHPStan\Type\ArrayType;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\MixedType; use PHPStan\Type\MixedType;
use PHPStan\Type\Type; use PHPStan\Type\Type;
use PHPStan\Type\UnionType; use PHPStan\Type\UnionType;
@ -36,9 +38,30 @@ final class NormalizeTypeToRespectArrayScalarType
return new ArrayType($type, $type); return new ArrayType($type, $type);
} }
if ($type instanceof ArrayType) {
return $this->resolveArrayType($type);
}
return $type; return $type;
} }
private function resolveArrayType(ArrayType $arrayType): ArrayType
{
$itemType = $arrayType->getItemType();
if (! $itemType instanceof IntersectionType) {
return $arrayType;
}
$types = $itemType->getTypes();
foreach ($types as $key => $itemTypeType) {
if ($itemTypeType instanceof NonEmptyArrayType) {
unset($types[$key]);
}
}
return new ArrayType($arrayType->getKeyType(), new IntersectionType($types));
}
private function normalizeUnionType(UnionType $unionType): UnionType private function normalizeUnionType(UnionType $unionType): UnionType
{ {
$normalizedTypes = []; $normalizedTypes = [];