AnnotationConfiguration   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 67
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A ignoredAnnotations() 0 11 4
A registerAnnotations() 0 16 3
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
8
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
9
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
10
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
11
 * THE SOFTWARE.
12
 *
13
 * This software consists of voluntary contributions made by many individuals
14
 * and is licensed under the MIT license.
15
 *
16
 * Copyright (c) 2015-2020 Yuuki Takezawa
17
 *
18
 */
19
20
namespace Ytake\LaravelAspect;
21
22
use Ytake\LaravelAspect\Annotation;
23
use Doctrine\Common\Annotations\AnnotationReader;
24
use Doctrine\Common\Annotations\AnnotationRegistry;
25
26
use function count;
27
use function array_merge;
28
29
/**
30
 * Class AnnotationConfiguration
31
 */
32
class AnnotationConfiguration
33
{
34
    /** @var array */
35
    protected $configuration = [];
36
37
    /** @var array */
38
    protected $customAnnotations = [];
39
40
    /** @var string[] */
41
    private $annotations = [
42
        Annotation\Cacheable::class,
43
        Annotation\CacheEvict::class,
44
        Annotation\CachePut::class,
45
        Annotation\EagerQueue::class,
46
        Annotation\LazyQueue::class,
47
        Annotation\LogExceptions::class,
48
        Annotation\Loggable::class,
49
        Annotation\MessageDriven::class,
50
        Annotation\PostConstruct::class,
51
        Annotation\QueryLog::class,
52
        Annotation\RetryOnFailure::class,
53
        Annotation\Transactional::class,
54
    ];
55
56
    /**
57
     * @param array $configuration
58
     * @param array $customAnnotations
59
     */
60
    public function __construct(array $configuration, array $customAnnotations = [])
61
    {
62
        $this->configuration = $configuration;
63
        $this->customAnnotations = $customAnnotations;
64
        $this->registerAnnotations();
65
    }
66
67
    /**
68
     * Add a new annotation to the globally ignored annotation names with regard to exception handling.
69
     */
70
    public function ignoredAnnotations(): void
71
    {
72
        if (isset($this->configuration['ignores'])) {
73
            $ignores = $this->configuration['ignores'];
74
            if (count($ignores)) {
75
                foreach ($ignores as $ignore) {
76
                    AnnotationReader::addGlobalIgnoredName($ignore);
77
                }
78
            }
79
        }
80
    }
81
82
    protected function registerAnnotations(): void
83
    {
84
        $this->annotations = array_merge(
0 ignored issues
show
Documentation Bug introduced by
It seems like \array_merge($this->anno...his->customAnnotations) of type array is incompatible with the declared type array<integer,string> of property $annotations.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
85
            $this->annotations,
86
            $this->customAnnotations
87
        );
88
        if (isset($this->configuration['custom'])) {
89
            $this->annotations = array_merge(
0 ignored issues
show
Documentation Bug introduced by
It seems like \array_merge($this->anno...onfiguration['custom']) of type array is incompatible with the declared type array<integer,string> of property $annotations.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
90
                $this->annotations,
91
                $this->configuration['custom']
92
            );
93
        }
94
        foreach ($this->annotations as $annotation) {
95
            AnnotationRegistry::loadAnnotationClass($annotation);
96
        }
97
    }
98
}
99