Remove dead code in Profiler, add static analysis annotations#1
Closed
simon-mundy wants to merge 2 commits into
Closed
Remove dead code in Profiler, add static analysis annotations#1simon-mundy wants to merge 2 commits into
simon-mundy wants to merge 2 commits into
Conversation
- Profiler::profilerStart(): remove unreachable else-branch. The union
type `string|StatementContainerInterface` guarantees only those two
types can be passed; the if/elseif handles both exhaustively, making
the else+throw dead code. Clean up unused imports (InvalidArgumentException,
is_string).
- AbstractPdo::checkEnvironment(): mark the throw inside
`if (!extension_loaded('PDO'))` with @codeCoverageIgnore. PDO is a
hard requirement — this branch cannot execute in any environment where
the class is loadable.
- AbstractResultSet::initialize(): add @PHPStan-Ignore for Traversable
assignment. After array and IteratorAggregate branches are handled, the
remaining Traversable is necessarily an Iterator, but PHPStan cannot
narrow it.
simon-mundy
marked this pull request as draft
March 25, 2026 09:49
Rename ~30 test methods across Adapter test suite to follow the convention of naming tests after what they verify rather than which method they call. Pattern applied: - Fluent/chaining tests: testFluent<Method> - Getter tests: test<Method>Returns<What> - Throw tests: test<Method>ThrowsOn<Condition> - Delegation tests: test<Method>DelegatesToX Simple getter/setter tests (testSetSql, testOffsetGet, etc.) left as-is where the method name already describes the behaviour.
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
Minimal src/-only changes that remove provably dead code and add static analysis annotations. No behavioural changes.
Changes
src/Adapter/Profiler/Profiler.php— Remove unreachable else-branch inprofilerStart()The method signature is
string|StatementContainerInterface $target. TheifhandlesStatementContainerInterface, theelseifhandlesstring. PHP's union type enforcement means no other type can reach the method body — theelsebranch with itsInvalidArgumentExceptionthrow is dead code. Removed the branch and cleaned up the now-unusedInvalidArgumentExceptionimport andis_string()import.src/Adapter/Driver/Pdo/AbstractPdo.php— Add@codeCoverageIgnoretocheckEnvironment()throwThe throw fires when
extension_loaded('PDO')returns false. ButAbstractPdoitself requires the PDO extension to be loaded (it imports PDO classes). Any environment where this class is instantiable necessarily has PDO loaded, making the throw unreachable in practice.src/ResultSet/AbstractResultSet.php— Add@phpstan-ignorefor Traversable assignmentIn
initialize(), after thearrayandIteratorAggregatebranches are handled, the remaining$dataSourceis aTraversablethat is necessarily anIterator. PHPStan cannot narrowTraversabletoIteratorhere, so the ignore annotation is appropriate.Test plan
./vendor/bin/phpunit— all 1446 tests pass./vendor/bin/phpstan— 0 errors./vendor/bin/phpcs— no new violations