Skip to content

Commit f772ca5

Browse files
committed
qa: update to laminas-coding-standard v2.1
Updates coding standard constraint to `~2.1.0` and applies it to the code base. Signed-off-by: Matthew Weier O'Phinney <[email protected]>
1 parent 060757f commit f772ca5

26 files changed

+276
-222
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/.phpcs-cache
12
/.phpunit.result.cache
23
/clover.xml
34
/composer.lock

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"psr/http-server-middleware": "^1.0"
3535
},
3636
"require-dev": {
37-
"laminas/laminas-coding-standard": "~1.0.0",
37+
"laminas/laminas-coding-standard": "~2.1.0",
3838
"laminas/laminas-diactoros": "^2.2",
3939
"phpunit/phpunit": "^9.3"
4040
},

phpcs.xml

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
<?xml version="1.0"?>
2-
<ruleset name="Laminas Coding Standard">
3-
<rule ref="./vendor/laminas/laminas-coding-standard/ruleset.xml"/>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
4+
5+
<arg name="basepath" value="."/>
6+
<arg name="cache" value=".phpcs-cache"/>
7+
<arg name="colors"/>
8+
<arg name="extensions" value="php"/>
9+
<arg name="parallel" value="80"/>
10+
11+
<!-- Show progress -->
12+
<arg value="p"/>
413

514
<!-- Paths to check -->
615
<file>src</file>
716
<file>test</file>
17+
18+
<!-- Include all rules from the Laminas Coding Standard -->
19+
<rule ref="LaminasCodingStandard"/>
820
</ruleset>

src/ConfigProvider.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,23 @@
1010

1111
namespace Mezzio\Session;
1212

