1 | <?php |
||
16 | class Reader implements ReaderInterface |
||
17 | { |
||
18 | /** |
||
19 | * @var \Minime\Annotations\Interfaces\ParserInterface |
||
20 | */ |
||
21 | protected $parser; |
||
22 | |||
23 | /** |
||
24 | * @var \Minime\Annotations\Interfaces\CacheInterface |
||
25 | */ |
||
26 | protected $cache; |
||
27 | |||
28 | /** |
||
29 | * @param \Minime\Annotations\Interfaces\ParserInterface $parser |
||
30 | */ |
||
31 | public function __construct(ParserInterface $parser, CacheInterface $cache = null) |
||
36 | |||
37 | /** |
||
38 | * @param \Minime\Annotations\Interfaces\CacheInterface $cache Cache handler |
||
39 | */ |
||
40 | public function setCache(CacheInterface $cache = null) |
||
44 | |||
45 | /** |
||
46 | * @return \Minime\Annotations\Interfaces\CacheInterface Cache handler |
||
47 | */ |
||
48 | public function getCache() |
||
52 | |||
53 | /** |
||
54 | * @param \Minime\Annotations\Interfaces\ParserInterface $parser |
||
55 | */ |
||
56 | public function setParser(ParserInterface $parser) |
||
60 | |||
61 | /** |
||
62 | * @return \Minime\Annotations\Interfaces\ParserInterface |
||
63 | */ |
||
64 | public function getParser() |
||
68 | |||
69 | /** |
||
70 | * Retrieve all annotations from a given function or closure |
||
71 | * |
||
72 | * @param mixed $fn Full qualified function name or closure |
||
73 | * @return \Minime\Annotations\Interfaces\AnnotationsBagInterface Annotations collection |
||
74 | * @throws \ReflectionException If function is not found |
||
75 | */ |
||
76 | public function getFunctionAnnotations($fn) |
||
80 | |||
81 | /** |
||
82 | * Retrieve all annotations from a given class |
||
83 | * |
||
84 | * @param mixed $class Full qualified class name or object |
||
85 | * @return \Minime\Annotations\Interfaces\AnnotationsBagInterface Annotations collection |
||
86 | * @throws \ReflectionException If class is not found |
||
87 | */ |
||
88 | public function getClassAnnotations($class) |
||
92 | |||
93 | /** |
||
94 | * Retrieve all annotations from a given property of a class |
||
95 | * |
||
96 | * @param mixed $class Full qualified class name or object |
||
97 | * @param string $property Property name |
||
98 | * @return \Minime\Annotations\Interfaces\AnnotationsBagInterface Annotations collection |
||
99 | * @throws \ReflectionException If property is undefined |
||
100 | */ |
||
101 | public function getPropertyAnnotations($class, $property) |
||
105 | |||
106 | /** |
||
107 | * Retrieve all annotations from a given method of a class |
||
108 | * |
||
109 | * @param mixed $class Full qualified class name or object |
||
110 | * @param string $method Method name |
||
111 | * @return \Minime\Annotations\Interfaces\AnnotationsBagInterface Annotations collection |
||
112 | * @throws \ReflectionException If method is undefined |
||
113 | */ |
||
114 | public function getMethodAnnotations($class, $method) |
||
118 | |||
119 | /** |
||
120 | * Retrieve all annotations from a given constant of a class |
||
121 | * |
||
122 | * @param string|object $class fully qualified name or instance of the class |
||
123 | * @param string $const name of the constant |
||
124 | * @return \Minime\Annotations\Interfaces\AnnotationsBagInterface Annotations collection |
||
125 | */ |
||
126 | public function getConstantAnnotations($class, $const) |
||
130 | |||
131 | /** |
||
132 | * Retrieve annotations from docblock of a given reflector |
||
133 | * |
||
134 | * @param \Reflector $Reflection Reflector object |
||
135 | * @return \Minime\Annotations\Interfaces\AnnotationsBagInterface Annotations collection |
||
136 | */ |
||
137 | public function getAnnotations(\Reflector $Reflection) |
||
153 | |||
154 | /** |
||
155 | * Shortcut to create an instance of the default annotations Reader |
||
156 | * bundled with the default Parser implementation |
||
157 | * |
||
158 | * @return \Minime\Annotations\Interfaces\ReaderInterface |
||
159 | */ |
||
160 | public static function createFromDefaults() |
||
164 | } |
||
165 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: