Skip to content

Commit 269dad6

Browse files
committedSep 14, 2022
Apply PHP 7.4 syntax and typed property
Signed-off-by: Abdul Malik Ikhsan <[email protected]>
1 parent 565928f commit 269dad6

File tree

2 files changed

+37
-67
lines changed

2 files changed

+37
-67
lines changed
 

‎src/CacheSessionPersistence.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ class CacheSessionPersistence implements SessionPersistenceInterface
3131
use CacheHeadersGeneratorTrait;
3232
use SessionCookieAwareTrait;
3333

34-
/** @var CacheItemPoolInterface */
35-
private $cache;
34+
private CacheItemPoolInterface $cache;
3635

37-
/** @var bool */
38-
private $persistent;
36+
private bool $persistent;
3937

4038
/**
4139
* Prepare session cache and default HTTP caching headers.

‎test/CacheSessionPersistenceTest.php

+35-63
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,8 @@ public function assertCookieExpiryMirrorsExpiry(int $expiry, ResponseInterface $
110110
{
111111
$setCookie = $response->getHeaderLine('Set-Cookie');
112112
$parts = explode(';', $setCookie);
113-
$parts = array_map(function ($value) {
114-
return trim($value);
115-
}, $parts);
116-
$parts = array_filter($parts, function (string $value) {
117-
return (bool) preg_match('/^Expires=/', $value);
118-
});
113+
$parts = array_map(static fn($value) => trim($value), $parts);
114+
$parts = array_filter($parts, static fn(string $value) => (bool) preg_match('/^Expires=/', $value));
119115

120116
$this->assertSame(1, count($parts), 'No Expires directive found in cookie: ' . $setCookie);
121117

@@ -136,12 +132,8 @@ public function assertCookieHasNoExpiryDirective(ResponseInterface $response): v
136132
{
137133
$setCookie = $response->getHeaderLine('Set-Cookie');
138134
$parts = explode(';', $setCookie);
139-
$parts = array_map(function ($value) {
140-
return trim($value);
141-
}, $parts);
142-
$parts = array_filter($parts, function (string $value) {
143-
return (bool) preg_match('/^Expires=/', $value);
144-
});
135+
$parts = array_map(static fn($value) => trim($value), $parts);
136+
$parts = array_filter($parts, static fn(string $value) => (bool) preg_match('/^Expires=/', $value));
145137

146138
$this->assertSame(
147139
0,
@@ -561,10 +553,8 @@ public function testPersistSessionRequestingRegenerationPersistsDataAndSetsHeade
561553

562554
$this->cachePool
563555
->method('getItem')
564-
->with($this->callback(function (string $value) {
565-
return $value !== 'identifier'
566-
&& preg_match('/^[a-f0-9]{32}$/', $value);
567-
}))
556+
->with($this->callback(static fn(string $value) => $value !== 'identifier'
557+
&& preg_match('/^[a-f0-9]{32}$/', $value)))
568558
->willReturn($cacheItem);
569559
$this->cachePool->expects($this->atLeastOnce())->method('save')->with($cacheItem);
570560

@@ -603,10 +593,8 @@ public function testPersistSessionRequestingRegenerationRemovesPreviousSession(s
603593

604594
$this->cachePool
605595
->method('getItem')
606-
->with($this->callback(function (string $value) {
607-
return $value !== 'identifier'
608-
&& preg_match('/^[a-f0-9]{32}$/', $value);
609-
}))
596+
->with($this->callback(static fn(string $value) => $value !== 'identifier'
597+
&& preg_match('/^[a-f0-9]{32}$/', $value)))
610598
->willReturn($cacheItem);
611599
$this->cachePool->expects($this->atLeastOnce())->method('save')->with($cacheItem);
612600

@@ -644,10 +632,8 @@ public function testPersistSessionWithIdentifierAndChangedDataPersistsDataAndSet
644632

645633
$this->cachePool
646634
->method('getItem')
647-
->with($this->callback(function (string $value) {
648-
return $value !== 'identifier'
649-
&& preg_match('/^[a-f0-9]{32}$/', $value);
650-
}))
635+
->with($this->callback(static fn(string $value) => $value !== 'identifier'
636+
&& preg_match('/^[a-f0-9]{32}$/', $value)))
651637
->willReturn($cacheItem);
652638
$this->cachePool->expects($this->atLeastOnce())->method('save')->with($cacheItem);
653639

@@ -685,10 +671,8 @@ public function testPersistSessionDeletesPreviousSessionIfItExists(string $cache
685671

686672
$this->cachePool
687673
->method('getItem')
688-
->with($this->callback(function (string $value) {
689-
return $value !== 'identifier'
690-
&& preg_match('/^[a-f0-9]{32}$/', $value);
691-
}))
674+
->with($this->callback(static fn(string $value) => $value !== 'identifier'
675+
&& preg_match('/^[a-f0-9]{32}$/', $value)))
692676
->willReturn($cacheItem);
693677
$this->cachePool->expects($this->atLeastOnce())->method('save')->with($cacheItem);
694678

@@ -782,12 +766,10 @@ public function testPersistenceDurationSpecifiedInSessionUsedWhenPresentEvenWhen
782766
$cacheItem
783767
->expects($this->atLeastOnce())
784768
->method('set')
785-
->with($this->callback(function (array $value) {
786-
return array_key_exists('foo', $value)
787-
&& $value['foo'] === 'bar'
788-
&& array_key_exists(SessionCookiePersistenceInterface::SESSION_LIFETIME_KEY, $value)
789-
&& $value[SessionCookiePersistenceInterface::SESSION_LIFETIME_KEY] === 1200;
790-
}));
769+
->with($this->callback(static fn(array $value) => array_key_exists('foo', $value)
770+
&& $value['foo'] === 'bar'
771+
&& array_key_exists(SessionCookiePersistenceInterface::SESSION_LIFETIME_KEY, $value)
772+
&& $value[SessionCookiePersistenceInterface::SESSION_LIFETIME_KEY] === 1200));
791773
$cacheItem->expects($this->atLeastOnce())->method('expiresAfter')->with($this->isType('int'));
792774
$this->cachePool->method('hasItem')->with('identifier')->willReturn(false);
793775
$this->cachePool
@@ -821,12 +803,10 @@ public function testPersistenceDurationSpecifiedInSessionOverridesExpiryWhenSess
821803
$cacheItem
822804
->expects($this->atLeastOnce())
823805
->method('set')
824-
->with($this->callback(function (array $value) {
825-
return array_key_exists('foo', $value)
826-
&& $value['foo'] === 'bar'
827-
&& array_key_exists(SessionCookiePersistenceInterface::SESSION_LIFETIME_KEY, $value)
828-
&& $value[SessionCookiePersistenceInterface::SESSION_LIFETIME_KEY] === 1200;
829-
}));
806+
->with($this->callback(static fn(array $value) => array_key_exists('foo', $value)
807+
&& $value['foo'] === 'bar'
808+
&& array_key_exists(SessionCookiePersistenceInterface::SESSION_LIFETIME_KEY, $value)
809+
&& $value[SessionCookiePersistenceInterface::SESSION_LIFETIME_KEY] === 1200));
830810
$cacheItem->expects($this->atLeastOnce())->method('expiresAfter')->with($this->isType('int'));
831811
$this->cachePool->method('hasItem')->with('identifier')->willReturn(false);
832812
$this->cachePool
@@ -858,12 +838,10 @@ public function testPersistenceDurationOfZeroSpecifiedInSessionDisablesPersisten
858838
$cacheItem
859839
->expects($this->atLeastOnce())
860840
->method('set')
861-
->with($this->callback(function (array $value) {
862-
return array_key_exists('foo', $value)
863-
&& $value['foo'] === 'bar'
864-
&& array_key_exists(SessionCookiePersistenceInterface::SESSION_LIFETIME_KEY, $value)
865-
&& $value[SessionCookiePersistenceInterface::SESSION_LIFETIME_KEY] === 0;
866-
}));
841+
->with($this->callback(static fn(array $value) => array_key_exists('foo', $value)
842+
&& $value['foo'] === 'bar'
843+
&& array_key_exists(SessionCookiePersistenceInterface::SESSION_LIFETIME_KEY, $value)
844+
&& $value[SessionCookiePersistenceInterface::SESSION_LIFETIME_KEY] === 0));
867845
$cacheItem->expects($this->atLeastOnce())->method('expiresAfter')->with($this->isType('int'));
868846
$this->cachePool->method('hasItem')->with('identifier')->willReturn(false);
869847
$this->cachePool
@@ -900,11 +878,9 @@ public function testPersistenceDurationOfZeroWithoutSessionLifetimeKeyInDataResu
900878
$cacheItem
901879
->expects($this->atLeastOnce())
902880
->method('set')
903-
->with($this->callback(function (array $value) {
904-
return array_key_exists('foo', $value)
905-
&& $value['foo'] === 'bar'
906-
&& ! array_key_exists(SessionCookiePersistenceInterface::SESSION_LIFETIME_KEY, $value);
907-
}));
881+
->with($this->callback(static fn(array $value) => array_key_exists('foo', $value)
882+
&& $value['foo'] === 'bar'
883+
&& ! array_key_exists(SessionCookiePersistenceInterface::SESSION_LIFETIME_KEY, $value)));
908884
$cacheItem->expects($this->atLeastOnce())->method('expiresAfter')->with($this->isType('int'));
909885
$this->cachePool->method('hasItem')->with('identifier')->willReturn(false);
910886
$this->cachePool->method('getItem')->with('identifier')->willReturn($cacheItem);
@@ -937,12 +913,10 @@ public function testPersistenceDurationOfZeroIgnoresGlobalPersistenceExpiry(): v
937913
$cacheItem
938914
->expects($this->atLeastOnce())
939915
->method('set')
940-
->with($this->callback(function (array $value) {
941-
return array_key_exists('foo', $value)
942-
&& $value['foo'] === 'bar'
943-
&& array_key_exists(SessionCookiePersistenceInterface::SESSION_LIFETIME_KEY, $value)
944-
&& $value[SessionCookiePersistenceInterface::SESSION_LIFETIME_KEY] === 0;
945-
}));
916+
->with($this->callback(static fn(array $value) => array_key_exists('foo', $value)
917+
&& $value['foo'] === 'bar'
918+
&& array_key_exists(SessionCookiePersistenceInterface::SESSION_LIFETIME_KEY, $value)
919+
&& $value[SessionCookiePersistenceInterface::SESSION_LIFETIME_KEY] === 0));
946920
$cacheItem->expects($this->atLeastOnce())->method('expiresAfter')->with($this->isType('int'));
947921
$this->cachePool->method('hasItem')->with('identifier')->willReturn(false);
948922
$this->cachePool
@@ -981,12 +955,10 @@ public function testPersistenceDurationInSessionDataWithValueOfZeroIgnoresGlobal
981955
$cacheItem
982956
->expects($this->atLeastOnce())
983957
->method('set')
984-
->with($this->callback(function (array $value) {
985-
return array_key_exists('foo', $value)
986-
&& $value['foo'] === 'baz'
987-
&& array_key_exists(SessionCookiePersistenceInterface::SESSION_LIFETIME_KEY, $value)
988-
&& $value[SessionCookiePersistenceInterface::SESSION_LIFETIME_KEY] === 0;
989-
}));
958+
->with($this->callback(static fn(array $value) => array_key_exists('foo', $value)
959+
&& $value['foo'] === 'baz'
960+
&& array_key_exists(SessionCookiePersistenceInterface::SESSION_LIFETIME_KEY, $value)
961+
&& $value[SessionCookiePersistenceInterface::SESSION_LIFETIME_KEY] === 0));
990962
$cacheItem->expects($this->atLeastOnce())->method('expiresAfter')->with($this->isType('int'));
991963
$this->cachePool->method('hasItem')->with('identifier')->willReturn(false);
992964
$this->cachePool

0 commit comments

Comments
 (0)
Please sign in to comment.