Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1261a41

Browse filesBrowse files
committed
[HttpFoundation] Fix return types of SessionHandler::gc()
Signed-off-by: Alexander M. Turek <me@derrabus.de>
1 parent e5c96c4 commit 1261a41
Copy full SHA for 1261a41

10 files changed

+28
-19
lines changed

‎src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcachedSessionHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcachedSessionHandler.php
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,13 @@ protected function doDestroy($sessionId)
9999
}
100100

101101
/**
102-
* @return bool
102+
* @return int|false
103103
*/
104+
#[\ReturnTypeWillChange]
104105
public function gc($maxlifetime)
105106
{
106107
// not required here because memcached will auto expire the records anyhow.
107-
return true;
108+
return 0;
108109
}
109110

110111
/**

‎src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MigratingSessionHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MigratingSessionHandler.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function destroy($sessionId)
6363
}
6464

6565
/**
66-
* @return bool
66+
* @return int|false
6767
*/
6868
#[\ReturnTypeWillChange]
6969
public function gc($maxlifetime)

‎src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,14 @@ protected function doDestroy($sessionId)
100100
}
101101

102102
/**
103-
* @return bool
103+
* @return int|false
104104
*/
105+
#[\ReturnTypeWillChange]
105106
public function gc($maxlifetime)
106107
{
107-
$this->getCollection()->deleteMany([
108+
return $this->getCollection()->deleteMany([
108109
$this->options['expiry_field'] => ['$lt' => new \MongoDB\BSON\UTCDateTime()],
109-
]);
110-
111-
return true;
110+
])->getDeletedCount();
112111
}
113112

114113
/**

‎src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NullSessionHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NullSessionHandler.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ protected function doDestroy($sessionId)
7070
}
7171

7272
/**
73-
* @return bool
73+
* @return int|false
7474
*/
7575
#[\ReturnTypeWillChange]
7676
public function gc($maxlifetime)
7777
{
78-
return true;
78+
return 0;
7979
}
8080
}

‎src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public function read($sessionId)
290290
}
291291

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

302-
return true;
302+
return 0;
303303
}
304304

305305
/**

‎src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,13 @@ public function close(): bool
104104

105105
/**
106106
* {@inheritdoc}
107+
*
108+
* @return int|false
107109
*/
108-
public function gc($maxlifetime): bool
110+
#[\ReturnTypeWillChange]
111+
public function gc($maxlifetime)
109112
{
110-
return true;
113+
return 0;
111114
}
112115

113116
/**

‎src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function testDestroySession()
114114

115115
public function testGcSession()
116116
{
117-
$this->assertTrue($this->storage->gc(123));
117+
$this->assertIsInt($this->storage->gc(123));
118118
}
119119

120120
public function testUpdateTimestamp()

‎src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/Fixtures/common.inc

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/Fixtures/common.inc
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,12 @@ class TestSessionHandler extends AbstractSessionHandler
121121
return true;
122122
}
123123

124-
public function gc($maxLifetime): bool
124+
#[\ReturnTypeWillChange]
125+
public function gc($maxLifetime)
125126
{
126127
echo __FUNCTION__, "\n";
127128

128-
return true;
129+
return 1;
129130
}
130131

131132
protected function doRead($sessionId): string

‎src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function testDestroySession()
113113

114114
public function testGcSession()
115115
{
116-
$this->assertTrue($this->storage->gc(123));
116+
$this->assertIsInt($this->storage->gc(123));
117117
}
118118

119119
/**

‎src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,14 @@ public function testGc()
184184
->willReturnCallback(function ($criteria) {
185185
$this->assertInstanceOf(\MongoDB\BSON\UTCDateTime::class, $criteria[$this->options['expiry_field']]['$lt']);
186186
$this->assertGreaterThanOrEqual(time() - 1, round((string) $criteria[$this->options['expiry_field']]['$lt'] / 1000));
187+
188+
$result = $this->createMock(\MongoDB\DeleteResult::class);
189+
$result->method('getDeletedCount')->willReturn(42);
190+
191+
return $result;
187192
});
188193

189-
$this->assertTrue($this->storage->gc(1));
194+
$this->assertSame(42, $this->storage->gc(1));
190195
}
191196

192197
public function testGetConnection()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.