Skip to content

Commit

Permalink
[PHPStan] Update PHPStan to 0.12.95 (#724)
Browse files Browse the repository at this point in the history
* [PHPStan] Update PHPStan to 0.12.95

* ignore new error message on explode and str_split

* Fixed 🎉

* phpstan
  • Loading branch information
samsonasik committed Aug 21, 2021
1 parent a1395e5 commit ea9cddd
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

-
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 }}"

Expand Down
2 changes: 1 addition & 1 deletion build/target-repository/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
],
"require": {
"php": "^7.1|^8.0",
"phpstan/phpstan": "0.12.94"
"phpstan/phpstan": "0.12.95"
},
"autoload": {
"files": [
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"nette/utils": "^3.2",
"nikic/php-parser": "4.12.0",
"phpstan/phpdoc-parser": "^0.5.5",
"phpstan/phpstan": "0.12.94",
"phpstan/phpstan": "0.12.95",
"phpstan/phpstan-phpunit": "^0.12.21",
"rector/extension-installer": "^0.11.0",
"rector/rector-cakephp": "^0.11.3",
Expand Down
12 changes: 12 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -538,3 +538,15 @@ parameters:
- rules/Php70/Rector/FuncCall/MultiDirnameRector.php
- src/Application/FileProcessor.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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace Rector\Privatization\TypeManipulator;

use PhpParser\Node;
use PHPStan\Type\Accessory\NonEmptyArrayType;
use PHPStan\Type\ArrayType;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use PHPStan\Type\UnionType;
Expand Down Expand Up @@ -36,9 +38,30 @@ public function normalizeToArray(Type $type, ?Node $returnNode): Type
return new ArrayType($type, $type);
}

if ($type instanceof ArrayType) {
return $this->resolveArrayType($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
{
$normalizedTypes = [];
Expand Down

0 comments on commit ea9cddd

Please sign in to comment.