Remove dead code in Profiler, add static analysis annotations#142
Open
simon-mundy wants to merge 5 commits intophp-db:0.6.xfrom
Open
Remove dead code in Profiler, add static analysis annotations#142simon-mundy wants to merge 5 commits intophp-db:0.6.xfrom
simon-mundy wants to merge 5 commits intophp-db:0.6.xfrom
Conversation
…rastructure - Add ~270 new test methods across 60 files, bringing line coverage from 84% (2809/3354) to 99.13% (3289/3318) - Achieve 100% coverage for Sql/*, ResultSet/*, Metadata/*, Container/* - Remove dead code in AbstractSql (unreachable processValuesArgument, defensive throw in processJoin) and AbstractResultSet (unreachable non-Iterator branches in valid/rewind, unreachable throw in initialize) - Remove 9 permanently-skipped tests that were redundant, had contradictory logic, or tested removed functionality - Replace all anonymous classes in tests with proper TestAsset classes for reusability and consistency - Fix invalid #[CoversMethod] attributes causing PHPUnit warnings - Fix #[CoversMethod] parentheses in method name strings - Add REFACTOR.md documenting completed work and remaining Adapter/* gaps Signed-off-by: Simon Mundy <simon.mundy@peptolab.com>
- 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.
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.
Signed-off-by: Simon Mundy <46739456+simon-mundy@users.noreply.github.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.
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 method renames
Renamed ~30 test methods across the Adapter test suite to describe behaviour rather than echo method names (Rule XII). Pattern:
testFluent<Method>for chaining,test<Method>Returns<What>for getters,test<Method>ThrowsOn<Condition>for exceptions.