AbstractFetcher   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 63.64%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 43
ccs 7
cts 11
cp 0.6364
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A filterContractAnnotation() 0 14 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