What was done to fix the analysis findings
mago analyze flagged 3 non-existent-method findings in src/Result.php:
rewind(): $this->resource->data_seek(0) where data_seek does not exist on plain mysqli.
loadFromMysqliResult(): $this->resource->fetch_assoc() where fetch_assoc does not exist on plain mysqli.
$this->resource is typed mysqli|mysqli_result|mysqli_stmt. Both call sites previously assumed the resource is never a bare mysqli connection object.
Added explicit instanceof guards immediately before each call, throwing a RuntimeException if the resource is not the expected type, instead of letting the call fail with an undefined method error, and instead of suppressing the finding with @mago-expect.
Rationale
Connection::execute() can pass the raw mysqli connection object itself into Driver::createResult() when a query is a non-SELECT (write) query that succeeds (true === $resultResource ? $this->resource : $resultResource). This means a Result instance can genuinely wrap a bare mysqli connection object rather than a mysqli_result or mysqli_stmt.
Calling rewind() or otherwise iterating such a Result would previously crash with an undefined method fatal error. The guards added turn that into a clear, specific RuntimeException instead.
Fixing the underlying design gap in this PR (whether Result should even wrap a bare mysqli connection for write queries, or whether iteration over such a Result should be handled differently upstream). Chose not to suppress the mago finding because doing so would make this gap invisible going forward.
What was done to fix the analysis findings
mago analyzeflagged 3non-existent-methodfindings insrc/Result.php:rewind():$this->resource->data_seek(0)wheredata_seekdoes not exist on plainmysqli.loadFromMysqliResult():$this->resource->fetch_assoc()wherefetch_assocdoes not exist on plainmysqli.$this->resourceis typedmysqli|mysqli_result|mysqli_stmt. Both call sites previously assumed the resource is never a baremysqliconnection object.Added explicit
instanceofguards immediately before each call, throwing aRuntimeExceptionif the resource is not the expected type, instead of letting the call fail with an undefined method error, and instead of suppressing the finding with@mago-expect.Rationale
Connection::execute()can pass the rawmysqliconnection object itself intoDriver::createResult()when a query is a non-SELECT (write) query that succeeds (true === $resultResource ? $this->resource : $resultResource). This means aResultinstance can genuinely wrap a baremysqliconnection object rather than amysqli_resultormysqli_stmt.Calling
rewind()or otherwise iterating such aResultwould previously crash with an undefined method fatal error. The guards added turn that into a clear, specificRuntimeExceptioninstead.Fixing the underlying design gap in this PR (whether
Resultshould even wrap a baremysqliconnection for write queries, or whether iteration over such aResultshould be handled differently upstream). Chose not to suppress the mago finding because doing so would make this gap invisible going forward.