Skip to content

Commit

Permalink
Fix type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Jun 30, 2023
1 parent 2ddc2c1 commit 0646af9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"require": {
"php": "^7.2 || ^8.0",
"symfony/finder": "^4.4 || ^5.3 || ^6 || ^7",
"composer/pcre": "^2 || ^3"
"composer/pcre": "^2.1 || ^3.1"
},
"require-dev": {
"symfony/phpunit-bridge": "^5",
Expand Down
6 changes: 3 additions & 3 deletions src/ClassMapGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function scanPaths($path, string $excluded = null, string $autoloadType =
}

$classes = PhpFileParser::findClasses($filePath);
if ('classmap' !== $autoloadType && isset($namespace, $basePath)) {
if ('classmap' !== $autoloadType && isset($namespace)) {
$classes = $this->filterByNamespace($classes, $filePath, $namespace, $autoloadType, $basePath);

// if no valid class was found in the file then we do not mark it as scanned as it might still be matched by another rule later
Expand Down Expand Up @@ -291,7 +291,7 @@ private static function normalizePath(string $path)
}

// extract a prefix being a protocol://, protocol:, protocol://drive: or simply drive:
if (Preg::isMatch('{^( [0-9a-z]{2,}+: (?: // (?: [a-z]: )? )? | [a-z]: )}ix', $path, $match)) {
if (Preg::isMatchStrictGroups('{^( [0-9a-z]{2,}+: (?: // (?: [a-z]: )? )? | [a-z]: )}ix', $path, $match)) {
$prefix = $match[1];
$path = substr($path, \strlen($prefix));
}
Expand All @@ -313,7 +313,7 @@ private static function normalizePath(string $path)
}

// ensure c: is normalized to C:
$prefix = Preg::replaceCallback('{(^|://)[a-z]:$}i', function (array $m) { return strtoupper($m[0]); }, $prefix);
$prefix = Preg::replaceCallbackStrictGroups('{(?:^|://)[a-z]:$}i', function (array $m) { return strtoupper($m[0]); }, $prefix);

return $prefix.$absolute.implode('/', $parts);
}
Expand Down
7 changes: 4 additions & 3 deletions src/PhpFileParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public static function findClasses(string $path): array
}

// return early if there is no chance of matching anything in this file
Preg::matchAll('{\b(?:class|interface|trait'.$extraTypes.')\s}i', $contents, $matches);
if (!$matches) {
Preg::matchAllStrictGroups('{\b(?:class|interface|trait'.$extraTypes.')\s}i', $contents, $matches);
if (0 === \count($matches)) {
return array();
}

Expand All @@ -76,14 +76,15 @@ public static function findClasses(string $path): array
$namespace = str_replace(array(' ', "\t", "\r", "\n"), '', (string) $matches['nsname'][$i]) . '\\';
} else {
$name = $matches['name'][$i];
assert(is_string($name));
// skip anon classes extending/implementing
if ($name === 'extends' || $name === 'implements') {
continue;
}
if ($name[0] === ':') {
// This is an XHP class, https://github.com/facebook/xhp
$name = 'xhp'.substr(str_replace(array('-', ':'), array('_', '__'), $name), 1);
} elseif (strtolower($matches['type'][$i]) === 'enum') {
} elseif (strtolower((string) $matches['type'][$i]) === 'enum') {
// something like:
// enum Foo: int { HERP = '123'; }
// The regex above captures the colon, which isn't part of
Expand Down

0 comments on commit 0646af9

Please sign in to comment.