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

ClassNameCommandFilter::matches()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
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
}