-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathphparkitect.php
More file actions
62 lines (52 loc) · 2.71 KB
/
Copy pathphparkitect.php
File metadata and controls
62 lines (52 loc) · 2.71 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
<?php
declare(strict_types=1);
/**
* php-qa-ci PHPArkitect — DEFAULT ENTRY CONFIG (on by default).
*
* configPath resolves this file whenever a project has NOT supplied its own
* qaConfig/phparkitect.php, so every consuming project gets the generic-safe
* default baseline (phparkitect-rules-default.php) applied to its detected
* source directory — no per-project setup required. This is the arkitect
* equivalent of the rules-default PHPStan baseline.
*
* A project takes over by adding qaConfig/phparkitect.php (use the template at
* templates/qaConfig-phparkitect.php), where it can extend the defaults, opt
* into the optional/symfony tiers, and add bespoke rules. To turn arkitect off
* for a project entirely, set `export useArkitect=0` in qaConfig/qaConfig.inc.bash.
*
* The wrapper exports PHPQACI_ARKITECT_SRC_DIR (the pipeline's detected srcDir),
* PHPQACI_ARKITECT_RULES_DEFAULT (the resolved default ruleset path) and
* PHPQACI_ARKITECT_EXCLUDE_PATHS (newline-delimited extra generated paths a
* project declares via `arkitectExcludePaths` in qaConfig/qaConfig.inc.bash).
*/
use Arkitect\ClassSet;
use Arkitect\CLI\Config;
return static function (Config $config): void {
$srcDir = getenv('PHPQACI_ARKITECT_SRC_DIR') ?: (getcwd() . '/src');
// Nothing to analyse (e.g. a project without a conventional src/) — pass cleanly.
if (!\is_dir($srcDir)) {
return;
}
$defaultRulesFile = getenv('PHPQACI_ARKITECT_RULES_DEFAULT')
?: __DIR__ . '/phparkitect-rules-default.php';
$defaultRules = \is_file($defaultRulesFile) ? require $defaultRulesFile : [];
if ([] === $defaultRules) {
fwrite(STDERR, "PHPArkitect: default ruleset resolved empty (looked at {$defaultRulesFile}) — NO rules applied.\n");
return;
}
// Generated code is regenerated and cannot be renamed — never check it.
// 'Generated' is the built-in convention. A project declares ADDITIONAL
// generated paths (e.g. a jane-php OpenAPI client at src/Quote/API) with
// arkitectExcludePaths+=("Quote/API")
// in qaConfig/qaConfig.inc.bash; the pipeline exports them newline-delimited
// as PHPQACI_ARKITECT_EXCLUDE_PATHS. Each entry is matched by arkitect
// (Arkitect\Glob::toRegex) against the path RELATIVE to src/.
$classSet = ClassSet::fromDir($srcDir)->excludePath('Generated');
$extraExcludePaths = getenv('PHPQACI_ARKITECT_EXCLUDE_PATHS');
if (false !== $extraExcludePaths && '' !== \trim($extraExcludePaths)) {
foreach (\array_filter(\array_map('trim', \explode("\n", $extraExcludePaths))) as $excludePath) {
$classSet = $classSet->excludePath($excludePath);
}
}
$config->add($classSet, ...$defaultRules);
};