Skip to content

Commit

Permalink
fix PHPStan 1.11 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
schlndh committed May 11, 2024
1 parent 4f8d640 commit 54acb4c
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 23 deletions.
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
parameters:
ignoreErrors:
-
message: "#^Method MariaStan\\\\PHPStan\\\\Helper\\\\MariaStanError\\:\\:buildPHPSTanRuleError\\(\\) should return PHPStan\\\\Rules\\\\IdentifierRuleError but returns PHPStan\\\\Rules\\\\RuleError\\.$#"
count: 1
path: src/PHPStan/Helper/MariaStanError.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
count: 1
Expand Down
10 changes: 5 additions & 5 deletions src/PHPStan/Helper/MariaStanError.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace MariaStan\PHPStan\Helper;

use PHPStan\Rules\RuleError;
use PHPStan\Rules\IdentifierRuleError;
use PHPStan\Rules\RuleErrorBuilder;

use function array_map;
Expand All @@ -16,21 +16,21 @@ public function __construct(public readonly string $error, public readonly strin
{
}

public function toPHPStanRuleError(): RuleError
public function toPHPStanRuleError(): IdentifierRuleError
{
return self::buildPHPSTanRuleError($this->error, $this->identifier);
}

public static function buildPHPSTanRuleError(string $message, string $identifier): RuleError
public static function buildPHPSTanRuleError(string $message, string $identifier): IdentifierRuleError
{
return RuleErrorBuilder::message($message)
->identifier('mariaStan.' . $identifier)
->build();
}

/**
* @param array<self> $errors
* @return array<RuleError>
* @param list<self> $errors
* @return list<IdentifierRuleError>
*/
public static function arrayToPHPStanRuleErrors(array $errors): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/PHPStan/Helper/MySQLi/PHPStanMySQLiHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function query(Type $queryType): QueryPrepareCallResult

/**
* @param array<array<Type>> $executeParamTypes possible params
* @return array<MariaStanError>
* @return list<MariaStanError>
*/
public function execute(AnalyserResultPHPStanParams $params, array $executeParamTypes): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/PHPStan/Helper/MySQLi/QueryPrepareCallResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
final class QueryPrepareCallResult
{
/**
* @param array<MariaStanError> $errors
* @param array<AnalyserResult> $analyserResults
* @param list<MariaStanError> $errors
* @param list<AnalyserResult> $analyserResults
*/
public function __construct(public readonly array $errors, public readonly array $analyserResults)
{
Expand Down
6 changes: 3 additions & 3 deletions src/PHPStan/Rules/MySQLi/MySQLiRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\IdentifierRuleError;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleError;
use PHPStan\Type\Constant\ConstantArrayType;
use PHPStan\Type\Generic\GenericObjectType;
use PHPStan\Type\Type;
Expand Down Expand Up @@ -73,7 +73,7 @@ public function processNode(Node $node, Scope $scope): array
};
}

/** @return array<RuleError> */
/** @return list<IdentifierRuleError> */
private function handleMysqliCall(string $methodName, MethodCall $node, Scope $scope): array
{
$queryType = $scope->getType($node->getArgs()[0]->value);
Expand All @@ -86,7 +86,7 @@ private function handleMysqliCall(string $methodName, MethodCall $node, Scope $s
return MariaStanError::arrayToPHPStanRuleErrors($result->errors ?? []);
}

/** @return array<string|RuleError> */
/** @return list<IdentifierRuleError> */
private function handleMysqliStmtCall(string $methodName, MethodCall $node, Scope $scope): array
{
if ($methodName !== 'execute') {
Expand Down
13 changes: 10 additions & 3 deletions src/PHPStan/Rules/MySQLi/MySQLiWrapperRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace MariaStan\PHPStan\Rules\MySQLi;

use MariaStan\PHPStan\Helper\MariaStanError;
use MariaStan\PHPStan\Helper\MariaStanErrorIdentifiers;
use MariaStan\PHPStan\Helper\MySQLi\PHPStanMySQLiHelper;
use MariaStan\PHPStan\MySQLiWrapper;
use MariaStan\Util\MysqliUtil;
Expand Down Expand Up @@ -76,8 +77,11 @@ public function processNode(Node $node, Scope $scope): array

if (count($tableConstantStrings) !== 1) {
return [
"Dynamic SQL: expected table as constant string, got: "
MariaStanError::buildPHPSTanRuleError(
"Dynamic SQL: expected table as constant string, got: "
. $tableType->describe(VerbosityLevel::precise()),
MariaStanErrorIdentifiers::DYNAMIC_SQL,
),
];
}

Expand All @@ -86,8 +90,11 @@ public function processNode(Node $node, Scope $scope): array

if (count($dataConstantArrays) !== 1) {
return [
"Dynamic SQL: expected data as constant array, got: "
. $dataType->describe(VerbosityLevel::precise()),
MariaStanError::buildPHPSTanRuleError(
"Dynamic SQL: expected data as constant array, got: "
. $dataType->describe(VerbosityLevel::precise()),
MariaStanErrorIdentifiers::DYNAMIC_SQL,
),
];
}

Expand Down
11 changes: 2 additions & 9 deletions src/Parser/MariaDbParserState.php
Original file line number Diff line number Diff line change
Expand Up @@ -2606,17 +2606,13 @@ private function parseIndexHints(): array
return $indexHints;
}

/**
* @phpstan-impure
* @throws ParserException
*/
/** @throws ParserException */
private function getPreviousToken(): Token
{
// It can only be called after a token was consumed.
return $this->tokens[$this->position - 1] ?? throw new UnexpectedTokenException('No previous token');
}

/** @phpstan-impure */
private function findCurrentToken(): ?Token
{
if ($this->position >= $this->tokenCount) {
Expand All @@ -2626,10 +2622,7 @@ private function findCurrentToken(): ?Token
return $this->tokens[$this->position];
}

/**
* @phpstan-impure
* @throws ParserException
*/
/** @throws ParserException */
private function getCurrentToken(): Token
{
return $this->tokens[$this->position] ?? throw new UnexpectedTokenException('Out of tokens');
Expand Down
1 change: 1 addition & 0 deletions tests/DbReflection/DbReflectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public static function provideDbReflections(): iterable

assert(self::$dumpFile !== null);
$meta_data = stream_get_meta_data(self::$dumpFile);
self::assertArrayHasKey('uri', $meta_data);
$filename = $meta_data["uri"];

yield 'file - current' => [new MariaDbFileDbReflection($filename, $informationSchemaParser)];
Expand Down

0 comments on commit 54acb4c

Please sign in to comment.