Passed
Push — master ( 9f6f8b...b68386 )
by Pauli
03:11 queued 16s
created

MethodAnnotationReader::hasAnnotation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * ownCloud
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\Music\AppFramework\Utility;
15
16
/**
17
 * Reads and parses annotations from doc comments
18
 */
19
class MethodAnnotationReader {
20
	private $annotations;
21
22
	/**
23
	 * @param object|string $object an object or classname
24
	 * @param string $method the method which we want to inspect for annotations
25
	 */
26
	public function __construct($object, $method) {
27
		$this->annotations = [];
28
29
		$reflection = new \ReflectionMethod($object, $method);
30
		$docs = $reflection->getDocComment();
31
32
		// extract everything prefixed by @ and first letter uppercase
33
		\preg_match_all('/@([A-Z]\w+)/', $docs, $matches);
34
		$this->annotations = $matches[1];
35
	}
36
37
	/**
38
	 * Check if a method contains an annotation
39
	 * @param string $name the name of the annotation
40
	 * @return bool true if the annotation is found
41
	 */
42
	public function hasAnnotation($name) {
43
		return \in_array($name, $this->annotations);
44
	}
45
}
46