Skip to content

Commit 34b2cb5

Browse files
authored
Merge pull request #31 from gsteel/psalm-fixes
Improve internal types
2 parents fb05968 + e7c3a03 commit 34b2cb5

File tree

3 files changed

+11
-39
lines changed

3 files changed

+11
-39
lines changed

psalm-baseline.xml

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<files psalm-version="5.9.0@8b9ad1eb9e8b7d3101f949291da2b9f7767cd163">
3-
<file src="src/LaminasRbac.php">
4-
<MixedArgument>
5-
<code>$routeName</code>
6-
</MixedArgument>
7-
<MixedAssignment>
8-
<code>$routeName</code>
9-
<code>$routeResult</code>
10-
</MixedAssignment>
11-
<MixedMethodCall>
12-
<code>getMatchedRouteName</code>
13-
<code>isFailure</code>
14-
</MixedMethodCall>
15-
<UndefinedInterfaceMethod>
16-
<code>setRequest</code>
17-
</UndefinedInterfaceMethod>
18-
</file>
19-
<file src="src/LaminasRbacAssertionInterface.php">
20-
<PossiblyUnusedMethod>
21-
<code>setRequest</code>
22-
</PossiblyUnusedMethod>
23-
</file>
243
<file src="src/LaminasRbacFactory.php">
254
<MixedArgument>
265
<code>$assertion</code>
@@ -33,13 +12,8 @@
3312
<code>$role</code>
3413
<code>$role</code>
3514
</MixedArgumentTypeCoercion>
36-
<MixedArrayAccess>
37-
<code><![CDATA[$config['permissions']]]></code>
38-
<code><![CDATA[$config['roles']]]></code>
39-
</MixedArrayAccess>
4015
<MixedAssignment>
4116
<code>$assertion</code>
42-
<code>$config</code>
4317
<code>$parents</code>
4418
<code>$permission</code>
4519
<code>$permissions</code>

src/LaminasRbac.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,22 @@
44

55
namespace Mezzio\Authorization\Rbac;
66

7-
use Laminas\Permissions\Rbac\AssertionInterface;
87
use Laminas\Permissions\Rbac\Rbac;
98
use Mezzio\Authorization\AuthorizationInterface;
109
use Mezzio\Authorization\Exception;
1110
use Mezzio\Router\RouteResult;
1211
use Psr\Http\Message\ServerRequestInterface;
1312

13+
use function assert;
14+
use function is_string;
1415
use function sprintf;
1516

1617
class LaminasRbac implements AuthorizationInterface
1718
{
18-
/** @var Rbac */
19-
private $rbac;
20-
21-
/** @var null|AssertionInterface */
22-
private $assertion;
23-
24-
public function __construct(Rbac $rbac, ?LaminasRbacAssertionInterface $assertion = null)
25-
{
26-
$this->rbac = $rbac;
27-
$this->assertion = $assertion;
19+
public function __construct(
20+
private Rbac $rbac,
21+
private ?LaminasRbacAssertionInterface $assertion = null
22+
) {
2823
}
2924

3025
/**
@@ -35,7 +30,7 @@ public function __construct(Rbac $rbac, ?LaminasRbacAssertionInterface $assertio
3530
public function isGranted(string $role, ServerRequestInterface $request): bool
3631
{
3732
$routeResult = $request->getAttribute(RouteResult::class, false);
38-
if (false === $routeResult) {
33+
if (! $routeResult instanceof RouteResult) {
3934
throw new Exception\RuntimeException(sprintf(
4035
'The %s attribute is missing in the request; cannot perform authorizations',
4136
RouteResult::class
@@ -48,6 +43,7 @@ public function isGranted(string $role, ServerRequestInterface $request): bool
4843
}
4944

5045
$routeName = $routeResult->getMatchedRouteName();
46+
assert(is_string($routeName));
5147
if (null !== $this->assertion) {
5248
$this->assertion->setRequest($request);
5349
}

src/LaminasRbacFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
namespace Mezzio\Authorization\Rbac;
66

7+
use ArrayAccess;
78
use Laminas\Permissions\Rbac\Exception\ExceptionInterface as RbacExceptionInterface;
89
use Laminas\Permissions\Rbac\Rbac;
910
use Mezzio\Authorization\AuthorizationInterface;
1011
use Mezzio\Authorization\Exception;
1112
use Psr\Container\ContainerInterface;
1213
use Zend\Expressive\Authorization\Rbac\ZendRbacAssertionInterface;
1314

15+
use function is_array;
1416
use function sprintf;
1517

1618
class LaminasRbacFactory
@@ -21,7 +23,7 @@ class LaminasRbacFactory
2123
public function __invoke(ContainerInterface $container): AuthorizationInterface
2224
{
2325
$config = $container->get('config')['mezzio-authorization-rbac'] ?? null;
24-
if (null === $config) {
26+
if (! is_array($config) && ! $config instanceof ArrayAccess) {
2527
throw new Exception\InvalidConfigException(sprintf(
2628
'Cannot create %s instance; no "mezzio-authorization-rbac" config key present',
2729
LaminasRbac::class

0 commit comments

Comments
 (0)