protected static function prefixLength(array $lines)
{
// find only lines with interesting things
- $lines = array_filter($lines, function ($line) {
- return substr($line, strspn($line, "* \t\n\r\0\x0B"));
+ $lines = \array_filter($lines, function ($line) {
+ return \substr($line, \strspn($line, "* \t\n\r\0\x0B"));
});
// if we sort the lines, we only have to compare two items
- sort($lines);
+ \sort($lines);
- $first = reset($lines);
- $last = end($lines);
+ $first = \reset($lines);
+ $last = \end($lines);
// find the longest common substring
- $count = min(strlen($first), strlen($last));
+ $count = \min(\strlen($first), \strlen($last));
for ($i = 0; $i < $count; $i++) {
if ($first[$i] !== $last[$i]) {
return $i;
protected function parseComment($comment)
{
// Strip the opening and closing tags of the docblock
- $comment = substr($comment, 3, -2);
+ $comment = \substr($comment, 3, -2);
// Split into arrays of lines
- $comment = array_filter(preg_split('/\r?\n\r?/', $comment));
+ $comment = \array_filter(\preg_split('/\r?\n\r?/', $comment));
// Trim asterisks and whitespace from the beginning and whitespace from the end of lines
$prefixLength = self::prefixLength($comment);
- $comment = array_map(function ($line) use ($prefixLength) {
- return rtrim(substr($line, $prefixLength));
+ $comment = \array_map(function ($line) use ($prefixLength) {
+ return \rtrim(\substr($line, $prefixLength));
}, $comment);
// Group the lines together by @tags
// Parse the blocks
foreach ($blocks as $block => $body) {
- $body = trim(implode("\n", $body));
+ $body = \trim(\implode("\n", $body));
if ($block === 0 && !self::isTagged($body)) {
// This is the description block
$this->desc = $body;
} else {
// This block is tagged
- $tag = substr(self::strTag($body), 1);
- $body = ltrim(substr($body, strlen($tag) + 2));
+ $tag = \substr(self::strTag($body), 1);
+ $body = \ltrim(\substr($body, \strlen($tag) + 2));
if (isset(self::$vectors[$tag])) {
// The tagged block is a vector
- $count = count(self::$vectors[$tag]);
+ $count = \count(self::$vectors[$tag]);
if ($body) {
- $parts = preg_split('/\s+/', $body, $count);
+ $parts = \preg_split('/\s+/', $body, $count);
} else {
$parts = [];
}
// Default the trailing values
- $parts = array_pad($parts, $count, null);
+ $parts = \array_pad($parts, $count, null);
// Store as a mapped array
- $this->tags[$tag][] = array_combine(self::$vectors[$tag], $parts);
+ $this->tags[$tag][] = \array_combine(self::$vectors[$tag], $parts);
} else {
// The tagged block is only text
$this->tags[$tag][] = $body;
*/
public function hasTag($tag)
{
- return is_array($this->tags) && array_key_exists($tag, $this->tags);
+ return \is_array($this->tags) && \array_key_exists($tag, $this->tags);
}
/**
*/
public static function isTagged($str)
{
- return isset($str[1]) && $str[0] === '@' && ctype_alpha($str[1]);
+ return isset($str[1]) && $str[0] === '@' && !\preg_match('/[^A-Za-z]/', $str[1]);
}
/**
*/
public static function strTag($str)
{
- if (preg_match('/^@[a-z0-9_]+/', $str, $matches)) {
+ if (\preg_match('/^@[a-z0-9_]+/', $str, $matches)) {
return $matches[0];
}
}