Skip to content

Commit 9da583d

Browse files
committed
Fix errors reported by phpstan.
1 parent 3a3d74f commit 9da583d

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ matrix:
1717
- php: 7.1
1818
env: PHPCS=1 DEFAULT=0
1919

20+
- php: 7.1
21+
env: PHPSTAN=1 DEFAULT=0
22+
2023
- php: 5.6
2124
env: PREFER_LOWEST=1
2225

@@ -29,13 +32,16 @@ before_script:
2932
- if [[ $DEFAULT = 1 ]]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi
3033

3134
- if [[ $PHPCS = 1 ]]; then composer require cakephp/cakephp-codesniffer:^3.0; fi
35+
- if [[ $PHPSTAN = 1 ]]; then composer require phpstan/phpstan; fi
3236

3337
script:
3438
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.1 ]]; then vendor/bin/phpunit --coverage-clover=clover.xml; fi
3539
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.1 ]]; then vendor/bin/phpunit; fi
3640

3741
- if [[ $PHPCS = 1 ]]; then vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi
3842

43+
- if [[ $PHPSTAN = 1 ]]; then vendor/bin/phpstan analyse -c phpstan.neon -l 5 src; fi
44+
3945
after_success:
4046
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.1 ]]; then bash <(curl -s https://codecov.io/bash); fi
4147

phpstan.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
parameters:
2+
ignoreErrors:
3+
- '#Call to an undefined method object::getConfig\(\)#'

src/Auth/JwtAuthenticate.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,15 @@ public function getPayload($request = null)
183183
/**
184184
* Get token from header or query string.
185185
*
186-
* @param \Cake\Network\Request|null $request Request object.
186+
* @param \Cake\Http\ServerRequest|null $request Request object.
187187
*
188188
* @return string|null Token string if found else null.
189189
*/
190190
public function getToken($request = null)
191191
{
192192
$config = $this->_config;
193193

194-
if (!$request) {
194+
if ($request === null) {
195195
return $this->_token;
196196
}
197197

@@ -201,7 +201,10 @@ public function getToken($request = null)
201201
}
202202

203203
if (!empty($this->_config['parameter'])) {
204-
$this->_token = $request->getQuery($this->_config['parameter']);
204+
$token = $request->getQuery($this->_config['parameter']);
205+
if ($token !== null) {
206+
$token = (string)$token;
207+
}
205208
}
206209

207210
return $this->_token;
@@ -252,7 +255,9 @@ public function unauthenticated(ServerRequest $request, Response $response)
252255
return;
253256
}
254257

255-
$message = $this->_error ? $this->_error->getMessage() : $this->_registry->Auth->_config['authError'];
258+
$message = $this->_error
259+
? $this->_error->getMessage()
260+
: $this->_registry->get('Auth')->getConfig('authError');
256261

257262
$exception = new $this->_config['unauthenticatedException']($message);
258263
throw $exception;

0 commit comments

Comments
 (0)