Skip to content

Commit ad47906

Browse files
committed
phpstan fixes
1 parent 42dfffe commit ad47906

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/Authentication/AuthenticationService.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
namespace CakeDC\Auth\Authentication;
1515

1616
use Authentication\AuthenticationService as BaseService;
17+
use Authentication\Authenticator\Result;
1718
use Authentication\Authenticator\ResultInterface;
1819
use Authentication\Authenticator\StatelessInterface;
1920
use Cake\Datasource\EntityInterface;
2021
use Psr\Http\Message\ServerRequestInterface;
2122
use RuntimeException;
23+
use UnexpectedValueException;
2224

2325
class AuthenticationService extends BaseService
2426
{
@@ -71,6 +73,9 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
7173
foreach ($this->authenticators() as $authenticator) {
7274
$result = $authenticator->authenticate($request);
7375
if ($result->isValid()) {
76+
if (!method_exists($authenticator, 'getConfig')) {
77+
throw new UnexpectedValueException('Authenticators must implement method `getConfig` to check when 2fa is required');
78+
}
7479
$skipTwoFactorVerify = $authenticator->getConfig('skipTwoFactorVerify');
7580
$userData = $result->getData();
7681
if ($userData instanceof EntityInterface) {

src/Authenticator/OneTimeTokenAuthenticator.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Cake\Core\Configure;
1111
use Cake\ORM\TableRegistry;
1212
use Psr\Http\Message\ServerRequestInterface;
13+
use UnexpectedValueException;
1314

1415
class OneTimeTokenAuthenticator extends AbstractAuthenticator implements AuthenticatorInterface
1516
{
@@ -29,6 +30,13 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
2930
}
3031

3132
$usersTable = TableRegistry::getTableLocator()->get(Configure::read('Users.table'));
33+
if (!method_exists($usersTable, 'loginWithToken')) {
34+
throw new UnexpectedValueException(sprintf(
35+
'%s requires to implement `%s::loginWithToken`',
36+
self::class,
37+
get_class($usersTable)
38+
));
39+
}
3240

3341
$user = $usersTable->loginWithToken($token);
3442

src/Policy/SuperuserPolicy.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ public function __construct(array $config = [])
4848
}
4949

5050
/**
51-
* Check permission
52-
*
53-
* @param \Authorization\IdentityInterface|null $identity user identity
54-
* @param \Psr\Http\Message\ServerRequestInterface $resource server request
55-
* @return bool
51+
* @inheritDoc
5652
*/
5753
public function canAccess(?IdentityInterface $identity, ServerRequestInterface $resource): ResultInterface
5854
{

0 commit comments

Comments
 (0)