Completed
Push — 2.x ( ee1bb7...bfb9a9 )
by Akihito
05:07
created

ReflectionClass::setObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * This file is part of the Ray.Aop package
4
 *
5
 * @license http://opensource.org/licenses/bsd-license.php BSD
6
 */
7
namespace Ray\Aop;
8
9
class ReflectionClass extends \ReflectionClass implements Reader
10
{
11
    /**
12
     * @var WeavedInterface
13
     */
14
    private $object;
15
16
    /**
17
     * Set dependencies
18
     *
19
     * @param WeavedInterface $object
20
     */
21 2
    public function setObject(WeavedInterface $object)
22
    {
23 2
        $this->object = $object;
24 2
    }
25
26
    /**
27
     * {@inheritDoc}
28
     */
29 2
    public function getAnnotations()
30
    {
31 2
        return unserialize($this->object->classAnnotations);
0 ignored issues
show
Bug introduced by
Accessing classAnnotations on the interface Ray\Aop\WeavedInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
32
    }
33
34
    /**
35
     * {@inheritDoc}
36
     */
37 2
    public function getAnnotation($annotationName)
38
    {
39 2
        $annotations = $this->getAnnotations();
40 2
        if (isset($annotations[$annotationName])) {
41 1
            return $annotations[$annotationName];
42
        }
43
44 1
        return null;
45
    }
46
}
47