Skip to content

Commit

Permalink
🚨 Apply PHPStan fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelien committed Nov 25, 2020
1 parent 8ca9b2b commit 01fd946
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 17 deletions.
24 changes: 22 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,25 @@ parameters:
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
ignoreErrors:
- '#Variable property access on Laminas\\Db\\RowGateway\\RowGateway.#'
- '#Variable method call on \$this\(App\\Permissions\).#'
- message: '#Variable property access on Laminas\\Db\\RowGateway\\RowGateway\.#'
path: src/App/Handler/API/DefaultHandler.php
- message: '#Variable method call on \$this\(App\\Permissions\)\.#'
path: src/App/Permissions.php
- message: '#Offset ''[a-zA-Z0-9_]+'' does not exist on array\|ArrayObject\|null\.#'
paths:
- src/App/DataModel.php
- src/App/Handler/Admin/RolesHandler.php
- message: '#Cannot access offset ''[a-zA-Z0-9_]+'' on array\|object\|null\.#'
paths:
- src/App/Handler/LoginHandler.php
- src/App/Handler/PasswordHandler.php
- src/App/Handler/RecoveryCodeHandler.php
- message: '#Cannot access offset ''[a-zA-Z0-9]+'' on array\|false\.#'
paths:
- src/App/Handler/RecoveryCodeHandler.php
- message: '#Cannot access property \$[a-zA-Z0-9]+ on array\|ArrayObject\|null\.#'
path: src/App/Permissions.php
- message: '#Cannot access offset string on array\|object\|null\.#'
path: src/App/Handler/LoginHandler.php
- message: '#Variable property access on mixed\.#'
path: src/App/UserRepository.php
4 changes: 2 additions & 2 deletions src/App/BruteForceProtection.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function increment(): int
{
$time = new DateTime();

if (is_null($this->creation)) {
if (!isset($this->creation)) {
$this->creation = $time;
}

Expand All @@ -117,7 +117,7 @@ public function lockUntil(DateTime $datetime): void
{
$time = new DateTime();

if (is_null($this->creation)) {
if (!isset($this->creation)) {
$this->creation = $time;
}

Expand Down
2 changes: 1 addition & 1 deletion src/App/Handler/LoginHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private function handleLoginAttempt(

$query = $request->getParsedBody();

$usernameField = $this->config['authentication']['username'];
/** @var string */ $usernameField = $this->config['authentication']['username'];

// User session takes precedence over user/pass POST in
// the auth adapter so we remove the session prior
Expand Down
22 changes: 11 additions & 11 deletions src/App/Middleware/AccessMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,27 +88,27 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$this->tableUserRole
);

$this->renderer->addDefaultParam($this->renderer::TEMPLATE_ALL, 'acl', $acl);

if (null !== $this->auth) {
$user = $this->auth->authenticate($request);
if (null !== $user) {
$request = $request->withAttribute(AclInterface::class, $acl);
$request = $request->withAttribute(UserInterface::class, $user);
} else {
// return $this->auth->unauthorizedResponse($request);

return new RedirectResponse($basePath !== '/' ? $basePath : ''.$this->redirect);
return new RedirectResponse($basePath !== '/' ? $basePath : '' . $this->redirect);
}
}

$resources = DataModel::getResources($adapter, $this->tableResource);
$homepages = array_values(array_filter($resources, function (Resource $resource) use ($acl, $user): bool {
return preg_match('/^home-.+$/', $resource->name) === 1
&& $acl->isAllowed($user->getIdentity(), $resource->name);
}));
$resources = DataModel::getResources($adapter, $this->tableResource);
$homepages = array_values(array_filter($resources, function (Resource $resource) use ($acl, $user): bool {
return preg_match('/^home-.+$/', $resource->name) === 1
&& $acl->isAllowed($user->getIdentity(), $resource->name);
}));

$this->renderer->addDefaultParam($this->renderer::TEMPLATE_ALL, 'acl', $acl);
$this->renderer->addDefaultParam($this->renderer::TEMPLATE_ALL, 'user', $user);
$this->renderer->addDefaultParam($this->renderer::TEMPLATE_ALL, 'homepages', $homepages);
$this->renderer->addDefaultParam($this->renderer::TEMPLATE_ALL, 'user', $user);
$this->renderer->addDefaultParam($this->renderer::TEMPLATE_ALL, 'homepages', $homepages);
}

return $handler->handle($request);
}
Expand Down
2 changes: 1 addition & 1 deletion src/App/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function search(string $column, string $value): ?UserInterface
$this->config['table'],
$column
);
$stmt = $this->pdo->prepare($sql);
/** @var \PDOStatement|false */ $stmt = $this->pdo->prepare($sql);

if (false === $stmt) {
throw new Exception(
Expand Down

0 comments on commit 01fd946

Please sign in to comment.