-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComposerDependencyAnalyserConfig.php
More file actions
158 lines (141 loc) · 5.47 KB
/
ComposerDependencyAnalyserConfig.php
File metadata and controls
158 lines (141 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
declare(strict_types=1);
/**
* Fast Forward Development Tools for PHP projects.
*
* This file is part of fast-forward/dev-tools project.
*
* @author Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
* @license https://opensource.org/licenses/MIT MIT License
*
* @see https://github.com/php-fast-forward/
* @see https://github.com/php-fast-forward/dev-tools
* @see https://github.com/php-fast-forward/dev-tools/issues
* @see https://php-fast-forward.github.io/dev-tools/
* @see https://datatracker.ietf.org/doc/html/rfc2119
*/
namespace FastForward\DevTools\Config;
use FastForward\DevTools\Path\DevToolsPathResolver;
use ShipMonk\ComposerDependencyAnalyser\Config\Configuration;
use ShipMonk\ComposerDependencyAnalyser\Config\ErrorType;
/**
* Provides the default Composer Dependency Analyser configuration.
*
* Consumers can use this as a starting point and extend it:
*
* return \FastForward\DevTools\Config\ComposerDependencyAnalyserConfig::configure(
* static function (\ShipMonk\ComposerDependencyAnalyser\Config\Configuration $configuration): void {
* $configuration->ignoreErrorsOnPackage(
* 'vendor/package',
* [\ShipMonk\ComposerDependencyAnalyser\Config\ErrorType::UNUSED_DEPENDENCY]
* );
* }
* );
*
* @see https://github.com/shipmonk-rnd/composer-dependency-analyser
*/
final class ComposerDependencyAnalyserConfig
{
public const string ENV_SHOW_SHADOW_DEPENDENCIES = 'FAST_FORWARD_DEV_TOOLS_SHOW_SHADOW_DEPENDENCIES';
/**
* Dependencies that are only required by the packaged DevTools distribution itself.
*
* These packages MUST only be ignored when the analyser runs against the
* DevTools repository, because consumer repositories do not inherit them as
* direct requirements automatically.
*
* @var array<int, string>
*/
public const array DEFAULT_PACKAGED_UNUSED_DEPENDENCIES = [
'ergebnis/composer-normalize',
'fakerphp/faker',
'fast-forward/phpdoc-bootstrap-template',
'php-parallel-lint/php-parallel-lint',
'phpdocumentor/shim',
'phpmetrics/phpmetrics',
'phpro/grumphp-shim',
'pyrech/composer-changelogs',
'rector/jack',
'saggre/phpdocumentor-markdown',
'symfony/var-dumper',
];
/**
* Production dependencies intentionally kept in require for the packaged toolchain.
*
* These dependencies are only exercised in test and development paths inside
* this repository, but they MUST remain available to the packaged DevTools
* runtime for consumer projects that choose to use those capabilities.
*
* @var array<int, string>
*/
public const array DEFAULT_PACKAGED_PROD_ONLY_IN_DEV_DEPENDENCIES = [
'phpspec/prophecy',
'phpspec/prophecy-phpunit',
'symfony/var-exporter',
];
/**
* Creates the default Composer Dependency Analyser configuration.
*
* @param callable|null $customize optional callback to customize the configuration
*
* @return Configuration the configured analyser configuration
*/
public static function configure(?callable $customize = null): Configuration
{
$configuration = new Configuration();
if (! self::shouldShowShadowDependencies()) {
self::applyIgnoresShadowDependencies($configuration);
}
if (DevToolsPathResolver::isRepositoryCheckout()) {
self::applyPackagedRepositoryIgnores($configuration);
}
if (null !== $customize) {
$customize($configuration);
}
return $configuration;
}
/**
* The default configuration ignores shadow dependencies because Fast
* Forward packages MAY intentionally require dependency groups. For example,
* ecosystem or meta packages can require related PSR or framework packages
* so consumers do not need to install every package one by one.
*
* @param Configuration $configuration the analyser configuration to customize
*
* @return Configuration the modified configuration with shadow dependencies ignored
*/
public static function applyIgnoresShadowDependencies(Configuration $configuration): Configuration
{
$configuration->ignoreErrors([ErrorType::SHADOW_DEPENDENCY]);
return $configuration;
}
/**
* Determines whether shadow dependency reports SHOULD remain visible.
*
* @return bool
*/
public static function shouldShowShadowDependencies(): bool
{
return '1' === getenv(self::ENV_SHOW_SHADOW_DEPENDENCIES);
}
/**
* Applies the ignores required only by the packaged DevTools repository.
*
* @param Configuration $configuration the analyser configuration to customize
*
* @return Configuration the modified configuration with packaged repository ignores applied
*/
public static function applyPackagedRepositoryIgnores(Configuration $configuration): Configuration
{
$configuration->ignoreErrorsOnExtension('ext-pcntl', [ErrorType::SHADOW_DEPENDENCY]);
$configuration->ignoreErrorsOnPackages(
self::DEFAULT_PACKAGED_UNUSED_DEPENDENCIES,
[ErrorType::UNUSED_DEPENDENCY]
);
$configuration->ignoreErrorsOnPackages(
self::DEFAULT_PACKAGED_PROD_ONLY_IN_DEV_DEPENDENCIES,
[ErrorType::PROD_DEPENDENCY_ONLY_IN_DEV],
);
return $configuration;
}
}