13+
use Zend\Expressive\Session\SessionMiddleware as LegacySessionMiddleware;
14+
1315
class ConfigProvider
1416
{
15-
public function __invoke() : array
17+
public function __invoke(): array
1618
{
1719
return [
1820
'dependencies' => $this->getDependencies(),
1921
];
2022
}
2123

22-
public function getDependencies() : array
24+
public function getDependencies(): array
2325
{
2426
return [
2527
// Legacy Zend Framework aliases
26-
'aliases' => [
27-
\Zend\Expressive\Session\SessionMiddleware::class => SessionMiddleware::class,
28+
'aliases' => [
29+
LegacySessionMiddleware::class => SessionMiddleware::class,
2830
],
2931
'factories' => [
3032
SessionMiddleware::class => SessionMiddlewareFactory::class,

src/Exception/InvalidHopsValueException.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212

1313
use InvalidArgumentException;
1414

15+
use function sprintf;
16+
1517
class InvalidHopsValueException extends InvalidArgumentException implements ExceptionInterface
1618
{
17-
public static function valueTooLow(string $key, int $hops) : self
19+
public static function valueTooLow(string $key, int $hops): self
1820
{
1921
return new self(sprintf(
2022
'Hops value specified for flash message "%s" was too low; must be greater than 0, received %d',

src/Exception/InvalidSessionSegmentDataException.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@
1212

1313
use RuntimeException;
1414

15+
use function get_class;
16+
use function gettype;
17+
use function is_object;
18+
use function sprintf;
19+
1520
class InvalidSessionSegmentDataException extends RuntimeException implements ExceptionInterface
1621
{
1722
/**
1823
* @param mixed $data
1924
*/
20-
public static function whenRetrieving(string $name, $data) : self
25+
public static function whenRetrieving(string $name, $data): self
2126
{
2227
return new self(sprintf(
2328
'Cannot retrieve session segment "%s"; data exists, but as a "%s" instead of an array',

src/Exception/NotInitializableException.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414
use Mezzio\Session\SessionPersistenceInterface;
1515
use RuntimeException;
1616

17+
use function get_class;
18+
use function sprintf;
19+
1720
final class NotInitializableException extends RuntimeException implements ExceptionInterface
1821
{
19-
public static function invalidPersistence(SessionPersistenceInterface $persistence) : self
22+
public static function invalidPersistence(SessionPersistenceInterface $persistence): self
2023
{
2124
return new self(sprintf(
2225
"Persistence '%s' does not implement '%s'",

src/Exception/SessionSegmentConflictException.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,27 @@
1212

1313
use RuntimeException;
1414

15+
use function sprintf;
16+
1517
class SessionSegmentConflictException extends RuntimeException implements ExceptionInterface
1618
{
17-
public static function whenRetrieving(string $name) : self
19+
public static function whenRetrieving(string $name): self
1820
{
1921
return new self(sprintf(
2022
'Retrieving session data "%s" via get(); however, this data refers to a session segment; aborting',
2123
$name
2224
));
2325
}
2426

25-
public static function whenSetting(string $name) : self
27+
public static function whenSetting(string $name): self
2628
{
2729
return new self(sprintf(
2830
'Attempting to set session data "%s"; however, this data refers to a session segment; aborting',
2931
$name
3032
));
3133
}
3234

33-
public static function whenDeleting(string $name) : self
35+
public static function whenDeleting(string $name): self
3436
{
3537
return new self(sprintf(
3638
'Attempting to unset session data "%s"; however, this data refers to a session segment. '

src/InitializePersistenceIdInterface.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ interface InitializePersistenceIdInterface
1414
{
1515
/**
1616
* Returns new instance with id generated / regenerated, if required
17-
*
18-
* @param SessionInterface $session
19-
* @return SessionInterface
2017
*/
21-
public function initializeId(SessionInterface $session) : SessionInterface;
18+
public function initializeId(SessionInterface $session): SessionInterface;
2219
}

src/InitializeSessionIdInterface.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* @license https://github.com/mezzio/mezzio-session/blob/master/LICENSE.md New BSD License
77
*/
88

9-
109
declare(strict_types=1);
1110

1211
namespace Mezzio\Session;
@@ -15,8 +14,6 @@ interface InitializeSessionIdInterface
1514
{
1615
/**
1716
* Returns id of session, generating / regenerating if required
18-
*
19-
* @return string
2017
*/
21-
public function initializeId() : string;
18+
public function initializeId(): string;
2219
}

src/LazySession.php

+22-20
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,10 @@ final class LazySession implements
2727
SessionInterface,
2828
InitializeSessionIdInterface
2929
{
30-
/**
31-
* @var SessionPersistenceInterface
32-
*/
30+
/** @var SessionPersistenceInterface */
3331
private $persistence;
3432

35-
/**
36-
* @var null|SessionInterface
37-
*/
33+
/** @var null|SessionInterface */
3834
private $proxiedSession;
3935

4036
/**
@@ -47,16 +43,16 @@ final class LazySession implements
4743
public function __construct(SessionPersistenceInterface $persistence, ServerRequestInterface $request)
4844
{
4945
$this->persistence = $persistence;
50-
$this->request = $request;
46+
$this->request = $request;
5147
}
5248

53-
public function regenerate() : SessionInterface
49+
public function regenerate(): SessionInterface
5450
{
5551
$this->proxiedSession = $this->getProxiedSession()->regenerate();
5652
return $this;
5753
}
5854

59-
public function isRegenerated() : bool
55+
public function isRegenerated(): bool
6056
{
6157
if (! $this->proxiedSession) {
6258
return false;
@@ -65,37 +61,44 @@ public function isRegenerated() : bool
6561
return $this->proxiedSession->isRegenerated();
6662
}
6763

68-
public function toArray() : array
64+
public function toArray(): array
6965
{
7066
return $this->getProxiedSession()->toArray();
7167
}
7268

69+
/**
70+
* @param null|mixed $default
71+
* @return mixed
72+
*/
7373
public function get(string $name, $default = null)
7474
{
7575
return $this->getProxiedSession()->get($name, $default);
7676
}
7777

78-
public function has(string $name) : bool
78+
public function has(string $name): bool
7979
{
8080
return $this->getProxiedSession()->has($name);
8181
}
8282

83-
public function set(string $name, $value) : void
83+
/**
84+
* @param mixed $value
85+
*/
86+
public function set(string $name, $value): void
8487
{
8588
$this->getProxiedSession()->set($name, $value);
8689
}
8790

88-
public function unset(string $name) : void
91+
public function unset(string $name): void
8992
{
9093
$this->getProxiedSession()->unset($name);
9194
}
9295

93-
public function clear() : void
96+
public function clear(): void
9497
{
9598
$this->getProxiedSession()->clear();
9699
}
97100

98-
public function hasChanged() : bool
101+
public function hasChanged(): bool
99102
{
100103
if (! $this->proxiedSession) {
101104
return false;
@@ -113,7 +116,7 @@ public function hasChanged() : bool
113116
*
114117
* @since 1.1.0
115118
*/
116-
public function getId() : string
119+
public function getId(): string
117120
{
118121
$proxiedSession = $this->getProxiedSession();
119122
return $proxiedSession instanceof SessionIdentifierAwareInterface
@@ -126,7 +129,7 @@ public function getId() : string
126129
*
127130
* @since 1.2.0
128131
*/
129-
public function persistSessionFor(int $duration) : void
132+
public function persistSessionFor(int $duration): void
130133
{
131134
$proxiedSession = $this->getProxiedSession();
132135
if ($proxiedSession instanceof SessionCookiePersistenceInterface) {
@@ -139,7 +142,7 @@ public function persistSessionFor(int $duration) : void
139142
*
140143
* @since 1.2.0
141144
*/
142-
public function getSessionLifetime() : int
145+
public function getSessionLifetime(): int
143146
{
144147
$proxiedSession = $this->getProxiedSession();
145148
return $proxiedSession instanceof SessionCookiePersistenceInterface
@@ -157,8 +160,7 @@ public function initializeId(): string
157160
return $this->proxiedSession->getId();
158161
}
159162

160-
161-
private function getProxiedSession() : SessionInterface
163+
private function getProxiedSession(): SessionInterface
162164
{
163165
if ($this->proxiedSession) {
164166
return $this->proxiedSession;

src/Persistence/CacheHeadersGeneratorTrait.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ trait CacheHeadersGeneratorTrait
4848
'private_no_expire' => true,
4949
];
5050

51-
/** @var false|string */
51+
/** @var bool|string */
5252
private $lastModified;
5353

5454
/**
5555
* Add cache headers to the response when needed.
5656
*/
57-
private function addCacheHeadersToResponse(ResponseInterface $response) : ResponseInterface
57+
private function addCacheHeadersToResponse(ResponseInterface $response): ResponseInterface
5858
{
5959
if (! $this->cacheLimiter || $this->responseAlreadyHasCacheHeaders($response)) {
6060
return $response;
@@ -74,7 +74,7 @@ private function addCacheHeadersToResponse(ResponseInterface $response) : Respon
7474
* Generate cache http headers for this instance's session cache-limiter and
7575
* cache-expire values.
7676
*/
77-
private function generateCacheHeaders() : array
77+
private function generateCacheHeaders(): array
7878
{
7979
// Unsupported cache_limiter => do not generate cache headers
8080
if (! isset(self::$supportedCacheLimiters[$this->cacheLimiter])) {
@@ -131,7 +131,7 @@ private function getLastModified()
131131
return $this->lastModified;
132132
}
133133

134-
$lastmod = getlastmod() ?: filemtime(__FILE__);
134+
$lastmod = getlastmod() ?: filemtime(__FILE__);
135135
$this->lastModified = $lastmod ? gmdate(Http::DATE_FORMAT, $lastmod) : false;
136136

137137
return $this->lastModified;
@@ -140,7 +140,7 @@ private function getLastModified()
140140
/**
141141
* Check if the response already carries cache headers
142142
*/
143-
private function responseAlreadyHasCacheHeaders(ResponseInterface $response) : bool
143+
private function responseAlreadyHasCacheHeaders(ResponseInterface $response): bool
144144
{
145145
return $response->hasHeader('Expires')
146146
|| $response->hasHeader('Last-Modified')

src/Persistence/Http.php

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Http
2020
* values.
2121
*
2222
* òsee https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Date
23+
*
2324
* @see https://tools.ietf.org/html/rfc7231#section-7.1.1.2
2425
*/
2526
public const DATE_FORMAT = 'D, d M Y H:i:s T';

0 commit comments

Comments
 (0)