PatternPackageFilter::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * Copyright MediaCT. All rights reserved.
4
 * https://www.mediact.nl
5
 */
6
7
namespace Mediact\DependencyGuard\Violation\Filter;
8
9
use Mediact\DependencyGuard\Violation\ViolationInterface;
10
11
class PatternPackageFilter implements ViolationFilterInterface
12
{
13
    /** @var string */
14
    private $pattern;
15
16
    /**
17
     * Constructor.
18
     *
19
     * @param string $pattern
20
     */
21 5
    public function __construct(string $pattern)
22
    {
23 5
        $this->pattern = $pattern;
24 5
    }
25
26
    /**
27
     * Filter violations.
28
     *
29
     * @param ViolationInterface $violation
30
     *
31
     * @return bool
32
     */
33 5
    public function __invoke(ViolationInterface $violation): bool
34
    {
35 5
        return !fnmatch(
36 5
            $this->pattern,
37 5
            $violation->getPackage()->getName(),
38 5
            FNM_PATHNAME | FNM_NOESCAPE
39
        );
40
    }
41
}
42