ReflectionAnnotatedMethod::getDeclaringClass()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * This software package is licensed under AGPL, Commercial license.
5
 *
6
 * @package maslosoft/addendum
7
 * @licence AGPL, Commercial
8
 * @copyright Copyright (c) Piotr Masełkowski <[email protected]> (Meta container, further improvements, bugfixes)
9
 * @copyright Copyright (c) Maslosoft (Meta container, further improvements, bugfixes)
10
 * @copyright Copyright (c) Jan Suchal (Original version, builder, parser)
11
 * @link https://maslosoft.com/addendum/ - maslosoft addendum
12
 * @link https://code.google.com/p/addendum/ - original addendum project
13
 */
14
15
namespace Maslosoft\Addendum\Reflection;
16
17
use Maslosoft\Addendum\Addendum;
18
use Maslosoft\Addendum\Builder\Builder;
19
use Maslosoft\Addendum\Collections\AnnotationsCollection;
20
use Maslosoft\Addendum\Interfaces\AnnotatedReflectorInterface;
21
use Maslosoft\Addendum\Utilities\ConflictChecker;
22
use ReflectionMethod;
23
24
class ReflectionAnnotatedMethod extends ReflectionMethod implements AnnotatedReflectorInterface
25
{
26
27
	/**
28
	 * Collection of annotations
29
	 * @var AnnotationsCollection
30
	 */
31
	private $annotations;
32
33
	/**
34
	 * Addendum instance
35
	 * @var Addendum
36
	 */
37
	private $addendum;
38
39 11
	public function __construct($class, $name, Addendum $addendum = null)
40
	{
41 11
		parent::__construct($class, $name);
42 11
		$this->annotations = (new Builder($addendum))->build($this);
43 11
		$this->addendum = $addendum;
44 11
		ConflictChecker::check($this, $this->annotations);
45 11
	}
46
47 10
	public function hasAnnotation($class)
48
	{
49 10
		return $this->annotations->hasAnnotation($class);
50
	}
51
52 3
	public function getAnnotation($annotation)
53
	{
54 3
		return $this->annotations->getAnnotation($annotation);
55
	}
56
57
	public function getAnnotations()
58
	{
59
		return $this->annotations->getAnnotations();
60
	}
61
62 6
	public function getAllAnnotations($restriction = false)
63
	{
64 6
		return $this->annotations->getAllAnnotations($restriction);
0 ignored issues
show
Documentation introduced by
$restriction is of type boolean, but the function expects a false|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
65
	}
66
67 11
	public function getDeclaringClass()
68
	{
69 11
		$class = parent::getDeclaringClass();
70 11
		return new ReflectionAnnotatedClass($class->name, $this->addendum);
71
	}
72
73
}
74