Skip to content

Commit 5c6afb1

Browse files
authored
Merge pull request #772 from cakephp/phpstan
Improve type declarations
2 parents 24e899b + 6a514ac commit 5c6afb1

27 files changed

+68
-86
lines changed

.phive/phars.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phive xmlns="https://phar.io/phive">
3-
<phar name="phpstan" version="2.1.33" installed="2.1.33" location="./tools/phpstan" copy="false"/>
3+
<phar name="phpstan" version="2.1.40" installed="2.1.40" location="./tools/phpstan" copy="false"/>
44
</phive>

phpstan-baseline.neon

Lines changed: 0 additions & 7 deletions
This file was deleted.

phpstan.neon

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
includes:
2-
- phpstan-baseline.neon
3-
41
parameters:
52
level: 8
63
paths:
74
- src/
85
ignoreErrors:
9-
- identifier: missingType.generics
10-
- identifier: missingType.iterableValue
6+
- identifier: missingType.iterableValue
7+
- identifier: missingType.generics

src/AbstractCollection.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,19 @@ abstract class AbstractCollection extends ObjectRegistry
3030
/**
3131
* Config array.
3232
*
33-
* @var array
33+
* @var array<string, mixed>
3434
*/
3535
protected array $_defaultConfig = [];
3636

3737
/**
3838
* Constructor
3939
*
40-
* @param array $config Configuration
40+
* @param array<int|string, mixed> $config Configuration
4141
*/
4242
public function __construct(array $config = [])
4343
{
44-
$this->setConfig($config);
44+
$configOptions = array_filter($config, fn($key) => is_string($key), ARRAY_FILTER_USE_KEY);
45+
$this->setConfig($configOptions);
4546

4647
foreach ($config as $key => $value) {
4748
if (is_int($key)) {

src/AuthenticationService.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class AuthenticationService implements AuthenticationServiceInterface, Impersona
9696
* ]);
9797
* ```
9898
*
99-
* @var array
99+
* @var array<string, mixed>
100100
*/
101101
protected array $_defaultConfig = [
102102
'authenticators' => [],
@@ -218,7 +218,7 @@ public function clearIdentity(ServerRequestInterface $request, ResponseInterface
218218
*
219219
* @param \Psr\Http\Message\ServerRequestInterface $request The request.
220220
* @param \Psr\Http\Message\ResponseInterface $response The response.
221-
* @param \ArrayAccess|array $identity Identity data.
221+
* @param \ArrayAccess<string, mixed>|array<string, mixed> $identity Identity data.
222222
* @return array{request: \Psr\Http\Message\ServerRequestInterface, response: \Psr\Http\Message\ResponseInterface}
223223
*/
224224
public function persistIdentity(
@@ -308,7 +308,7 @@ public function getIdentityAttribute(): string
308308
/**
309309
* Builds the identity object
310310
*
311-
* @param \ArrayAccess|array $identityData Identity data
311+
* @param \ArrayAccess<string, mixed>|array<string, mixed> $identityData Identity data
312312
* @return \Authentication\IdentityInterface
313313
*/
314314
public function buildIdentity(ArrayAccess|array $identityData): IdentityInterface
@@ -375,7 +375,7 @@ public function getUnauthenticatedRedirectUrl(ServerRequestInterface $request):
375375
}
376376
$query = urlencode($param) . '=' . urlencode($redirect);
377377

378-
/** @var array $url */
378+
/** @var array<string, mixed> $url */
379379
$url = parse_url($target);
380380
if (isset($url['query']) && strlen($url['query'])) {
381381
$url['query'] .= '&' . $query;
@@ -470,13 +470,13 @@ protected function validateRedirect(string $redirect): ?string
470470
}
471471

472472
/**
473-
* Impersonates a user
473+
* Impersonate a user
474474
*
475475
* @param \Psr\Http\Message\ServerRequestInterface $request The request
476476
* @param \Psr\Http\Message\ResponseInterface $response The response
477-
* @param \ArrayAccess $impersonator User who impersonates
478-
* @param \ArrayAccess $impersonated User impersonated
479-
* @return array
477+
* @param \ArrayAccess<string, mixed> $impersonator User who impersonates
478+
* @param \ArrayAccess<string, mixed> $impersonated User impersonated
479+
* @return array{request: \Psr\Http\Message\ServerRequestInterface, response: \Psr\Http\Message\ResponseInterface}
480480
*/
481481
public function impersonate(
482482
ServerRequestInterface $request,
@@ -494,7 +494,7 @@ public function impersonate(
494494
*
495495
* @param \Psr\Http\Message\ServerRequestInterface $request The request
496496
* @param \Psr\Http\Message\ResponseInterface $response The response
497-
* @return array
497+
* @return array{request: \Psr\Http\Message\ServerRequestInterface, response: \Psr\Http\Message\ResponseInterface}
498498
*/
499499
public function stopImpersonating(ServerRequestInterface $request, ResponseInterface $response): array
500500
{

src/Authenticator/AbstractAuthenticator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ abstract class AbstractAuthenticator implements AuthenticatorInterface
3030
* Default config for this object.
3131
* - `fields` The fields to use to identify a user by.
3232
*
33-
* @var array
33+
* @var array<string, mixed>
3434
*/
3535
protected array $_defaultConfig = [
3636
'fields' => [

src/Authenticator/AuthenticationRequiredException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class AuthenticationRequiredException extends HttpException
4040
/**
4141
* Constructor
4242
*
43-
* @param array $headers The headers that should be sent in the unauthorized challenge response.
43+
* @param array<non-empty-string, array<string>|string> $headers The headers that should be sent in the unauthorized challenge response.
4444
* @param string $body The response body that should be sent in the challenge response.
4545
* @param int $code The exception code that will be used as a HTTP status code
4646
*/

src/Authenticator/CookieAuthenticator.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,11 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
123123
/**
124124
* @inheritDoc
125125
*/
126-
public function persistIdentity(ServerRequestInterface $request, ResponseInterface $response, $identity): array
127-
{
126+
public function persistIdentity(
127+
ServerRequestInterface $request,
128+
ResponseInterface $response,
129+
ArrayAccess|array $identity,
130+
): array {
128131
$field = $this->getConfig('rememberMeField');
129132
$bodyData = $request->getParsedBody();
130133

@@ -149,7 +152,7 @@ public function persistIdentity(ServerRequestInterface $request, ResponseInterfa
149152
*
150153
* Returns concatenated username, password hash, and HMAC signature.
151154
*
152-
* @param \ArrayAccess|array $identity Identity data.
155+
* @param \ArrayAccess<string, mixed>|array<string, mixed> $identity Identity data.
153156
* @return string
154157
*/
155158
protected function _createPlainToken(ArrayAccess|array $identity): string
@@ -186,7 +189,7 @@ protected function _createPlainToken(ArrayAccess|array $identity): string
186189
*
187190
* Cookie token consists of a username and hashed username + password hash.
188191
*
189-
* @param \ArrayAccess|array $identity Identity data.
192+
* @param \ArrayAccess<string, mixed>|array<string, mixed> $identity Identity data.
190193
* @return string
191194
* @throws \JsonException
192195
*/
@@ -203,7 +206,7 @@ protected function _createToken(ArrayAccess|array $identity): string
203206
/**
204207
* Checks whether a token hash matches the identity data.
205208
*
206-
* @param \ArrayAccess|array $identity Identity data.
209+
* @param \ArrayAccess<string, mixed>|array<string, mixed> $identity Identity data.
207210
* @param string $tokenHash Hashed part of a cookie token.
208211
* @return bool
209212
*/

src/Authenticator/EnvironmentAuthenticator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class EnvironmentAuthenticator extends AbstractAuthenticator
3838
* - `fields` array of required fields to get from the environment
3939
* - `optionalFields` array of optional fields to get from the environment
4040
*
41-
* @var array
41+
* @var array<string, mixed>
4242
*/
4343
protected array $_defaultConfig = [
4444
'loginUrl' => null,
@@ -64,7 +64,7 @@ public function __construct(?IdentifierInterface $identifier, array $config = []
6464
* Get values from the environment variables configured by `fields`.
6565
*
6666
* @param \Psr\Http\Message\ServerRequestInterface $request The request that contains login information.
67-
* @return array|null server params defined by `fields` or null if a field is missing.
67+
* @return array<string, mixed>|null server params defined by `fields` or null if a field is missing.
6868
*/
6969
protected function _getData(ServerRequestInterface $request): ?array
7070
{
@@ -92,7 +92,7 @@ protected function _getData(ServerRequestInterface $request): ?array
9292
* Get values from the environment variables configured by `optionalFields`.
9393
*
9494
* @param \Psr\Http\Message\ServerRequestInterface $request The request that contains login information.
95-
* @return array server params defined by optionalFields.
95+
* @return array<string, mixed> server params defined by optionalFields.
9696
*/
9797
protected function _getOptionalData(ServerRequestInterface $request): array
9898
{

src/Authenticator/FormAuthenticator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class FormAuthenticator extends AbstractAuthenticator
3838
* - `loginUrl` Login URL or an array of URLs.
3939
* - `urlChecker` Url checker config.
4040
*
41-
* @var array
41+
* @var array<string, mixed>
4242
*/
4343
protected array $_defaultConfig = [
4444
'loginUrl' => null,
@@ -73,12 +73,12 @@ public function getIdentifier(): IdentifierInterface
7373
* Checks the fields to ensure they are supplied.
7474
*
7575
* @param \Psr\Http\Message\ServerRequestInterface $request The request that contains login information.
76-
* @return array|null Username and password retrieved from a request body.
76+
* @return array<string, mixed>|null Username and password retrieved from a request body.
7777
*/
7878
protected function _getData(ServerRequestInterface $request): ?array
7979
{
8080
$fields = $this->_config['fields'];
81-
/** @var array $body */
81+
/** @var array<string, mixed> $body */
8282
$body = $request->getParsedBody();
8383

8484
$data = [];

0 commit comments

Comments
 (0)