Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"roave/security-advisories": "dev-master",
"webware/webware-console": "1.0.x-dev",
"webware/webware-event": "1.0.0-alpha.3",
"webware/webware-tools": "^1.0.0-rc.5"
"webware/webware-tools": "^1.0.0-rc.6"
},
"suggest": {
"mezzio/mezzio-session": "Required to use the database-backed session persistence",
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions src/Session/DbSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
* @throws SqlInvalidArgumentException
*/
#[Override]
public function gc(int $maxLifetime): int|false

Check warning on line 67 in src/Session/DbSessionHandler.php

View workflow job for this annotation

GitHub Actions / Mago (PHP 8.4)

incompatible-parameter-name

Parameter #1 of `PhpDb\Session\DbSessionHandler::gc()` is named `$maxLifetime` but parent `SessionHandlerInterface::gc()` names it `$max_lifetime` >Parameter named `$maxLifetime` but parent uses `$max_lifetime` >Parent method `SessionHandlerInterface::gc()` parameter `$max_lifetime` defined here >In class `PhpDb\Session\DbSessionHandler` Parameter name changes can break code using named arguments. Help: Consider renaming the parameter to `$max_lifetime` to match the parent method.

Check warning on line 67 in src/Session/DbSessionHandler.php

View workflow job for this annotation

GitHub Actions / Mago (PHP 8.5)

incompatible-parameter-name

Parameter #1 of `PhpDb\Session\DbSessionHandler::gc()` is named `$maxLifetime` but parent `SessionHandlerInterface::gc()` names it `$max_lifetime` >Parameter named `$maxLifetime` but parent uses `$max_lifetime` >Parent method `SessionHandlerInterface::gc()` parameter `$max_lifetime` defined here >In class `PhpDb\Session\DbSessionHandler` Parameter name changes can break code using named arguments. Help: Consider renaming the parameter to `$max_lifetime` to match the parent method.
{
$cutoff = date(format: self::TIMESTAMP_FORMAT);

Expand All @@ -88,13 +88,14 @@
#[Override]
public function read(string $id): string|false
{
$select = $this->sql->select()
$select = $this->sql
->select()
->columns(['payload'])
->where(['id' => $id]);
$select->where->greaterThan('expires_at', date(format: self::TIMESTAMP_FORMAT));

$row = $this->sql->prepareStatementForSqlObject($select)->execute()?->current();

Check warning on line 97 in src/Session/DbSessionHandler.php

View workflow job for this annotation

GitHub Actions / Mago (PHP 8.4)

mixed-assignment

Assigning `mixed` type to a variable may lead to unexpected behavior. >Assigning `mixed` type here. Using `mixed` can lead to runtime errors if the variable is used in a way that assumes a specific type. Help: Consider using a more specific type to avoid potential issues.

Check warning on line 97 in src/Session/DbSessionHandler.php

View workflow job for this annotation

GitHub Actions / Mago (PHP 8.5)

mixed-assignment

Assigning `mixed` type to a variable may lead to unexpected behavior. >Assigning `mixed` type here. Using `mixed` can lead to runtime errors if the variable is used in a way that assumes a specific type. Help: Consider using a more specific type to avoid potential issues.
$payload = is_array($row) ? $row['payload'] ?? false : false;

Check warning on line 98 in src/Session/DbSessionHandler.php

View workflow job for this annotation

GitHub Actions / Mago (PHP 8.4)

mixed-assignment

Assigning `nonnull` type to a variable may lead to unexpected behavior. >Assigning `nonnull` type here. Using `nonnull` can lead to runtime errors if the variable is used in a way that assumes a specific type. Help: Consider using a more specific type to avoid potential issues.

Check warning on line 98 in src/Session/DbSessionHandler.php

View workflow job for this annotation

GitHub Actions / Mago (PHP 8.5)

mixed-assignment

Assigning `nonnull` type to a variable may lead to unexpected behavior. >Assigning `nonnull` type here. Using `nonnull` can lead to runtime errors if the variable is used in a way that assumes a specific type. Help: Consider using a more specific type to avoid potential issues.

return is_string($payload) ? $payload : false;
}
Expand All @@ -112,14 +113,15 @@
);
$now = date(format: self::TIMESTAMP_FORMAT);

$this->sql->prepareStatementForSqlObject(
new Insert(table: SessionTable::Session->value)->values([
'id' => $id,
'payload' => $data,
'expires_at' => $expiresAt,
'modified_at' => $now,
]),
)
$this->sql
->prepareStatementForSqlObject(
new Insert(table: SessionTable::Session->value)->values([
'id' => $id,
'payload' => $data,
'expires_at' => $expiresAt,
'modified_at' => $now,
]),
)
->execute();

return true;
Expand Down
20 changes: 11 additions & 9 deletions src/Session/PhpDbSessionPersistence.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,13 @@
return new Session([], '');
}

