ReflectionHelper::getReflectionClass()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4.25

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 6
cts 8
cp 0.75
rs 9.7333
c 0
b 0
f 0
cc 4
nc 4
nop 2
crap 4.25
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\Utilities;
16
17
use Exception;
18
use Maslosoft\Addendum\Interfaces\Matcher\MatcherInterface;
19
use Maslosoft\Addendum\Reflection\ReflectionAnnotatedClass;
20
use Maslosoft\Addendum\Reflection\ReflectionAnnotatedMethod;
21
use Maslosoft\Addendum\Reflection\ReflectionAnnotatedProperty;
22
23
/**
24
 * ReflectionHelper
25
 *
26
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
27
 */
28
class ReflectionHelper
29
{
30
31
	/**
32
	 * Get reflection class.
33
	 * @param ReflectionAnnotatedClass|ReflectionAnnotatedProperty|ReflectionAnnotatedMethod $reflection Reflection
34
	 * @param MatcherInterface                                                               $matcher
35
	 * @return ReflectionAnnotatedClass
36
	 * @throws Exception
37
	 */
38 19
	public static function getReflectionClass($reflection, MatcherInterface $matcher)
39
	{
40 19
		if (null === $reflection)
41
		{
42
			throw new Exception(sprintf('No reflection class for matcher `%s`', get_class($matcher)));
43
		}
44 19
		if ($reflection instanceof ReflectionAnnotatedMethod)
45
		{
46
			return $reflection->getDeclaringClass();
47
		}
48 19
		if ($reflection instanceof ReflectionAnnotatedProperty)
49
		{
50 6
			return $reflection->getDeclaringClass();
51
		}
52 13
		return $reflection;
53
	}
54
55
}
56