Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
16 / 16 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ComposerDependencyAnalyserConfig | |
100.00% |
16 / 16 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| configure | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| applyPackagedRepositoryIgnores | |
100.00% |
10 / 10 |
|
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\Config; |
| 21 | |
| 22 | use FastForward\DevTools\Path\DevToolsPathResolver; |
| 23 | use ShipMonk\ComposerDependencyAnalyser\Config\Configuration; |
| 24 | use ShipMonk\ComposerDependencyAnalyser\Config\ErrorType; |
| 25 | |
| 26 | /** |
| 27 | * Provides the default Composer Dependency Analyser configuration. |
| 28 | * |
| 29 | * Consumers can use this as a starting point and extend it: |
| 30 | * |
| 31 | * return \FastForward\DevTools\Config\ComposerDependencyAnalyserConfig::configure( |
| 32 | * static function (\ShipMonk\ComposerDependencyAnalyser\Config\Configuration $configuration): void { |
| 33 | * $configuration->ignoreErrorsOnPackage( |
| 34 | * 'vendor/package', |
| 35 | * [\ShipMonk\ComposerDependencyAnalyser\Config\ErrorType::UNUSED_DEPENDENCY] |
| 36 | * ); |
| 37 | * } |
| 38 | * ); |
| 39 | * |
| 40 | * @see https://github.com/shipmonk-rnd/composer-dependency-analyser |
| 41 | */ |
| 42 | class ComposerDependencyAnalyserConfig |
| 43 | { |
| 44 | /** |
| 45 | * Dependencies that are only required by the packaged DevTools distribution itself. |
| 46 | * |
| 47 | * These packages MUST only be ignored when the analyser runs against the |
| 48 | * DevTools repository, because consumer repositories do not inherit them as |
| 49 | * direct requirements automatically. |
| 50 | * |
| 51 | * @var array<int, string> |
| 52 | */ |
| 53 | public const array DEFAULT_PACKAGED_UNUSED_DEPENDENCIES = [ |
| 54 | 'ergebnis/composer-normalize', |
| 55 | 'fakerphp/faker', |
| 56 | 'fast-forward/phpdoc-bootstrap-template', |
| 57 | 'php-parallel-lint/php-parallel-lint', |
| 58 | 'phpdocumentor/shim', |
| 59 | 'phpmetrics/phpmetrics', |
| 60 | 'phpro/grumphp-shim', |
| 61 | 'pyrech/composer-changelogs', |
| 62 | 'rector/jack', |
| 63 | 'saggre/phpdocumentor-markdown', |
| 64 | 'symfony/var-dumper', |
| 65 | ]; |
| 66 | |
| 67 | /** |
| 68 | * Production dependencies intentionally kept in require for the packaged toolchain. |
| 69 | * |
| 70 | * These dependencies are only exercised in test and development paths inside |
| 71 | * this repository, but they MUST remain available to the packaged DevTools |
| 72 | * runtime for consumer projects that choose to use those capabilities. |
| 73 | * |
| 74 | * @var array<int, string> |
| 75 | */ |
| 76 | public const array DEFAULT_PACKAGED_PROD_ONLY_IN_DEV_DEPENDENCIES = [ |
| 77 | 'phpspec/prophecy', |
| 78 | 'phpspec/prophecy-phpunit', |
| 79 | 'symfony/var-exporter', |
| 80 | ]; |
| 81 | |
| 82 | /** |
| 83 | * Creates the default Composer Dependency Analyser configuration. |
| 84 | * |
| 85 | * @param callable|null $customize optional callback to customize the configuration |
| 86 | * |
| 87 | * @return Configuration the configured analyser configuration |
| 88 | */ |
| 89 | public static function configure(?callable $customize = null): Configuration |
| 90 | { |
| 91 | $configuration = new Configuration(); |
| 92 | |
| 93 | if (DevToolsPathResolver::isRepositoryCheckout()) { |
| 94 | self::applyPackagedRepositoryIgnores($configuration); |
| 95 | } |
| 96 | |
| 97 | if (null !== $customize) { |
| 98 | $customize($configuration); |
| 99 | } |
| 100 | |
| 101 | return $configuration; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Applies the ignores required only by the packaged DevTools repository. |
| 106 | * |
| 107 | * @param Configuration $configuration the analyser configuration to customize |
| 108 | * |
| 109 | * @return void |
| 110 | */ |
| 111 | public static function applyPackagedRepositoryIgnores(Configuration $configuration): Configuration |
| 112 | { |
| 113 | $configuration->ignoreErrorsOnExtension('ext-pcntl', [ErrorType::SHADOW_DEPENDENCY]); |
| 114 | $configuration->ignoreErrorsOnPackages( |
| 115 | self::DEFAULT_PACKAGED_UNUSED_DEPENDENCIES, |
| 116 | [ErrorType::UNUSED_DEPENDENCY] |
| 117 | ); |
| 118 | $configuration->ignoreErrorsOnPackages( |
| 119 | self::DEFAULT_PACKAGED_PROD_ONLY_IN_DEV_DEPENDENCIES, |
| 120 | [ErrorType::PROD_DEPENDENCY_ONLY_IN_DEV], |
| 121 | ); |
| 122 | |
| 123 | return $configuration; |
| 124 | } |
| 125 | } |