From 2eacedebfbeb9d9587ef1e59c18d170879474c61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Fri, 3 Apr 2020 20:30:25 +0200 Subject: [PATCH] phpstan fix (#43) (#44) --- src/Bridges/SecurityDI/SecurityExtension.php | 1 + src/Security/Permission.php | 13 +++++-------- tests/phpstan.neon | 2 ++ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Bridges/SecurityDI/SecurityExtension.php b/src/Bridges/SecurityDI/SecurityExtension.php index 1630fab9..d87f21a7 100644 --- a/src/Bridges/SecurityDI/SecurityExtension.php +++ b/src/Bridges/SecurityDI/SecurityExtension.php @@ -50,6 +50,7 @@ public function getConfigSchema(): Nette\Schema\Schema public function loadConfiguration() { + /** @var object{debugger: bool, users: array, roles: array, resources: array} $config */ $config = $this->config; $builder = $this->getContainerBuilder(); diff --git a/src/Security/Permission.php b/src/Security/Permission.php index a646b81e..7e0e74aa 100644 --- a/src/Security/Permission.php +++ b/src/Security/Permission.php @@ -597,20 +597,17 @@ public function isAllowed($role = self::ALL, $resource = self::ALL, $privilege = break; } } - } else { - if (($result = $this->getRuleType($resource, null, $privilege)) !== null) { // look for rule on 'allRoles' pseudo-parent - break; - - } elseif (($result = $this->getRuleType($resource, null, null)) !== null) { - break; - } + } elseif (($result = $this->getRuleType($resource, null, $privilege)) !== null) { // look for rule on 'allRoles' pseudo-parent + break; + } elseif (($result = $this->getRuleType($resource, null, null)) !== null) { + break; } $resource = $this->resources[$resource]['parent']; // try next Resource } while (true); $this->queriedRole = $this->queriedResource = null; - return $result; + return $result ?? false; } diff --git a/tests/phpstan.neon b/tests/phpstan.neon index 1b188579..5faa990b 100644 --- a/tests/phpstan.neon +++ b/tests/phpstan.neon @@ -3,3 +3,5 @@ includes: parameters: treatPhpDocTypesAsCertain: false + ignoreErrors: + - '#Variable \$this in isset\(\) always exists and is not nullable\.#'