Completed
Push — master ( 4c2930...4201b5 )
by Peter
05:41
created

StaticConstantMatcher::process()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5.0909

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 11
cts 13
cp 0.8462
rs 8.7624
c 0
b 0
f 0
cc 5
eloc 13
nc 5
nop 1
crap 5.0909
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 http://maslosoft.com/addendum/ - maslosoft addendum
12
 * @link https://code.google.com/p/addendum/ - original addendum project
13
 */
14
15
namespace Maslosoft\Addendum\Matcher;
16
17
use Maslosoft\Addendum\Exceptions\ClassNotFoundException;
18
use Maslosoft\Addendum\Interfaces\Matcher\MatcherInterface;
19
use Maslosoft\Addendum\Matcher\Helpers\Processor;
20
use Maslosoft\Addendum\Utilities\ClassChecker;
21
22
class StaticConstantMatcher extends RegexMatcher implements MatcherInterface
23
{
24
25 39
	public function __construct()
26
	{
27 39
		parent::__construct('([\w\\\]+::\w+)');
28 39
	}
29
30 3
	protected function process($matches)
31
	{
32 3
		$value = $matches[1];
33 3
		$parts = explode('::', $value);
34 3
		$className = $parts[0];
35 3
		$constName = $parts[1];
36 3
		$className = Processor::process($this, $className);
37 3
		$value = sprintf('%s::%s', $className, $constName);
38 3
		if ($className !== 'self' && $className !== 'static')
39
		{
40 3
			if (!ClassChecker::exists($className))
41
			{
42
				throw new ClassNotFoundException("Class $className not found while parsing annotations");
43
			}
44
		}
45 3
		if (!defined($value))
46
		{
47
			return false;
48
		}
49 3
		return constant($value);
50
	}
51
52
}
53