StaticMethodCallsCollector   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 44
rs 10
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A collect() 0 42 6
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: peter
5
 * Date: 20.07.18
6
 * Time: 14:21
7
 */
8
9
namespace Maslosoft\Whitelist\Tokenizer\Collectors;
10
11
12
use Maslosoft\Whitelist\Interfaces\TokenCollectorInterface;
13
use Maslosoft\Whitelist\Tokenizer\Composite\StaticMethod;
14
use const T_DOUBLE_COLON;
15
use const T_STRING;
16
17
class StaticMethodCallsCollector implements TokenCollectorInterface
18
{
19
	public function collect($tokens)
20
	{
21
		$result = [];
22
		foreach ($tokens as $index => $token)
23
		{
24
			// Skip all except double colon
25
			if($token->not(T_DOUBLE_COLON))
26
			{
27
				continue;
28
			}
29
			$prev = $token->prev();
30
			$next = $token->next();
31
32
			// Should start with class name
33
			if($prev->not(T_STRING))
34
			{
35
				continue;
36
			}
37
38
			// Should have method name
39
			if($next->not(T_STRING))
40
			{
41
				continue;
42
			}
43
44
			$finishing = $next->next();
45
46
			// Should have opening bracket after method name
47
			if($finishing->value !== '(')
48
			{
49
				continue;
50
			}
51
52
			// TODO Resolve use statements
53
			$className = $prev->value;
54
55
			$methodName = $next->value;
56
			$name = sprintf('%s::%s', $className, $methodName);
57
58
			$result[] = new StaticMethod($name,$tokens, $index);
59
		}
60
		return $result;
61
	}
62
63
}