fix: use FetchAs::Associative enum for fetchAll() in RlAnalyzer#39
Merged
Conversation
Drupal 11 changed the Connection statement fetch-mode argument from the legacy int-based PDO::FETCH_* constants to the Drupal\Core\Database\Statement\FetchAs enum. Passing \PDO::FETCH_ASSOC still works at runtime (PDO defines it as an int), but PHPStan via mglaman/phpstan-drupal flags it as an argument.type error because the type declaration on Connection::fetchAll() is now FetchAs|null: Parameter #1 $mode of method Drupal\Core\Database\StatementInterface::fetchAll() expects Drupal\Core\Database\Statement\FetchAs|null, int given. Two call sites in src/Service/RlAnalyzer.php (lines 407 and 428) were the only remaining drupal-check failures on 1.x. Swap both for FetchAs::Associative and add the corresponding use statement. Verified: - drupal-check (PHPStan) is clean: [OK] No errors (was: Found 2 errors) - drupal-lint (PHPCS) is clean - e2e: 88/88 assertions pass across all 6 test files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix the two pre-existing
drupal-check(PHPStan) failures on1.xby swapping the legacy\PDO::FETCH_ASSOCint constant for the newDrupal\Core\Database\Statement\FetchAs::Associativeenum case.What changed
Drupal 11 moved the fetch-mode argument of
Connection::fetchAll()from the int-basedPDO::FETCH_*constants to a typedFetchAsenum. Passing\PDO::FETCH_ASSOCstill works at runtime (PDO defines it as an int), but PHPStan viamglaman/phpstan-drupalflags it as anargument.typeerror:```
Parameter #1 $mode of method
Drupal\Core\Database\StatementInterface::fetchAll() expects
Drupal\Core\Database\Statement\FetchAs|null, int given.
```
Two call sites in `src/Service/RlAnalyzer.php` (lines 407 and 428) were the only remaining drupal-check failures on `1.x`. Both swapped to `FetchAs::Associative`, plus a matching `use Drupal\Core\Database\Statement\FetchAs;` import.
Why now
These two errors have been present on `1.x` since the repo adopted Drupal 11 compatibility. They were surfaced again during the PR #35 review as the only red CI check that was never blocking a merge but was always noise in the status rollup. Worth fixing in a tiny dedicated PR so every subsequent PR starts from a green baseline.
Verification
Test plan
Scope guardrails