MethodAnnotationReader::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 10
rs 9.4285
cc 1
eloc 6
nc 1
nop 2
1
<?php
2
/**
3
 * ownCloud - News
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Alessandro Cosentino <[email protected]>
9
 * @author Bernhard Posselt <[email protected]>
10
 * @copyright Alessandro Cosentino 2012
11
 * @copyright Bernhard Posselt 2012, 2014
12
 */
13
14
namespace OCA\Chat\Utility;
15
16
17
/**
18
 * Reads and parses annotations from doc comments
19
 */
20
class MethodAnnotationReader {
21
22
	private $annotations;
23
24
	/**
25
	 * @param object $object an object or classname
26
	 * @param string $method the method which we want to inspect for annotations
27
	 */
28
	public function __construct($object, $method){
29
		$this->annotations = array();
30
31
		$reflection = new \ReflectionMethod($object, $method);
32
		$docs = $reflection->getDocComment();
33
34
		// extract everythin prefixed by @ and first letter uppercase
35
		preg_match_all('/@([A-Z]\w+)/', $docs, $matches);
36
		$this->annotations = $matches[1];
37
	}
38
39
40
	/**
41
	 * Check if a method contains an annotation
42
	 * @param string $name the name of the annotation
43
	 * @return bool true if the annotation is found
44
	 */
45
	public function hasAnnotation($name){
46
		return in_array($name, $this->annotations);
47
	}
48
49
50
}