Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| WorkingProjectPathResolver | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| getProjectPath | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
| getToolingExcludedDirectories | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * Fast Forward Development Tools for PHP projects. |
| 7 | * |
| 8 | * This file is part of fast-forward/dev-tools project. |
| 9 | * |
| 10 | * @author Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
| 11 | * @license https://opensource.org/licenses/MIT MIT License |
| 12 | * |
| 13 | * @see https://github.com/php-fast-forward/ |
| 14 | * @see https://github.com/php-fast-forward/dev-tools |
| 15 | * @see https://github.com/php-fast-forward/dev-tools/issues |
| 16 | * @see https://php-fast-forward.github.io/dev-tools/ |
| 17 | * @see https://datatracker.ietf.org/doc/html/rfc2119 |
| 18 | */ |
| 19 | |
| 20 | namespace FastForward\DevTools\Path; |
| 21 | |
| 22 | use Symfony\Component\Filesystem\Path; |
| 23 | |
| 24 | use function Safe\getcwd; |
| 25 | |
| 26 | /** |
| 27 | * Provides canonical repository-root paths that are not part of the managed workspace. |
| 28 | */ |
| 29 | class WorkingProjectPathResolver |
| 30 | { |
| 31 | /** |
| 32 | * Returns the current working project directory or a path under it. |
| 33 | * |
| 34 | * @param string $path the optional relative segment to append under the project directory |
| 35 | */ |
| 36 | public static function getProjectPath(string $path = ''): string |
| 37 | { |
| 38 | if ('' !== $path && Path::isAbsolute($path)) { |
| 39 | return $path; |
| 40 | } |
| 41 | |
| 42 | return Path::join(getcwd(), $path); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Returns the project directories that static-analysis and coding-style tooling SHOULD skip. |
| 47 | * |
| 48 | * @param string $baseDir the optional repository base directory used to materialize absolute paths |
| 49 | * |
| 50 | * @return list<string> |
| 51 | */ |
| 52 | public static function getToolingExcludedDirectories(string $baseDir = ''): array |
| 53 | { |
| 54 | return [ |
| 55 | ManagedWorkspace::getOutputDirectory(baseDir: $baseDir), |
| 56 | Path::join($baseDir, 'resources'), |
| 57 | Path::join($baseDir, 'vendor'), |
| 58 | ]; |
| 59 | } |
| 60 | } |