AbstractFetcher::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
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