Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use rector-src#dev-upgrade-to-php-parser5-and-phpstan-2 #235

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
27ee014
Use rector-src#dev-upgrade-to-php-parser5-and-phpstan-2
samsonasik Nov 19, 2024
0249dd8
update to php-parser 5 nodes
samsonasik Nov 19, 2024
00efc4e
cs fix
samsonasik Nov 19, 2024
c1ba474
fix print return
samsonasik Nov 19, 2024
767b4d5
fix use Token as array
samsonasik Nov 19, 2024
c05b162
fix use token as array on FollowedByCommaAnalyzer
samsonasik Nov 19, 2024
7b530e2
fix downgrade array spread
samsonasik Nov 19, 2024
47d8b97
[ci-review] Rector Rectify
actions-user Nov 19, 2024
8a82260
fix Throw_ as Expr on DowngradeThrowExprRector
samsonasik Nov 19, 2024
30fb2c7
fix token as array on DowngradeDereferenceableOperationRector
samsonasik Nov 19, 2024
abd18bf
fix constant type on DowngradeNamedArgumentRector
samsonasik Nov 19, 2024
6a88e43
fix ParamTagValueNode usage on DowngradeEnumToConstantListClassRector
samsonasik Nov 19, 2024
48c89e2
fix throw as expr on ArrowFunctionToAnonymousFunctionRector
samsonasik Nov 19, 2024
dc7b56e
[ci-review] Rector Rectify
actions-user Nov 19, 2024
fed1892
fix
samsonasik Nov 19, 2024
12cebe3
fix throw
samsonasik Nov 19, 2024
df89283
[ci-review] Rector Rectify
actions-user Nov 19, 2024
8b8d200
fix downgrade json const and fix token as array
samsonasik Nov 19, 2024
fbb9959
fix fixture on DowngradeUnionTypeDeclarationRector
samsonasik Nov 19, 2024
f1fc769
fix constant type
samsonasik Nov 19, 2024
bd0b1c2
fixing phpstan
samsonasik Nov 19, 2024
5fa0e8d
[ci-review] Rector Rectify
actions-user Nov 19, 2024
04f7089
fix phpstan on DowngradeAttributeToAnnotationRector
samsonasik Nov 19, 2024
866dbd4
fix phpstan
samsonasik Nov 19, 2024
2d70ff9
fix fixture
samsonasik Nov 19, 2024
7b5243d
handle doc indentation
samsonasik Nov 19, 2024
2b4eab9
require dev phpstan webmozart v2 and fix phsptan message return
samsonasik Nov 20, 2024
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
11 changes: 4 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
},
"require-dev": {
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-webmozart-assert": "^1.2",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-webmozart-assert": "^2.0",
"phpunit/phpunit": "^10.5",
"rector/rector-src": "dev-main",
"rector/type-perfect": "^1.0",
"rector/rector-src": "dev-upgrade-to-php-parser5-and-phpstan-2",
"symplify/easy-coding-standard": "^12.3",
"symplify/phpstan-extensions": "^11.4",
"symplify/phpstan-rules": "^13.0",
"symplify/rule-doc-generator": "^12.2",
"symplify/vendor-patches": "^11.3",
"tomasvotruba/class-leak": "^1.0",
Expand All @@ -33,7 +30,7 @@
"classmap": ["stubs"]
},
"scripts": {
"phpstan": "vendor/bin/phpstan analyse --ansi --error-format symplify",
"phpstan": "vendor/bin/phpstan analyse --ansi",
"check-cs": "vendor/bin/ecs check --ansi",
"fix-cs": "vendor/bin/ecs check --fix --ansi"
},
Expand Down
35 changes: 27 additions & 8 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
includes:
- vendor/symplify/phpstan-rules/config/symplify-rules.neon
- vendor/symplify/phpstan-rules/config/rector-rules.neon
# to be enabled later once rector upgraded to use phpstan v2
# includes:
# - vendor/symplify/phpstan-rules/config/symplify-rules.neon
# - vendor/symplify/phpstan-rules/config/rector-rules.neon

parameters:
level: 8
Expand All @@ -10,6 +11,8 @@ parameters:
# requires exact closure types
checkMissingCallableSignature: true

