AuthorizationProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 35
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 12 1
A registerRoleHierarchyResolver() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Security\Authorization;
6
7
use Pimple\Container;
8
use Pimple\ServiceProviderInterface;
9
10
final class AuthorizationProvider implements ServiceProviderInterface
11
{
12
    /**
13
     * @param Container $container
14
     */
15 1
    public function register(Container $container)
16
    {
17 1
        $this->registerRoleHierarchyResolver($container);
0 ignored issues
show
Unused Code introduced by
The call to the method Chubbyphp\Security\Autho...RoleHierarchyResolver() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
18
19 1
        $container['security.authorization.authorizations'] = function () use ($container) {
20 1
            return [];
21
        };
22
23 1
        $container['security.authorization'] = function () use ($container) {
24 1
            return new AuthorizationStack($container['security.authorization.authorizations']);
25
        };
26 1
    }
27
28
    /**
29
     * @param Container $container
30
     */
31
    private function registerRoleHierarchyResolver(Container $container)
32
    {
33 1
        $container['security.authorization.rolehierarchy'] = function () use ($container) {
34 1
            return [];
35
        };
36
37 1
        $container['security.authorization.rolehierarchyresolver'] = function () use ($container) {
38 1
            return new RoleHierarchyResolver(
39 1
                $container['security.authorization.rolehierarchy'],
40 1
                $container['logger'] ?? null
41
            );
42
        };
43 1
    }
44
}
45