Completed
Pull Request — master (#335)
by Luc
04:43
created

ClassNameCommandFilter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A matches() 0 10 3
1
<?php
2
3
namespace CultuurNet\UDB3\Security;
4
5
use CultuurNet\UDB3\Offer\Commands\AuthorizableCommandInterface;
6
use ValueObjects\StringLiteral\StringLiteral;
7
8
class ClassNameCommandFilter implements CommandFilterInterface
9
{
10
    private $classNames;
11
12
    /**
13
     * ClassNameCommandFilter constructor.
14
     * @param StringLiteral[] $classNames
15
     */
16
    public function __construct(StringLiteral ...$classNames)
17
    {
18
        $this->classNames = $classNames;
19
    }
20
21
    /**
22
     * @inheritdoc
23
     */
24
    public function matches(AuthorizableCommandInterface $command)
25
    {
26
        foreach ($this->classNames as $className) {
27
            if (get_class($command) === $className->toNative()) {
0 ignored issues
show
Bug introduced by
The method toNative cannot be called on $className (of type array<integer,object<Val...Literal\StringLiteral>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
28
                return true;
29
            }
30
        }
31
32
        return false;
33
    }
34
}