1 | <?php |
||
12 | class Rule |
||
13 | { |
||
14 | const COMPILED = 'compiled'; |
||
15 | const DIRTY = 'dirty'; |
||
16 | |||
17 | /** |
||
18 | * User agent on which the rule apply |
||
19 | * @var string |
||
20 | */ |
||
21 | private $ua; |
||
22 | |||
23 | /** |
||
24 | * Rule status (compiled or dirty) |
||
25 | * @var string |
||
26 | */ |
||
27 | private $state; |
||
28 | |||
29 | /** |
||
30 | * Expression collection with allow / disallow segments |
||
31 | * @var array |
||
32 | */ |
||
33 | private $exp = [ |
||
34 | 'allow' => [], |
||
35 | 'disallow' => [] |
||
36 | ]; |
||
37 | |||
38 | /** |
||
39 | * Compiled regex pattern with allow / disallow segments |
||
40 | * @var array |
||
41 | */ |
||
42 | private $patterns = [ |
||
43 | 'allow' => '', |
||
44 | 'disallow' => '' |
||
45 | ]; |
||
46 | |||
47 | /** |
||
48 | * @param string $ua |
||
49 | */ |
||
50 | public function __construct($ua) |
||
54 | |||
55 | /** |
||
56 | * Retrieve rule's UserAgent |
||
57 | * @return string |
||
58 | */ |
||
59 | public function getUserAgent() |
||
63 | |||
64 | /** |
||
65 | * Add a pattern to match in the current rule by allowing |
||
66 | * @param string $pattern |
||
67 | * @return Rule |
||
68 | */ |
||
69 | public function allow($pattern) |
||
73 | |||
74 | /** |
||
75 | * Add a pattern to match in the current rule by disallowing |
||
76 | * @param string $pattern |
||
77 | * @return Rule |
||
78 | */ |
||
79 | public function disallow($pattern) |
||
83 | |||
84 | /** |
||
85 | * Add an expression in the current rule |
||
86 | * @param string $pattern Expression raw pattern |
||
|
|||
87 | * @param string $mode Expression mode (allow / disallow) |
||
88 | * @return Expression |
||
89 | */ |
||
90 | private function addExpression(Expression $exp, $mode) |
||
96 | |||
97 | /** |
||
98 | * Compile expressions to a global pattern |
||
99 | * @return boolean |
||
100 | */ |
||
101 | private function compile() |
||
118 | |||
119 | /** |
||
120 | * Check if the URL is allowed or not |
||
121 | * @param string $url |
||
122 | * @return boolean |
||
123 | */ |
||
124 | public function match($url) |
||
145 | |||
146 | /** |
||
147 | * Retrieve the last filled index in a given array |
||
148 | * @param array $data |
||
149 | * @return integer |
||
150 | */ |
||
151 | private function lastFilledIndex(array $data) |
||
155 | } |
||
156 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.