From c2deb4cc3ed4154417770c2c0ae9f502ef6dca18 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Sat, 4 May 2024 20:43:10 +0700 Subject: [PATCH] Fix psalm (#832) --- .github/workflows/static.yml | 34 +++++++++---------- composer.json | 2 +- psalm.xml | 6 ++-- psalm83.xml | 22 ++++++++++++ src/Driver/Pdo/AbstractPdoCommand.php | 1 - src/Driver/Pdo/AbstractPdoSchema.php | 2 -- src/Exception/ConvertException.php | 1 - src/Expression/AbstractExpressionBuilder.php | 1 - .../Builder/HashConditionBuilder.php | 1 - src/QueryBuilder/DQLQueryBuilderInterface.php | 2 -- 10 files changed, 43 insertions(+), 29 deletions(-) create mode 100644 psalm83.xml diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index abebcd189..6b3b0fb92 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -1,23 +1,15 @@ on: pull_request: - paths-ignore: - - 'docs/**' - - 'README.md' - - 'CHANGELOG.md' - - '.gitignore' - - '.gitattributes' - - 'infection.json.dist' - - 'phpunit.xml.dist' + paths: + - 'src/**' + - 'config/**' + - 'psalm*.xml' push: - paths-ignore: - - 'docs/**' - - 'README.md' - - 'CHANGELOG.md' - - '.gitignore' - - '.gitattributes' - - 'infection.json.dist' - - 'phpunit.xml.dist' + paths: + - 'src/**' + - 'config/**' + - 'psalm*.xml' name: static analysis @@ -28,4 +20,12 @@ jobs: os: >- ['ubuntu-latest'] php: >- - ['8.1', '8.2', '8.3'] + ['8.1', '8.2'] + psalm83: + uses: yiisoft/actions/.github/workflows/psalm.yml@master + with: + psalm-config: psalm83.xml + os: >- + ['ubuntu-latest'] + php: >- + ['8.3'] diff --git a/composer.json b/composer.json index f79b5dcd6..1637cdeb7 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "rector/rector": "^1.0", "roave/infection-static-analysis-plugin": "^1.16", "spatie/phpunit-watcher": "^1.23", - "vimeo/psalm": "^4.30|^5.20", + "vimeo/psalm": "^4.30|^5.24", "yiisoft/aliases": "^3.0", "yiisoft/cache-file": "^3.1", "yiisoft/di": "^1.0", diff --git a/psalm.xml b/psalm.xml index fc5771199..d39857d9d 100644 --- a/psalm.xml +++ b/psalm.xml @@ -3,6 +3,8 @@ errorLevel="1" findUnusedBaselineEntry="true" findUnusedCode="false" + findUnusedVariablesAndParams="true" + findUnusedPsalmSuppress="true" resolveFromConfigFile="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" @@ -10,9 +12,7 @@ > - - - + diff --git a/psalm83.xml b/psalm83.xml new file mode 100644 index 000000000..19bc35838 --- /dev/null +++ b/psalm83.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + diff --git a/src/Driver/Pdo/AbstractPdoCommand.php b/src/Driver/Pdo/AbstractPdoCommand.php index 0611c834e..54899e993 100644 --- a/src/Driver/Pdo/AbstractPdoCommand.php +++ b/src/Driver/Pdo/AbstractPdoCommand.php @@ -144,7 +144,6 @@ public function prepare(bool|null $forRead = null): void $this->bindPendingParams(); } catch (PDOException $e) { $message = $e->getMessage() . "\nFailed to prepare SQL: $sql"; - /** @psalm-var array|null $errorInfo */ $errorInfo = $e->errorInfo ?? null; throw new Exception($message, $errorInfo, $e); diff --git a/src/Driver/Pdo/AbstractPdoSchema.php b/src/Driver/Pdo/AbstractPdoSchema.php index 76c294f39..58789a0c8 100644 --- a/src/Driver/Pdo/AbstractPdoSchema.php +++ b/src/Driver/Pdo/AbstractPdoSchema.php @@ -21,8 +21,6 @@ abstract class AbstractPdoSchema extends AbstractSchema */ protected function generateCacheKey(): array { - $cacheKey = []; - if ($this->db instanceof PdoConnectionInterface) { $cacheKey = [$this->db->getDriver()->getDsn(), $this->db->getDriver()->getUsername()]; } else { diff --git a/src/Exception/ConvertException.php b/src/Exception/ConvertException.php index e6e7c17a1..1b81b934c 100644 --- a/src/Exception/ConvertException.php +++ b/src/Exception/ConvertException.php @@ -31,7 +31,6 @@ public function run(): Exception { $message = $this->e->getMessage() . PHP_EOL . 'The SQL being executed was: ' . $this->rawSql; - /** @var array|null $errorInfo */ $errorInfo = $this->e instanceof PDOException ? $this->e->errorInfo : null; return match ( diff --git a/src/Expression/AbstractExpressionBuilder.php b/src/Expression/AbstractExpressionBuilder.php index b75775492..6cbcd9c11 100644 --- a/src/Expression/AbstractExpressionBuilder.php +++ b/src/Expression/AbstractExpressionBuilder.php @@ -99,7 +99,6 @@ private function appendParams(array &$expressionParams, array &$params): array $replacements = []; - /** @var non-empty-string $name */ foreach ($nonUniqueParams as $name => $value) { $paramName = $name[0] === ':' ? substr($name, 1) : $name; $uniqueName = $this->getUniqueName($paramName, $params); diff --git a/src/QueryBuilder/Condition/Builder/HashConditionBuilder.php b/src/QueryBuilder/Condition/Builder/HashConditionBuilder.php index f978c4e52..c0d8b121e 100644 --- a/src/QueryBuilder/Condition/Builder/HashConditionBuilder.php +++ b/src/QueryBuilder/Condition/Builder/HashConditionBuilder.php @@ -44,7 +44,6 @@ public function build(HashConditionInterface $expression, array &$params = []): /** * @psalm-var array $hash - * @psalm-var array|mixed $value */ foreach ($hash as $column => $value) { if (is_iterable($value) || $value instanceof QueryInterface) { diff --git a/src/QueryBuilder/DQLQueryBuilderInterface.php b/src/QueryBuilder/DQLQueryBuilderInterface.php index 6a53585cb..20b58ee8f 100644 --- a/src/QueryBuilder/DQLQueryBuilderInterface.php +++ b/src/QueryBuilder/DQLQueryBuilderInterface.php @@ -301,8 +301,6 @@ public function createConditionFromArray(array $condition): ConditionInterface; * @throws InvalidArgumentException * * @return object Instance of {@see ExpressionBuilderInterface} for the given expression. - * - * @psalm-suppress InvalidStringClass */ public function getExpressionBuilder(ExpressionInterface $expression): object;