Completed
Push — master ( 8a93d3...c82149 )
by Peter
04:18
created

ReflectionHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 27
ccs 6
cts 8
cp 0.75
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getReflectionClass() 0 16 4
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\Reflection\ReflectionAnnotatedClass;
19
use Maslosoft\Addendum\Reflection\ReflectionAnnotatedMethod;
20
use Maslosoft\Addendum\Reflection\ReflectionAnnotatedProperty;
21
22
/**
23
 * ReflectionHelper
24
 *
25
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
26
 */
27
class ReflectionHelper
28
{
29
30
	/**
31
	 * Get reflection class.
32
	 * @param ReflectionAnnotatedClass|ReflectionAnnotatedProperty|ReflectionAnnotatedMethod $reflection Reflection
33
	 * @return ReflectionAnnotatedClass
34
	 * @throws Exception
35
	 */
36 15
	public static function getReflectionClass($reflection)
37
	{
38 15
		if (null === $reflection)
39
		{
40
			throw new Exception(sprintf('No reflection class for matcher `%s`', get_class($this)));
0 ignored issues
show
Bug introduced by
Usage of "$this" in static methods will cause runtime errors
Loading history...
41
		}
42 15
		if ($reflection instanceof ReflectionAnnotatedMethod)
43
		{
44
			return $reflection->getDeclaringClass();
45
		}
46 15
		if ($reflection instanceof ReflectionAnnotatedProperty)
47
		{
48 6
			return $reflection->getDeclaringClass();
49
		}
50 9
		return $reflection;
51
	}
52
53
}
54