From 3a1c110c6aabcea7b07efcc8d917c228ae190b62 Mon Sep 17 00:00:00 2001 From: Joey Smith Date: Sat, 7 Nov 2026 00:03:24 -0600 Subject: [PATCH 1/2] fix(session): declare mixed types read back from PhpDb results mago analyze at Help level flags four mixed-assignment warnings where a value read from the driver is assigned to an undeclared local: - SessionPayload::decode() - unserialize() returns mixed - DbSessionHandler::read() - ResultInterface::current() returns mixed, and the array offset read from it is mixed - PhpDbSessionPersistence::initializeSessionFromRequest() - same current() call Each value is genuinely mixed, so the fix declares it with a local @var annotation rather than narrowing it to a type the driver does not promise. No behaviour change: the existing is_array()/is_string() guards still do the narrowing. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- src/Session/DbSessionHandler.php | 5 ++++- src/Session/PhpDbSessionPersistence.php | 1 + src/Session/SessionPayload.php | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Session/DbSessionHandler.php b/src/Session/DbSessionHandler.php index 2785c60..2b5a99b 100644 --- a/src/Session/DbSessionHandler.php +++ b/src/Session/DbSessionHandler.php @@ -124,7 +124,10 @@ public function read(string $id): string|false ->where(['id' => $id]); $select->where->greaterThan('expires_at', date(format: self::TIMESTAMP_FORMAT)); - $row = $this->sql->prepareStatementForSqlObject($select)->execute()?->current(); + /** @var mixed $row */ + $row = $this->sql->prepareStatementForSqlObject($select)->execute()?->current(); + + /** @var mixed $payload */ $payload = is_array($row) ? $row['payload'] ?? false : false; return is_string($payload) ? $payload : false; diff --git a/src/Session/PhpDbSessionPersistence.php b/src/Session/PhpDbSessionPersistence.php index 090dc0d..e3eb967 100644 --- a/src/Session/PhpDbSessionPersistence.php +++ b/src/Session/PhpDbSessionPersistence.php @@ -135,6 +135,7 @@ public function initializeSessionFromRequest(ServerRequestInterface $request): S ->where(['id' => $id]); $select->where->greaterThan('expires_at', date(format: self::TIMESTAMP_FORMAT)); + /** @var mixed $row */ $row = $this->sql->prepareStatementForSqlObject($select)->execute()?->current(); if (! is_array($row)) { diff --git a/src/Session/SessionPayload.php b/src/Session/SessionPayload.php index fb7748a..31ede3f 100644 --- a/src/Session/SessionPayload.php +++ b/src/Session/SessionPayload.php @@ -34,6 +34,7 @@ final class SessionPayload */ public static function decode(string $payload): array { + /** @var mixed $data */ $data = unserialize(data: $payload); /** @var array */ From 5b0c1b5fa29cac44b43103fb832b2b46b5d5a60f Mon Sep 17 00:00:00 2001 From: Joey Smith Date: Sat, 7 Nov 2026 00:13:46 -0600 Subject: [PATCH 2/2] fix(schema): suppress mago literal inference on enum schema name mago types $schema::NAME as the literal string('') from SchemaInterface::NAME and does not account for an implementing enum overriding that constant, so it reports the else branch of the '' === $schema::NAME ternary as unreachable. The branch is live: WebwareSchema redeclares NAME as 'webware', and SchemaFactoryTest::itPreservesSchemaFromEnumConstant asserts it. Suppress both findings with an inline end-of-line pragma rather than refactoring working code. Inline placement is deliberate: an own-line pragma that matches nothing binds to the next later occurrence in the file (mago issue #2652), and this file has two identical sites. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- src/SchemaFactory.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/SchemaFactory.php b/src/SchemaFactory.php index 9ebd4e0..fc3894f 100644 --- a/src/SchemaFactory.php +++ b/src/SchemaFactory.php @@ -92,9 +92,12 @@ public function backup( ?string $prefix = null, ?string $separator = null, ): TableIdentifier { - $name = Type\non_empty_string()->assert($schema->value); - $enumSchema = '' === $schema::NAME ? null : $schema::NAME; - $schemas = $this->config['schemas'] ?? []; + $name = Type\non_empty_string()->assert($schema->value); + + // mago infers string('') from SchemaInterface::NAME and ignores that an implementing + // enum may override it; see SchemaInterface::NAME docblock and itPreservesSchemaFromEnumConstant. + $enumSchema = '' === $schema::NAME ? null : $schema::NAME; // @mago-expect analysis:redundant-comparison, analysis:redundant-condition + $schemas = $this->config['schemas'] ?? []; return new TableIdentifier( table : $name, @@ -139,10 +142,13 @@ public function __invoke( ?string $prefix = null, ?string $separator = null, ): TableIdentifier { - $name = Type\non_empty_string()->assert($schema->value); - $enumSchema = '' === $schema::NAME ? null : $schema::NAME; - $prefixes = $this->config['prefixes'] ?? []; - $schemas = $this->config['schemas'] ?? []; + $name = Type\non_empty_string()->assert($schema->value); + + // mago infers string('') from SchemaInterface::NAME and ignores that an implementing + // enum may override it; see SchemaInterface::NAME docblock and itPreservesSchemaFromEnumConstant. + $enumSchema = '' === $schema::NAME ? null : $schema::NAME; // @mago-expect analysis:redundant-comparison, analysis:redundant-condition + $prefixes = $this->config['prefixes'] ?? []; + $schemas = $this->config['schemas'] ?? []; return new TableIdentifier( table : $name,