Skip to content

Commit b7e2384

Browse files
committed
Fix errors reported by static analysis
1 parent e3eae81 commit b7e2384

File tree

5 files changed

+33
-11
lines changed

5 files changed

+33
-11
lines changed

.editorconfig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ insert_final_newline = true
1111
trim_trailing_whitespace = true
1212

1313
[*.yml]
14-
indent_style = space
1514
indent_size = 2
15+
16+
[*.neon]
17+
indent_style = tab

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
phpunit.xml export-ignore
66
.travis.yml export-ignore
77
tests export-ignore
8+
.phpstan.neon export-ignore
9+
.psalm.xml export-ignore

phpstan.neon

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
parameters:
2-
level: 6
3-
checkMissingIterableValueType: false
4-
ignoreErrors:
5-
-
6-
message: "#^Ternary operator condition is always true\\.$#"
7-
count: 1
8-
path: src/Auth/JwtAuthenticate.php
2+
level: 6
3+
checkMissingIterableValueType: false
4+
paths:
5+
- src/

psalm.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="2"
4+
resolveFromConfigFile="true"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xmlns="https://getpsalm.org/schema/config"
7+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
>
9+
<projectFiles>
10+
<directory name="src" />
11+
<ignoreFiles>
12+
<directory name="vendor" />
13+
</ignoreFiles>
14+
</projectFiles>
15+
<issueHandlers>
16+
<PropertyNotSetInConstructor errorLevel="suppress"/>
17+
</issueHandlers>
18+
</psalm>

src/Auth/JwtAuthenticate.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class JwtAuthenticate extends BaseAuthenticate
5252
/**
5353
* Exception.
5454
*
55-
* @var \Exception
55+
* @var \Throwable|null
5656
*/
5757
protected $_error;
5858

@@ -115,7 +115,7 @@ public function __construct(ComponentRegistry $registry, array $config)
115115
*
116116
* @param \Cake\Http\ServerRequest $request The request object.
117117
* @param \Cake\Http\Response $response Response object.
118-
* @return bool|array User record array or false on failure.
118+
* @return false|array User record array or false on failure.
119119
*/
120120
public function authenticate(ServerRequest $request, Response $response)
121121
{
@@ -126,7 +126,7 @@ public function authenticate(ServerRequest $request, Response $response)
126126
* Get user record based on info available in JWT.
127127
*
128128
* @param \Cake\Http\ServerRequest $request Request object.
129-
* @return bool|array User record array or false on failure.
129+
* @return false|array User record array or false on failure.
130130
*/
131131
public function getUser(ServerRequest $request)
132132
{
@@ -198,6 +198,7 @@ public function getToken(?ServerRequest $request = null)
198198
if (!empty($this->_config['cookie'])) {
199199
$token = $request->getCookie($this->_config['cookie']);
200200
if ($token !== null) {
201+
/** @psalm-suppress PossiblyInvalidCast */
201202
$token = (string)$token;
202203
}
203204

@@ -207,6 +208,7 @@ public function getToken(?ServerRequest $request = null)
207208
if (!empty($this->_config['parameter'])) {
208209
$token = $request->getQuery($this->_config['parameter']);
209210
if ($token !== null) {
211+
/** @psalm-suppress PossiblyInvalidCast */
210212
$token = (string)$token;
211213
}
212214

@@ -264,6 +266,7 @@ public function unauthenticated(ServerRequest $request, Response $response)
264266
? $this->_error->getMessage()
265267
: $this->_registry->get('Auth')->getConfig('authError');
266268

269+
/** @var \Throwable $exception */
267270
$exception = new $this->_config['unauthenticatedException']($message);
268271
throw $exception;
269272
}

0 commit comments

Comments
 (0)