AbstractFetcher::filterContractAnnotation()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 7
cts 7
cp 1
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
3
/**
4
 * PHP Deal framework
5
 *
6
 * @copyright Copyright 2019, Lisachenko Alexander <[email protected]>
7
 *
8
 * This source file is subject to the license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
declare(strict_types=1);
13
14
namespace PhpDeal\Contract\Fetcher\Parent;
15
16
use Doctrine\Common\Annotations\Reader;
17
18
abstract class AbstractFetcher
19
{
20
    /**
21
     * @var string[]
22
     */
23
    protected $expectedAnnotationTypes;
24
25
    /**
26
     * @var Reader
27
     */
28
    protected $annotationReader;
29
30
    /**
31
     * @param string[] $expectedAnnotationTypes
32
     * @param Reader   $reader
33
     */
34
    public function __construct(array $expectedAnnotationTypes, Reader $reader)
35
    {
36
        $this->expectedAnnotationTypes = $expectedAnnotationTypes;
37
        $this->annotationReader        = $reader;
38
    }
39
40
    /**
41
     * Performs filtering of annotations by the requested class name
42
     *
43
     * @param array $annotations
44
     * @return array
45
     */
46 29
    protected function filterContractAnnotation(array $annotations): array
47
    {
48 29
        $contractAnnotations = [];
49
50 29
        foreach ($annotations as $annotation) {
51 20
            $annotationClass = \get_class($annotation);
52
53 20
            if (\in_array($annotationClass, $this->expectedAnnotationTypes, true)) {
54 20
                $contractAnnotations[] = $annotation;
55
            }
56
        }
57
58 29
        return $contractAnnotations;
59
    }
60
}
61