$select = $this->sql->select()
$select = $this->sql
->select()
->columns(['payload'])
->where(['id' => $id]);
$select->where->greaterThan('expires_at', date(format: self::TIMESTAMP_FORMAT));

$row = $this->sql->prepareStatementForSqlObject($select)->execute()?->current();

Check warning on line 136 in src/Session/PhpDbSessionPersistence.php

View workflow job for this annotation

GitHub Actions / Mago (PHP 8.4)

mixed-assignment

Assigning `mixed` type to a variable may lead to unexpected behavior. >Assigning `mixed` type here. Using `mixed` can lead to runtime errors if the variable is used in a way that assumes a specific type. Help: Consider using a more specific type to avoid potential issues.

Check warning on line 136 in src/Session/PhpDbSessionPersistence.php

View workflow job for this annotation

GitHub Actions / Mago (PHP 8.5)

mixed-assignment

Assigning `mixed` type to a variable may lead to unexpected behavior. >Assigning `mixed` type here. Using `mixed` can lead to runtime errors if the variable is used in a way that assumes a specific type. Help: Consider using a more specific type to avoid potential issues.

if (! is_array($row)) {
// Session not found or expired - return empty session keeping same ID.
Expand Down Expand Up @@ -185,14 +186,15 @@
$now = date(format: self::TIMESTAMP_FORMAT);
$payload = SessionPayload::encode(data: $session->toArray());

$this->sql->prepareStatementForSqlObject(
new Insert(table: SessionTable::Session->value)->values([
'id' => $id,
'payload' => $payload,
'expires_at' => $expiresAt,
'modified_at' => $now,
]),
)
$this->sql
->prepareStatementForSqlObject(
new Insert(table: SessionTable::Session->value)->values([
'id' => $id,
'payload' => $payload,
'expires_at' => $expiresAt,
'modified_at' => $now,
]),
)
->execute();

$response = $this->addSessionCookieHeaderToResponse($response, $id, $session);
Expand Down
7 changes: 4 additions & 3 deletions test/integration/Support/MysqlSessionTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ protected function expiresAtOf(string $id): ?string

protected function insertRow(string $id, string $payload, string $expiresAt): void
{
$this->pdo->prepare(
query: 'INSERT INTO `session` (id, payload, modified_at, expires_at) VALUES (?, ?, NOW(), ?)',
)
$this->pdo
->prepare(
query: 'INSERT INTO `session` (id, payload, modified_at, expires_at) VALUES (?, ?, NOW(), ?)',
)
->execute([$id, $payload, $expiresAt]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public function invokeBuildsACommandForTheSessionTable(): void
$executed = [];
$adapter = $this->ddlAdapter($executed);
$container = $this->createStub(ContainerInterface::class);
$container->method('get')
$container
->method('get')
->willReturnCallback(
static fn(string $id): AdapterInterface => $adapter,
);
Expand Down
3 changes: 2 additions & 1 deletion test/unit/Session/Console/Schema/SessionSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public function sessionTableHasExactlyTheColumnsBothClassesWrite(): void
#[Test]
public function sessionTableOptionsSetEngineCharsetAndCollation(): void
{
$options = new SessionSchema()->sessionTable('session')
$options = new SessionSchema()
->sessionTable('session')
->getOptions();

self::assertSame(['engine', 'default charset', 'collate'], array_keys($options));
Expand Down
6 changes: 4 additions & 2 deletions test/unit/Session/Container/SessionFactoriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ private function container(array $services): ContainerInterface
$services[AdapterInterface::class] = $this->createStub(AdapterInterface::class);

$container = $this->createStub(ContainerInterface::class);
$container->method('has')
$container
->method('has')
->willReturnCallback(
static fn(string $id): bool => array_key_exists($id, $services),
);
$container->method('get')
$container
->method('get')
->willReturnCallback(
static fn(string $id): mixed => $services[$id],
);
Expand Down
3 changes: 2 additions & 1 deletion test/unit/Support/DdlAdapterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ private function ddlAdapter(array &$executed): AdapterInterface
$adapter = $this->createStub(AdapterInterface::class);
$adapter->method('getDriver')->willReturn($driver);
$adapter->method('getPlatform')->willReturn(new AdapterPlatform($driver));
$adapter->method('query')
$adapter
->method('query')
->willReturnCallback(
function (string $sql) use (&$executed): ResultInterface {
$executed[] = $sql;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ public function itTargetsEveryPublishedEventAtTheTableGateway(): void
private function feature(AbstractTableGateway $gateway): EventDispatcherFeature
{
$dispatcher = $this->createStub(EventDispatcherInterface::class);
$dispatcher->method('dispatch')
$dispatcher
->method('dispatch')
->willReturnCallback(
function (object $event): object {
if ($event instanceof TableGatewayEvent) {
Expand Down
Loading