Skip to content

Commit

Permalink
Fixed #131: app error: PHPError [2] preg_match(): Compilation failed:…
Browse files Browse the repository at this point in the history
… unknown property name after \P or \p at offset 51 at file D:\home\commithook\src\lib\PreCommit\Validator\ParentThis.php:141

 - Fixed regular expression.
  • Loading branch information
andkirby committed May 24, 2017
1 parent 6bcf8a4 commit b4ffbdf
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/lib/PreCommit/Validator/ParentThis.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,22 @@ protected function getClassAlias($class, $content)
$class = ltrim($class, '\\');
$matched = null;

preg_match('~use [\x5C]?'.$class.' as ([A-z0-9_]+);~', $content, $matches);
if (!empty($matches[1])) {
$matched = $matches[1];
$classRegular = str_replace('\\', '[\x5C]', $class);

preg_match('~(use [\x5C]?'.$classRegular.') as ([A-z0-9_]+);~', $content, $matches);
if (!empty($matches[2])) {
$matched = $matches[2];
}

if ($matched === null) {
preg_match('~use ([A-z0-9\x5C_]+[\x5C]'.$class.');~', $content, $matches);
preg_match('~use ([A-z0-9\x5C_]+[\x5C]'.$classRegular.');~', $content, $matches);
if (!empty($matches[1])) {
$matched = $matches[1];
}
}

if ($matched === null) {
preg_match('~use ([A-z0-9\x5C_]+) as '.$class.';~', $content, $matches);
preg_match('~use ([A-z0-9\x5C_]+) as '.$classRegular.';~', $content, $matches);
if (!empty($matches[1])) {
$matched = $matches[1];
}
Expand Down

0 comments on commit b4ffbdf

Please sign in to comment.