Repository navigation
chore: raise PHPStan to level 8 and add PHP 8.5 to CI - #58
Merged
Merged
Conversation
Contributor
|
@Vondry Hi, Thanks for PR |
Level 6 requires iterable value types and explicit return types. Annotate the array/Collection generics on ContentField, Seo, SeoExtension and SeoInjectorWidget, declare SeoField::getTwigValue(): Markup, and give Seo::ogtype()/robots() a string return type (casting the config override branch, which was the only untyped path).
Level 7 flags unresolved union types. Narrow the container lookups in Extension: annotate the translator service as TranslatorInterface, and guard that kernel.project_dir and bolt.public_folder are strings before building the asset destination path.
Level 8 flags member access on nullables. Guard the nullable content definition in ContentField::getFieldDefinition(), fall back to the un-collapsed string when preg_replace() fails in Seo::cleanUp(), and throw when the extension is missing from the registry instead of returning null from SeoExtension::getExtension(). # Conflicts: # src/Seo/Seo.php
Rector's dry-run in CI flags the fully-qualified \RuntimeException introduced with the level 7 and 8 null guards.
Vondry
force-pushed
the
chore/static-analysis-level-8
branch
from
July 27, 2026 11:10
6e13bee to
b5fbc31
Compare
Contributor
Author
Contributor
|
Thanks again. |
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
Raises static analysis from PHPStan level 5 to level 8 in three incremental steps, fixing every issue surfaced at each level. Also adds PHP 8.5 to the CI matrix.
No behavioural changes are intended. Most changes consist of improved type annotations and null guards on paths that were already unreachable or correct in practice, with two genuine robustness improvements noted below.
Changes by level
Level 6 — iterable value types & missing return types
ContentField::getFieldDefinition()andgetField()— annotated$fieldsasarray<int, string>.SeoInjectorWidget::run()— annotated$paramsasarray<string, mixed>.Seo— typed$defaultsOverrideand$seoDataasarray<string, mixed>, and the constructor's$configasCollection<string, mixed>.SeoExtension— added@return array<string, mixed>toseoGetConfig()andCollection<string, mixed>togetExtensionConfig().SeoField::getTwigValue()— declared a: Markupreturn type. The parent method's untyped@return string|array|Markup|boolannotation was the source of the unspecified array-type warning.Seo::ogtype()androbots()— declared: string, casting the configuration-override branch, which was the only path not already guaranteed to return a string.Level 7 — unresolved union types
Extension::initialize()—getContainer()->get('translator')returnsobject; narrowed it toTranslatorInterfacevia an inline annotation, matching the existing pattern used inSeoExtension.Extension::install()—getParameter()returnsarray|bool|float|int|string|UnitEnum|null. A simple(string)cast is insufficient because arrays are not safely castable. The code now validates withis_string()and throws otherwise.This is a genuine robustness improvement: a non-string
bolt.public_foldervalue would previously have causedFilesystem::mirror()to copy assets into an invalid path.Level 8 — member access on nullable values
ContentField::getFieldDefinition()—Content::getDefinition()returns?ContentType; added an early return before dereferencing->get('fields').Seo::cleanUp()—preg_replace()returnsstring|null(nullon failure, such as malformed UTF-8 with the/umodifier), while the method declaresstring. The method now falls back to the original input instead of propagatingnull.This is a genuine robustness improvement rather than a PHPStan-only change.
SeoExtension::getExtension()—ExtensionRegistry::getExtension()returns?ExtensionInterface; now throws if the extension is not registered instead of returningnullfrom a non-nullable method.CI
Added PHP 8.5 to the
code_analysismatrix after verifying compatibility:composer check-platform-reqspasses on PHP 8.5 (exit code0).composer why-not php 8.5reports no dependencies with an upper PHP version constraint below 8.5.The
rector_analysisjob remains pinned to PHP 8.4 because it is a single, non-matrix job and Rector's output is version-independent for this project.Testing