Repository navigation
fix(session): declare PhpDb Sql runtime exceptions in session sources - #27
Merged
Merged
Conversation
Renovate PR #25 moves the php-db/phpdb dev dependency from source reference ed4a407c2f51b951e0261da0bf93baacb23d2e98 to 1570a6122cde75699394a6a38cf17335c3b1d622 on the 0.6.x branch. At 1570a612, Sql::buildSqlString() and Sql::prepareStatementForSqlObject() declare PhpDb\Sql\Exception\RuntimeException, so mago analyze reports unhandled-thrown-type at every call site in this package that was not declaring it, and possible-method-access-on-null where the code reads the magic `where` property of Select and Delete. Declare the exception with @throws where propagation is intended: InitDbCommand::executeDdl and execute; DbSessionHandler::destroy, gc, read, write, updateTimestamp and validateId; PhpDbSessionPersistence::initializeSessionFromRequest, persistSession and the private destroy. No exception is caught, no control flow is changed and runtime behaviour is identical; only docblocks and imports change. The three possible-method-access-on-null findings are recorded in analysis-baseline.toml rather than fixed in source. Select::__get() and Delete::__get() both return getWhere(), which is `return $this->where ??= new Where();`, so the null branch is unreachable at runtime; the nullable type comes only from the `@property ?Where $where` annotation on the vendor classes, which is expected to be corrected upstream. The baseline entries are the two issue blocks mago itself generates for those findings. composer.lock is untouched; the dependency change belongs to #25.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Symptom
Renovate #25 changes only
composer.lock, and bothMago (PHP 8.4)andMago (PHP 8.5)fail on it. The failures are genuine, not a stale baseline: with the bumped dependency installed,mago analyzereports 11 errors insrc/Session.Root cause
#25 moves the dev dependency
php-db/phpdbfrom source referenceed4a407c2f51b951e0261da0bf93baacb23d2e98to1570a6122cde75699394a6a38cf17335c3b1d622on the0.6.xbranch.At
1570a612,php-db/phpdbsrc/Sql/Sql.phpdeclares@throws Exception\RuntimeExceptiononbuildSqlString()andprepareStatementForSqlObject(), andsrc/Sql/Select.phpandsrc/Sql/Delete.phpcarry a class level@property ?Where $whereannotation. Neither is present ated4a407, so the findings appear only once the lock is refreshed.Changes
unhandled-thrown-typeforPhpDb\Sql\Exception\RuntimeException. Propagation is the intended behaviour: a failed prepare or execute must surface to the caller, so each method now declares what it throws. No exception is caught, no control flow changes, and runtime behaviour is identical.InitDbCommand::executeDdlSql::buildSqlString()InitDbCommand::executeexecuteDdl(); cascaded once the callee declared the throwDbSessionHandler::destroyprepareStatementForSqlObject()DbSessionHandler::gcprepareStatementForSqlObject()DbSessionHandler::readprepareStatementForSqlObject()DbSessionHandler::writeprepareStatementForSqlObject()DbSessionHandler::updateTimestampwrite(); cascadedDbSessionHandler::validateIdread(); cascadedPhpDbSessionPersistence::initializeSessionFromRequestprepareStatementForSqlObject()PhpDbSessionPersistence::persistSessionprepareStatementForSqlObject()and the privatedestroy()PhpDbSessionPersistence::destroy(private)prepareStatementForSqlObject()Fixing the eight reported sites exposed three more at their callers, so eleven
@throwslines are added in total, plus theSqlRuntimeExceptionimport in each of the three files.possible-method-access-on-nullatDbSessionHandlerlines 98 and 121 andPhpDbSessionPersistenceline 134 is baselined rather than fixed in source.The access cannot be null at runtime.
Select::__get()andDelete::__get()both return$this->getWhere(), andgetWhere()isreturn $this->where ??= new Where();. The nullable type comes only from the class level@property ?Where $whereannotation on the vendor classes, which is expected to be corrected upstream. Anull === $whereguard in the consumer would be an unreachable defensive branch that can only be covered by stubbing vendorSqlandDeleteand injecting them into the readonly$sqlproperty by reflection, so the three findings are recorded inanalysis-baseline.tomluntil the vendor annotation is fixed. The two entries added to the baseline are the blocksmago analyze --generate-baselineproduces for those findings, copied verbatim; mago reports no outdated entries against them.Guard findings were not touched and remain clean.
Gates
Run locally against
php-db/phpdb1570a612, with the samemago1.59.0 the CI pins:mago format --check:All files are already formatted.mago lint:No issues found.mago analyze: exit 0,found 8 issues: 4 warning(s), 4 help message(s),Filtered out 4 issues based on the baseline file.The 8 remaining are the pre-existingmixed-assignmentwarnings inSessionPayload,DbSessionHandlerandPhpDbSessionPersistenceand theredundant-comparison/redundant-conditionhelp messages inSchemaFactory; they are identical ated4a407.mago guard:No issues found.OK (70 tests, 141 assertions)SchemaFactoryIntegrationTest::itCreatesPrefixedTableOnPgsqlfailing withcould not find driver;pdo_pgsqlis not installed in this environment, and the failure is identical before and after the change.Run locally against the currently locked
php-db/phpdbed4a407(what this PR's own CI sees):mago format --check,mago lint,mago guard: clean.mago analyze: exit 0, same 8 pre-existing warnings and help messages, plusYour baseline file contains 3 entries for issues that no longer exist. That warning is expected: the three baseline entries describe findings that only exist at1570a612. It is informational and does not fail the run, and it disappears once Lock file maintenance #25 is rebased onto this branch.Scope
composer.lockis untouched.php-db/phpdbis untouched; the vendor tree was swapped locally only to reproduce and was restored withcomposer reinstall php-db/phpdbbefore committing. No suppression comments were added.