for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Bee4\RobotsTxt;
/**
* Class Expression
* Represent a matching expression rule
*
* @copyright Bee4 2016
* @author Stephane HULARD <[email protected]>
*/
class Expression
{
* Raw definition
* @var string
private $raw;
* Rule pattern
private $pattern;
* Initialize expression
* @param string $rule
public function __construct($rule, $operator = self::ALLOW)
$operator
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.
$this->raw = $rule;
}
* Retrieve the raw rule definition
* @return string
public function getRaw()
return $this->raw;
* Transform current pattern to be used for matching
* @param string $raw
$raw
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 method finale(...).
$italy
finale(...)
/** * @param array $germany * @param array $island * @param array $italy */ function finale($germany, $island) { return "2:1"; }
The most likely cause is that the parameter was removed, but the annotation was not.
private function build()
$raw = $this->raw;
$ended = substr($raw, -1) === '$';
$raw = rtrim($raw, '*');
$raw = rtrim($raw, '$');
$parts = explode('*', $raw);
array_walk($parts, function (&$part) {
$part = preg_quote($part, '/');
});
return implode('.*', $parts).($ended?'':'.*');
* Check if current expression is contained in another
* @param Expression $exp
* @return boolean
public function contained(Expression $exp)
return $exp->contains($this);
* Check if current expression contains another
public function contains(Expression $exp)
return preg_match('/^'.(string)$this.'$/', $exp->getRaw()) === 1;
* Retrieve the regex pattern corresponding to the Expression
public function getPattern()
$this->pattern = $this->pattern ?: $this->build();
return $this->pattern;
* Transform expression to string
public function __toString()
return $this->getPattern();
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.