Skip to content

Commit

Permalink
Replace match with switch to support older PHP versions
Browse files Browse the repository at this point in the history
  • Loading branch information
pelmered committed Jun 11, 2024
1 parent 3f3901e commit 05c4066
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/VaporIgnore.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static function get(): LazyCollection
$baseDir = dirname($path);

return static::getLines($path)->map(function ($line) use ($baseDir) {
return static::parseLine($baseDir, trim($line));
return static::parseLine($baseDir,$line);
})->flatten()->filter();
}

Expand All @@ -37,22 +37,24 @@ protected static function getLines($path): LazyCollection
});
}

protected static function parseLine($baseDir, $line): false|array|null
protected static function parseLine($baseDir, $line): array
{
$line = trim($line);

return Arr::map(match ($line) {
'', '#' => [], // ignore empty lines and comments
default => glob("$baseDir/$line")
}, static function ($line) use ($baseDir) {
return Str::of($line)
->after($baseDir)
->trim('/')
->pipe(function ($line) {
return '/^'.preg_quote($line, '/').'/';
})
->toString();
});
switch (trim($line)) {
// ignore empty lines and comments
case '':
case '#':
return [];
default:
return Arr::map(glob($baseDir.'/'.trim($line, '/')), function ($path) use ($baseDir) {
return Str::of($path)
->after($baseDir)
->trim('/')
->pipe(function ($line) {
return '/^'.preg_quote($line, '/').'/';
})
->toString();
});
}

}
}

0 comments on commit 05c4066

Please sign in to comment.