treatPhpDocTypesAsCertain: false

paths:
- src
- config
Expand All @@ -24,11 +27,12 @@ parameters:
- '*/Source/*'

# see https://github.com/rectorphp/type-perfect/
type_perfect:
no_mixed: true
null_over_false: true
narrow_param: true
narrow_return: true
# to be enabled later once rector upgraded to use phpstan v2
# type_perfect:
# no_mixed: true
# null_over_false: true
# narrow_param: true
# narrow_return: true

ignoreErrors:
# php enum value minus
Expand All @@ -55,3 +59,18 @@ parameters:
message: '#Parameter \#1 \$attributeClass of class Rector\\DowngradePhp80\\ValueObject\\DowngradeAttributeToAnnotation constructor expects class\-string, string given#'
path: "config/*"

# more advanced usage, but not always working
# see https://github.com/rectorphp/rector-src/actions/runs/11798721617/job/32865546672?pr=6422#step:5:110
- '#Doing instanceof PHPStan\\Type\\.+ is error\-prone and deprecated#'

# phpstan instanceof
-
identifier: phpstanApi.instanceofAssumption

-
identifier: phpstanApi.varTagAssumption

-
identifier: argument.type

- '#Asking about instanceof PHPStan\\.* is not covered by backward compatibility promise#'
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@ SQL;
SELECT *
FROM `table`
WHERE `column` = true;
SQL
);
SQL);
$this->setOnClick(<<<JAVASCRIPT
document.getElementById('{$this->getHtmlId()}').value = '';
document.getElementById('{$this->getHtmlId()}').onchange();
JAVASCRIPT
);
JAVASCRIPT);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ EOS

$needsDowngrade1 = sprintf(<<<EOS
test %s
EOS
, 'more');
EOS, 'more');

$needsDowngrade2 = <<<EOS
test
EOS
; $z = '';
EOS; $z = '';
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class ErrorsConsoleStyle

