Completed
Push — master ( a774bb...596fca )
by Alexander
67:49 queued 42:47
created

IntroductionAspectExtension::getKind()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types = 1);
4
/*
5
 * Go! AOP framework
6
 *
7
 * @copyright Copyright 2012, Lisachenko Alexander <[email protected]>
8
 *
9
 * This source file is subject to the license that is bundled
10
 * with this source code in the file LICENSE.
11
 */
12
13
namespace Go\Core;
14
15
use Go\Aop\Advisor;
16
use Go\Aop\Aspect;
17
use Go\Aop\Framework\DeclareErrorInterceptor;
18
use Go\Aop\Framework\TraitIntroductionInfo;
19
use Go\Aop\Pointcut;
20
use Go\Aop\Support\DeclareParentsAdvisor;
21
use Go\Aop\Support\DefaultPointcutAdvisor;
22
use Go\Lang\Annotation;
23
use Go\Lang\Annotation\DeclareParents;
24
use ReflectionClass;
25
use UnexpectedValueException;
26
27
/**
28
 * Introduction aspect extension
29
 */
30
class IntroductionAspectExtension extends AbstractAspectLoaderExtension
31
{
32 1
    /**
33
     * Loads definition from specific point of aspect into the container
34 1
     *
35
     * @param Aspect          $aspect           Instance of aspect
36
     * @param ReflectionClass $reflectionAspect Reflection of point
37
     *
38
     * @return array<string,Pointcut>|array<string,Advisor>
39
     *
40 2
     * @throws UnexpectedValueException
41
     */
42 2
    public function load(Aspect $aspect, ReflectionClass $reflectionAspect): array
43
    {
44
        $loadedItems = [];
45
        foreach ($reflectionAspect->getProperties() as $aspectProperty) {
46
            $propertyId  = $reflectionAspect->getName() . '->'. $aspectProperty->getName();
47
            $annotations = $this->reader->getPropertyAnnotations($aspectProperty);
48
49
            foreach ($annotations as $annotation) {
50
                if ($annotation instanceof DeclareParents) {
0 ignored issues
show
Bug introduced by
The class Go\Lang\Annotation\DeclareParents does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
51
                    $pointcut = $this->parsePointcut($aspect, $aspectProperty, $annotation->value);
52
53
                    $implement        = $annotation->defaultImpl;
54
                    $interface        = $annotation->interface;
55
                    $introductionInfo = new TraitIntroductionInfo($implement, $interface);
56
                    $advisor          = new DeclareParentsAdvisor($pointcut, $introductionInfo);
57
58
                    $loadedItems[$propertyId] = $advisor;
59
                } elseif ($annotation instanceof Annotation\DeclareError) {
0 ignored issues
show
Bug introduced by
The class Go\Lang\Annotation\DeclareError does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
60
                    $pointcut = $this->parsePointcut($aspect, $reflectionAspect, $annotation->value);
61
62
                    $aspectProperty->setAccessible(true);
63
                    $errorMessage     = $aspectProperty->getValue($aspect);
64
                    $errorLevel       = $annotation->level;
65
                    $introductionInfo = new DeclareErrorInterceptor($errorMessage, $errorLevel, $annotation->value);
66
                    $loadedItems[$propertyId] = new DefaultPointcutAdvisor($pointcut, $introductionInfo);
67
                    break;
68
69
                } else {
70
                    throw new UnexpectedValueException('Unsupported annotation class: ' . get_class($annotation));
71
                }
72
            }
73
        }
74
75
        return $loadedItems;
76
    }
77
}
78