Repository navigation
#143 - Improve PHPStan level from 6 to 7 - #252
Merged
Merged
Conversation
…el 8 errors not requiring a signature change: explicit exceptions instead of TypeError / Error on edge cases (CsvResource, XpathEvaluatorTransformer, SlugifyTransformer, GenericTransformer, TransformerTrait, RegistryCompilerPass, SubprocessInstance), safe defaults in ProcessState, ConditionTrait, IterableBatchTask and JsonStreamReaderTask Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Description
Refs #143 (step 2: level 7, plus the level 8 errors that can be fixed without breaking backward compatibility; the issue stays open).
phpstan.neongoes from level 6 to level 7 (no ignore), with the level 7 errors fixed:ProcessHelpCommand: branches typed asarray<int, string|null>, the remaining task list kept as alist, task code explicitly cast tostring;CsvResource::tell()throws a\RuntimeExceptionwhenftell()fails (instead of aTypeError);SubprocessInstancethrows a\RuntimeExceptionwhen the PHP executable cannot be found;CsvWriterTask: headers taken from the keys of a list input are cast to strings (same CSV output);FolderBrowserTask(iterator accessed through a private helper),ProcessLauncherTaskprocess_optionsnormalizer,CachedTransformer::generateCacheKey()returningstring|false.Level 8 errors that do not require a signature change are fixed as well (they used to fail with a
TypeErroror anError):CsvResourcerejects a blank header line (headers used to be['']);XpathEvaluatorTransformerthrows an explicit\UnexpectedValueExceptionon an invalid query (with the libxml messages, instead of a PHP warning), on a namespace node to unwrap and on a node without document;SlugifyTransformerthrows an\UnexpectedValueExceptionon a value that cannot be transliterated (e.g. invalid UTF-8);ProcessState::getContext()returns[]until the context is defined, and aContextualOptionResolveris used by default when none is set;ConditionTraitdefaults to a property accessor;GenericTransformerandTransformerTraitthrow an explicit\LogicExceptionwhen not initialized;IterableBatchTaskcan be flushed andJsonStreamReaderTaskiterated before their first execution;RegistryCompilerPasschecks its configuration; null guards inAdvancedStatCounterTaskandAbstractIterableOutputTask.Tests: new
CsvResourceTestandRegistryCompilerPassTest, new cases in 7 existing tests;TransformerTraitTestuses a namedTransformerTraitHolderinstead of an anonymous class (whose methods PHPStan could not see), the test loggers ofLoggerTaskTest/ValidatorTaskTestbuild typed records.On
main, the 12 new regression tests fail. PHPStan (level 7, no ignore), PHPUnit (817 tests), PHP-CS-Fixer and Rector pass.Left for v6.0 (16 level 8 errors)
They all come from native nullable types that are never
nullin practice:AbstractConfigurableTask::getOptions(): ?array,ProcessState::getContextualizedOptions(): ?array,CsvResource::$lineNumber,ProcessHistory::$startDate. PHPStan keeps thenullof the native type even with a stricter PHPDoc, and narrowing the native types is a BC break (e.g.archive-process-bundleUnzipTask/ZipTaskoverridegetOptions(): ?array).Requirements
Breaking changes
None: no native signature is changed. Edge cases that used to fail with a
TypeError/Errornow throw explicit exceptions, or work (ProcessState::getContext(),IterableBatchTask,JsonStreamReaderTask). A CSV file whose first line is blank is now rejected when headers are read from the file.🤖 Generated with Claude Code