MethodAnnotationReader   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 31
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hasAnnotation() 0 3 1
A __construct() 0 10 1
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
}