These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Bee4\RobotsTxt; |
||
4 | |||
5 | /** |
||
6 | * Class Expression |
||
7 | * Represent a matching expression rule |
||
8 | * |
||
9 | * @copyright Bee4 2016 |
||
10 | * @author Stephane HULARD <[email protected]> |
||
11 | */ |
||
12 | class Expression |
||
13 | { |
||
14 | /** |
||
15 | * Raw definition |
||
16 | * @var string |
||
17 | */ |
||
18 | private $raw; |
||
19 | |||
20 | /** |
||
21 | * Rule pattern |
||
22 | * @var string |
||
23 | */ |
||
24 | private $pattern; |
||
25 | |||
26 | /** |
||
27 | * Initialize expression |
||
28 | * @param string $rule |
||
29 | */ |
||
30 | 3 | public function __construct($rule) |
|
31 | { |
||
32 | 3 | $this->raw = $rule; |
|
33 | 3 | } |
|
34 | |||
35 | /** |
||
36 | * Retrieve the raw rule definition |
||
37 | * @return string |
||
38 | */ |
||
39 | 2 | public function getRaw() |
|
40 | { |
||
41 | 2 | return $this->raw; |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * Transform current pattern to be used for matching |
||
46 | * @param string $raw |
||
0 ignored issues
–
show
|
|||
47 | * @return string |
||
48 | */ |
||
49 | 2 | private function build() |
|
50 | { |
||
51 | 2 | $raw = $this->raw; |
|
52 | |||
53 | 2 | $ended = substr($raw, -1) === '$'; |
|
54 | 2 | $raw = rtrim($raw, '*'); |
|
55 | 2 | $raw = rtrim($raw, '$'); |
|
56 | |||
57 | 2 | $parts = explode('*', $raw); |
|
58 | 2 | array_walk($parts, function (&$part) { |
|
59 | 2 | $part = preg_quote($part, '/'); |
|
60 | 2 | }); |
|
61 | 2 | return implode('.*', $parts).($ended?'':'.*'); |
|
62 | } |
||
63 | |||
64 | /** |
||
65 | * Check if current expression is contained in another |
||
66 | * @param Expression $exp |
||
67 | * @return boolean |
||
68 | */ |
||
69 | public function contained(Expression $exp) |
||
70 | { |
||
71 | return $exp->contains($this); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Check if current expression contains another |
||
76 | * @param Expression $exp |
||
77 | * @return boolean |
||
78 | */ |
||
79 | public function contains(Expression $exp) |
||
80 | { |
||
81 | return preg_match('/^'.(string)$this.'$/', $exp->getRaw()) === 1; |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Retrieve the regex pattern corresponding to the Expression |
||
86 | * @return string |
||
87 | */ |
||
88 | 2 | public function getPattern() |
|
89 | { |
||
90 | 2 | $this->pattern = $this->pattern ?: $this->build(); |
|
91 | 2 | return $this->pattern; |
|
92 | } |
||
93 | |||
94 | /** |
||
95 | * Transform expression to string |
||
96 | * @return string |
||
97 | */ |
||
98 | 2 | public function __toString() |
|
99 | { |
||
100 | 2 | return $this->getPattern(); |
|
101 | } |
||
102 | } |
||
103 |
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.