| 1 | <?php |
||
| 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 |
||
|
|
|||
| 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) |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Check if current expression contains another |
||
| 76 | * @param Expression $exp |
||
| 77 | * @return boolean |
||
| 78 | */ |
||
| 79 | public function contains(Expression $exp) |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Retrieve the regex pattern corresponding to the Expression |
||
| 86 | * @return string |
||
| 87 | */ |
||
| 88 | 2 | public function getPattern() |
|
| 93 | |||
| 94 | /** |
||
| 95 | * Transform expression to string |
||
| 96 | * @return string |
||
| 97 | */ |
||
| 98 | 2 | public function __toString() |
|
| 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
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.