public function table(int $terminalWidth, int $maxHeaderWidth): void
{
$f = static function ($rows) use ($terminalWidth, $maxHeaderWidth) : array {
return array_map(static function ($row) use ($terminalWidth, $maxHeaderWidth) : array {
$f = static function ($rows) use ($terminalWidth, $maxHeaderWidth): array {
return array_map(static function ($row) use ($terminalWidth, $maxHeaderWidth): array {
return array_map(static function ($s) use ($terminalWidth, $maxHeaderWidth) {
if ($terminalWidth > $maxHeaderWidth + 5) {
return wordwrap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PreserveByRefClosureUse
$nameScopeMap = [];
$f = function () use ($j, &$nameScopeMap): ?int {
$nameScopeMap[] = function () use ($j): callable {
return static function (int $i) use ($j) : int {
return static function (int $i) use ($j): int {
return $i + $j;
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class WithNullableReturnType
{
public function run()
{
$callable = function () : ?string {
$callable = function (): ?string {
return 'Hello world';
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class WithReturnType
{
public function run()
{
$callable = function () : string {
$callable = function (): string {
return 'Hello world';
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ final class InArrowFunction
];

$mapped = array_map(
static function (mixed $default) : mixed {
static function (mixed $default): mixed {
switch (true) {
case is_string($default):
return sprintf('"%s"', $default);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class InArrowFunction2
{
public function run($value)
{
$mapped = static function (mixed $default) : mixed {
$mapped = static function (mixed $default): mixed {
switch (true) {
case is_string($default):
return sprintf('"%s"', $default);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class InArrowFunctionAsInvokable
{
public function run($value)
{
(static function (mixed $default) : mixed {
(static function (mixed $default): mixed {
switch (true) {
case is_string($default):
return sprintf('"%s"', $default);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class InArrowFunctionInExpression
{
public function run($value)
{
static function (mixed $default) : mixed {
static function (mixed $default): mixed {
switch (true) {
case is_string($default):
return sprintf('"%s"', $default);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class InArrowFunctionInReturn
{
public function run($value)
{
return static function (mixed $default) : mixed {
return static function (mixed $default): mixed {
switch (true) {
case is_string($default):
return sprintf('"%s"', $default);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use PhpParser\Node\Stmt;
final class DoNotChangeCorrectUnionArrayDocblockOnParam
{
/**
* @param int|string[]
* @param int|string[] $data
*/
public function run(int|array $data)
{
}

/**
* @param Node|null|Stmt[]
* @param Node|null|Stmt[] $data
*/
public function run2(Node|null|array $data)
{
Expand All @@ -32,14 +32,14 @@ use PhpParser\Node\Stmt;
final class DoNotChangeCorrectUnionArrayDocblockOnParam
{
/**
* @param int|string[]
* @param int|string[] $data
*/
public function run($data)
{
}

/**
* @param Node|null|Stmt[]
* @param Node|null|Stmt[] $data
*/
public function run2($data)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ array_is_list([1 => 'apple', 'orange']);

namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeArrayIsListRector\Fixture;

$arrayIsListFunction = function (array $array) : bool {
$arrayIsListFunction = function (array $array): bool {
if (function_exists('array_is_list')) {
return array_is_list($array);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeArrayIsListRector

function insideIf($arguments)
{
$arrayIsListFunction = function (array $array) : bool {
$arrayIsListFunction = function (array $array): bool {
if (function_exists('array_is_list')) {
return array_is_list($array);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeArrayIsListRector

function insideReturn($arguments)
{
$arrayIsListFunction = function (array $array) : bool {
$arrayIsListFunction = function (array $array): bool {
if (function_exists('array_is_list')) {
return array_is_list($array);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ final class Loop
}

register_shutdown_function(function () {
$arrayIsListFunction = function (array $array) : bool {
$arrayIsListFunction = function (array $array): bool {
if (function_exists('array_is_list')) {
return array_is_list($array);
}
Expand Down
10 changes: 5 additions & 5 deletions rules/DowngradePhp72/NodeManipulator/JsonConstCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\BitwiseOr;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\Int_;
use Rector\Enum\JsonConstant;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;
Expand All @@ -35,19 +35,19 @@ public function clean(ConstFetch|BitwiseOr $node, array $constants): Expr|null
/**
* @param array<JsonConstant::*> $constants
*/
private function cleanByConstFetch(ConstFetch $constFetch, array $constants): ?LNumber
private function cleanByConstFetch(ConstFetch $constFetch, array $constants): ?Int_
{
if (! $this->nodeNameResolver->isNames($constFetch, $constants)) {
return null;
}

return new LNumber(0);
return new Int_(0);
}

/**
* @param array<JsonConstant::*> $constants
*/
private function cleanByBitwiseOr(BitwiseOr $bitwiseOr, array $constants): null|Expr|LNumber
private function cleanByBitwiseOr(BitwiseOr $bitwiseOr, array $constants): null|Expr|Int_
{
$isLeftTransformed = $this->isTransformed($bitwiseOr->left, $constants);
$isRightTransformed = $this->isTransformed($bitwiseOr->right, $constants);
Expand All @@ -64,7 +64,7 @@ private function cleanByBitwiseOr(BitwiseOr $bitwiseOr, array $constants): null|
return $bitwiseOr->right;
}

return new LNumber(0);
return new Int_(0);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion rules/DowngradePhp72/PhpDoc/NativeParamToPhpDocDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\DowngradePhp72\PhpDoc;

use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\ClassMethod;
Expand All @@ -29,7 +30,7 @@ public function __construct(

public function decorate(ClassMethod $classMethod, Param $param): void
{
if ($param->type === null) {
if (! $param->type instanceof Node) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function getNodeTypes(): array
/**
* @param ConstFetch|BitwiseOr|If_ $node
*/
public function refactor(Node $node): Expr|If_|null|int
public function refactor(Node $node): Expr|If_|null
{
if ($node instanceof If_) {
return $this->refactorIf($node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Param;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\Int_;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\ClassConst;
Expand Down Expand Up @@ -150,7 +150,7 @@ private function refactorClassConst(ClassConst $classConst): ?ClassConst
continue;
}

$classConst->consts[$key]->value = new LNumber(512);
$classConst->consts[$key]->value = new Int_(512);
return $classConst;
}

Expand Down
Loading
Loading