Skip to content

Commit

Permalink
[HttpFoundation] Fix return types of SessionHandler::gc()
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander M. Turek <me@derrabus.de>
  • Loading branch information
derrabus committed Jul 15, 2021
1 parent 48f7bed commit c087ba3
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 19 deletions.
5 changes: 3 additions & 2 deletions Session/Storage/Handler/MemcachedSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,13 @@ protected function doDestroy($sessionId)
}

/**
* @return bool
* @return int|false
*/
#[\ReturnTypeWillChange]
public function gc($maxlifetime)
{
// not required here because memcached will auto expire the records anyhow.
return true;
return 0;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Session/Storage/Handler/MigratingSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function destroy($sessionId)
}

/**
* @return bool
* @return int|false
*/
#[\ReturnTypeWillChange]
public function gc($maxlifetime)
Expand Down
9 changes: 4 additions & 5 deletions Session/Storage/Handler/MongoDbSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,14 @@ protected function doDestroy($sessionId)
}

/**
* @return bool
* @return int|false
*/
#[\ReturnTypeWillChange]
public function gc($maxlifetime)
{
$this->getCollection()->deleteMany([
return $this->getCollection()->deleteMany([
$this->options['expiry_field'] => ['$lt' => new \MongoDB\BSON\UTCDateTime()],
]);

return true;
])->getDeletedCount();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Session/Storage/Handler/NullSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ protected function doDestroy($sessionId)
}

/**
* @return bool
* @return int|false
*/
#[\ReturnTypeWillChange]
public function gc($maxlifetime)
{
return true;
return 0;
}
}
4 changes: 2 additions & 2 deletions Session/Storage/Handler/PdoSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public function read($sessionId)
}

/**
* @return bool
* @return int|false
*/
#[\ReturnTypeWillChange]
public function gc($maxlifetime)
Expand All @@ -299,7 +299,7 @@ public function gc($maxlifetime)
// This way, pruning expired sessions does not block them from being started while the current session is used.
$this->gcCalled = true;

return true;
return 0;
}

/**
Expand Down
7 changes: 5 additions & 2 deletions Session/Storage/Handler/RedisSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,13 @@ public function close(): bool

/**
* {@inheritdoc}
*
* @return int|false
*/
public function gc($maxlifetime): bool
#[\ReturnTypeWillChange]
public function gc($maxlifetime)
{
return true;
return 0;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function testDestroySession()

public function testGcSession()
{
$this->assertTrue($this->storage->gc(123));
$this->assertIsInt($this->storage->gc(123));
}

public function testUpdateTimestamp()
Expand Down
5 changes: 3 additions & 2 deletions Tests/Session/Storage/Handler/Fixtures/common.inc
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,12 @@ class TestSessionHandler extends AbstractSessionHandler
return true;
}

public function gc($maxLifetime): bool
#[\ReturnTypeWillChange]
public function gc($maxLifetime)
{
echo __FUNCTION__, "\n";

return true;
return 1;
}

protected function doRead($sessionId): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function testDestroySession()

public function testGcSession()
{
$this->assertTrue($this->storage->gc(123));
$this->assertIsInt($this->storage->gc(123));
}

/**
Expand Down
7 changes: 6 additions & 1 deletion Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,14 @@ public function testGc()
->willReturnCallback(function ($criteria) {
$this->assertInstanceOf(\MongoDB\BSON\UTCDateTime::class, $criteria[$this->options['expiry_field']]['$lt']);
$this->assertGreaterThanOrEqual(time() - 1, round((string) $criteria[$this->options['expiry_field']]['$lt'] / 1000));

$result = $this->createMock(\MongoDB\DeleteResult::class);
$result->method('getDeletedCount')->willReturn(42);

return $result;
});

$this->assertTrue($this->storage->gc(1));
$this->assertSame(42, $this->storage->gc(1));
}

public function testGetConnection()
Expand Down

0 comments on commit c087ba3

Please sign in to comment.