From 8a3bf57e5882bdf1d2525a0cbb2bfda6ed773aa8 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 16 May 2024 18:55:23 +0200 Subject: [PATCH] Fix nikic/php-parser deprecation warnings --- phpstan.neon.dist | 3 --- src/Rules/DoctrineKeyValueStyleRule.php | 4 ++-- src/Rules/PdoStatementExecuteMethodRule.php | 6 +++--- src/Rules/QueryPlanAnalyzerRule.php | 8 ++++---- .../SyntaxErrorInDibiPreparedStatementMethodRule.php | 8 ++++---- src/Rules/SyntaxErrorInPreparedStatementMethodRule.php | 6 +++--- src/Rules/SyntaxErrorInQueryFunctionRule.php | 4 ++-- src/Rules/SyntaxErrorInQueryMethodRule.php | 4 ++-- 8 files changed, 20 insertions(+), 23 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index b334a40e1..94cd061b7 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -35,6 +35,3 @@ parameters: - message: '#^Instanceof between mysqli_result\|string\|null>> and mysqli_result will always evaluate to true\.$#' path: src/DbSchema/SchemaHasherMysql.php - - # nikic/php-parser 4.x compat - - '#Call to deprecated method getLine\(\) of class PhpParser\\NodeAbstract.*#' diff --git a/src/Rules/DoctrineKeyValueStyleRule.php b/src/Rules/DoctrineKeyValueStyleRule.php index f55db14e0..61d7636b2 100644 --- a/src/Rules/DoctrineKeyValueStyleRule.php +++ b/src/Rules/DoctrineKeyValueStyleRule.php @@ -114,7 +114,7 @@ public function processNode(Node $callLike, Scope $scope): array $tableNames = $tableType->getConstantStrings(); if (\count($tableNames) === 0) { return [ - RuleErrorBuilder::message('Argument #0 expects a constant string, got ' . $tableType->describe(VerbosityLevel::precise()))->line($callLike->getLine())->build(), + RuleErrorBuilder::message('Argument #0 expects a constant string, got ' . $tableType->describe(VerbosityLevel::precise()))->line($callLike->getStartLine())->build(), ]; } @@ -185,7 +185,7 @@ public function processNode(Node $callLike, Scope $scope): array $ruleErrors = []; foreach ($errors as $error) { - $ruleErrors[] = RuleErrorBuilder::message('Query error: ' . $error)->line($callLike->getLine())->build(); + $ruleErrors[] = RuleErrorBuilder::message('Query error: ' . $error)->line($callLike->getStartLine())->build(); } return $ruleErrors; } diff --git a/src/Rules/PdoStatementExecuteMethodRule.php b/src/Rules/PdoStatementExecuteMethodRule.php index ebc546a16..21a5ffd64 100644 --- a/src/Rules/PdoStatementExecuteMethodRule.php +++ b/src/Rules/PdoStatementExecuteMethodRule.php @@ -97,7 +97,7 @@ private function checkErrors(MethodReflection $methodReflection, MethodCall $met $parameters = $queryReflection->resolveParameters($parameterTypes) ?? []; } catch (UnresolvableQueryException $exception) { return [ - RuleErrorBuilder::message($exception->asRuleMessage())->tip($exception::getTip())->line($methodCall->getLine())->build(), + RuleErrorBuilder::message($exception->asRuleMessage())->tip($exception::getTip())->line($methodCall->getStartLine())->build(), ]; } @@ -110,13 +110,13 @@ private function checkErrors(MethodReflection $methodReflection, MethodCall $met } } catch (UnresolvableQueryException $exception) { return [ - RuleErrorBuilder::message($exception->asRuleMessage())->tip($exception::getTip())->line($methodCall->getLine())->build(), + RuleErrorBuilder::message($exception->asRuleMessage())->tip($exception::getTip())->line($methodCall->getStartLine())->build(), ]; } $ruleErrors = []; foreach ($errors as $error) { - $ruleErrors[] = RuleErrorBuilder::message($error)->line($methodCall->getLine())->build(); + $ruleErrors[] = RuleErrorBuilder::message($error)->line($methodCall->getStartLine())->build(); } return $ruleErrors; diff --git a/src/Rules/QueryPlanAnalyzerRule.php b/src/Rules/QueryPlanAnalyzerRule.php index 30f07719e..672638850 100644 --- a/src/Rules/QueryPlanAnalyzerRule.php +++ b/src/Rules/QueryPlanAnalyzerRule.php @@ -92,7 +92,7 @@ public function processNode(Node $callLike, Scope $scope): array return $this->analyze($callLike, $scope); } catch (UnresolvableQueryException $exception) { return [ - RuleErrorBuilder::message($exception->asRuleMessage())->tip($exception::getTip())->line($callLike->getLine())->build(), + RuleErrorBuilder::message($exception->asRuleMessage())->tip($exception::getTip())->line($callLike->getStartLine())->build(), ]; } } @@ -144,7 +144,7 @@ private function analyze(CallLike $callLike, Scope $scope): array $table ) ) - ->line($callLike->getLine()) + ->line($callLike->getStartLine()) ->tip('see Mysql Docs https://dev.mysql.com/doc/refman/8.0/en/select-optimization.html') ->build(); } @@ -156,7 +156,7 @@ private function analyze(CallLike $callLike, Scope $scope): array $table ) ) - ->line($callLike->getLine()) + ->line($callLike->getStartLine()) ->tip('see Mysql Docs https://dev.mysql.com/doc/refman/8.0/en/table-scan-avoidance.html') ->build(); } @@ -168,7 +168,7 @@ private function analyze(CallLike $callLike, Scope $scope): array $table ) ) - ->line($callLike->getLine()) + ->line($callLike->getStartLine()) ->tip('see Mysql Docs https://dev.mysql.com/doc/refman/8.0/en/select-optimization.html') ->build(); } diff --git a/src/Rules/SyntaxErrorInDibiPreparedStatementMethodRule.php b/src/Rules/SyntaxErrorInDibiPreparedStatementMethodRule.php index 68079bd15..323de2b56 100644 --- a/src/Rules/SyntaxErrorInDibiPreparedStatementMethodRule.php +++ b/src/Rules/SyntaxErrorInDibiPreparedStatementMethodRule.php @@ -169,7 +169,7 @@ private function checkErrors(CallLike $callLike, Scope $scope, MethodReflection } return [ - RuleErrorBuilder::message($placeholderExpectation . ', ' . $parameterActual . '.')->line($callLike->getLine())->build(), + RuleErrorBuilder::message($placeholderExpectation . ', ' . $parameterActual . '.')->line($callLike->getStartLine())->build(), ]; } } @@ -194,7 +194,7 @@ private function checkErrors(CallLike $callLike, Scope $scope, MethodReflection $validity = $queryReflection->validateQueryString($queryParameters[0]); if (null !== $validity) { - return [RuleErrorBuilder::message($validity->asRuleMessage())->line($callLike->getLine())->build()]; + return [RuleErrorBuilder::message($validity->asRuleMessage())->line($callLike->getStartLine())->build()]; } $result = $queryReflection->getResultType($queryParameters[0], QueryReflector::FETCH_TYPE_BOTH); @@ -204,11 +204,11 @@ private function checkErrors(CallLike $callLike, Scope $scope, MethodReflection $columnsInResult = \count($result->getValueTypes()) / 2; if ('fetchPairs' === $methodReflection->getName() && 2 !== $columnsInResult) { - return [RuleErrorBuilder::message('fetchPairs requires exactly 2 selected columns, got ' . $columnsInResult . '.')->line($callLike->getLine())->build()]; + return [RuleErrorBuilder::message('fetchPairs requires exactly 2 selected columns, got ' . $columnsInResult . '.')->line($callLike->getStartLine())->build()]; } if ('fetchSingle' === $methodReflection->getName() && 1 !== $columnsInResult) { - return [RuleErrorBuilder::message('fetchSingle requires exactly 1 selected column, got ' . $columnsInResult . '.')->line($callLike->getLine())->build()]; + return [RuleErrorBuilder::message('fetchSingle requires exactly 1 selected column, got ' . $columnsInResult . '.')->line($callLike->getStartLine())->build()]; } } diff --git a/src/Rules/SyntaxErrorInPreparedStatementMethodRule.php b/src/Rules/SyntaxErrorInPreparedStatementMethodRule.php index 3d93db029..22acdddca 100644 --- a/src/Rules/SyntaxErrorInPreparedStatementMethodRule.php +++ b/src/Rules/SyntaxErrorInPreparedStatementMethodRule.php @@ -113,7 +113,7 @@ private function checkErrors(CallLike $callLike, Scope $scope): array $parameters = $queryReflection->resolveParameters($parameterTypes) ?? []; } catch (UnresolvableQueryException $exception) { return [ - RuleErrorBuilder::message($exception->asRuleMessage())->tip($exception::getTip())->line($callLike->getLine())->build(), + RuleErrorBuilder::message($exception->asRuleMessage())->tip($exception::getTip())->line($callLike->getStartLine())->build(), ]; } } @@ -144,13 +144,13 @@ private function checkErrors(CallLike $callLike, Scope $scope): array $ruleErrors = []; foreach ($errors as $error) { - $ruleErrors[] = RuleErrorBuilder::message($error)->line($callLike->getLine())->build(); + $ruleErrors[] = RuleErrorBuilder::message($error)->line($callLike->getStartLine())->build(); } return $ruleErrors; } catch (UnresolvableQueryException $exception) { return [ - RuleErrorBuilder::message($exception->asRuleMessage())->tip($exception::getTip())->line($callLike->getLine())->build(), + RuleErrorBuilder::message($exception->asRuleMessage())->tip($exception::getTip())->line($callLike->getStartLine())->build(), ]; } } diff --git a/src/Rules/SyntaxErrorInQueryFunctionRule.php b/src/Rules/SyntaxErrorInQueryFunctionRule.php index a1f8b693e..cb4938ad9 100644 --- a/src/Rules/SyntaxErrorInQueryFunctionRule.php +++ b/src/Rules/SyntaxErrorInQueryFunctionRule.php @@ -96,13 +96,13 @@ public function processNode(Node $node, Scope $scope): array $queryError = $queryReflection->validateQueryString($queryString); if (null !== $queryError) { return [ - RuleErrorBuilder::message($queryError->asRuleMessage())->line($node->getLine())->build(), + RuleErrorBuilder::message($queryError->asRuleMessage())->line($node->getStartLine())->build(), ]; } } } catch (UnresolvableQueryException $exception) { return [ - RuleErrorBuilder::message($exception->asRuleMessage())->tip($exception::getTip())->line($node->getLine())->build(), + RuleErrorBuilder::message($exception->asRuleMessage())->tip($exception::getTip())->line($node->getStartLine())->build(), ]; } diff --git a/src/Rules/SyntaxErrorInQueryMethodRule.php b/src/Rules/SyntaxErrorInQueryMethodRule.php index 7e200f44c..c19bdd52d 100644 --- a/src/Rules/SyntaxErrorInQueryMethodRule.php +++ b/src/Rules/SyntaxErrorInQueryMethodRule.php @@ -91,13 +91,13 @@ public function processNode(Node $node, Scope $scope): array $queryError = $queryReflection->validateQueryString($queryString); if (null !== $queryError) { return [ - RuleErrorBuilder::message($queryError->asRuleMessage())->line($node->getLine())->build(), + RuleErrorBuilder::message($queryError->asRuleMessage())->line($node->getStartLine())->build(), ]; } } } catch (UnresolvableQueryException $exception) { return [ - RuleErrorBuilder::message($exception->asRuleMessage())->tip($exception::getTip())->line($node->getLine())->build(), + RuleErrorBuilder::message($exception->asRuleMessage())->tip($exception::getTip())->line($node->getStartLine())->build(), ]; }