Skip to content

Commit 095eaf5

Browse files
committed
Add .yireo-extension-checker.json file for config
1 parent 6d863d2 commit 095eaf5

File tree

3 files changed

+63
-6
lines changed

3 files changed

+63
-6
lines changed

Scan/ScanComposerRequirements.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,28 @@
1111
use Yireo\ExtensionChecker\Config\RuntimeConfig;
1212
use Yireo\ExtensionChecker\Message\MessageBucket;
1313
use Yireo\ExtensionChecker\Message\MessageGroupLabels;
14+
use Yireo\ExtensionChecker\Util\CheckerConfiguration;
1415

1516
class ScanComposerRequirements
1617
{
1718
private ComposerFileProvider $composerFileProvider;
1819
private MessageBucket $messageBucket;
1920
private ComposerProvider $composerProvider;
2021
private RuntimeConfig $runtimeConfig;
22+
private CheckerConfiguration $checkerConfiguration;
2123

2224
public function __construct(
2325
ComposerFileProvider $composerFileProvider,
2426
MessageBucket $messageBucket,
2527
ComposerProvider $composerProvider,
26-
RuntimeConfig $runtimeConfig
28+
RuntimeConfig $runtimeConfig,
29+
CheckerConfiguration $checkerConfiguration
2730
) {
2831
$this->composerFileProvider = $composerFileProvider;
2932
$this->messageBucket = $messageBucket;
3033
$this->composerProvider = $composerProvider;
3134
$this->runtimeConfig = $runtimeConfig;
35+
$this->checkerConfiguration = $checkerConfiguration;
3236
}
3337

3438
/**
@@ -48,7 +52,7 @@ public function scan(string $moduleName, array $components)
4852
}
4953

5054
foreach ($requirements as $requirement => $requirementVersion) {
51-
$this->scanComposerRequirementWithComponents($requirement, $requirementVersion, $components);
55+
$this->scanComposerRequirementWithComponents($moduleName, $requirement, $requirementVersion, $components);
5256
}
5357
}
5458

@@ -93,11 +97,12 @@ private function scanComponentWithComposerRequirements(
9397
* @return void
9498
*/
9599
private function scanComposerRequirementWithComponents(
100+
string $moduleName,
96101
string $requirement,
97102
string $requirementVersion,
98103
array $components
99104
) {
100-
$this->checkIfRequirementIsNeeded($requirement, $components);
105+
$this->checkIfRequirementIsNeeded($moduleName, $requirement, $components);
101106
$this->checkIfComposerRequirementUsesWildCard($requirement, $requirementVersion);
102107
$this->checkPhpVersion($requirement, $requirementVersion);
103108
}
@@ -107,12 +112,16 @@ private function scanComposerRequirementWithComponents(
107112
* @param array $components
108113
* @return void
109114
*/
110-
private function checkIfRequirementIsNeeded(string $requirement, array $components)
115+
private function checkIfRequirementIsNeeded(string $moduleName, string $requirement, array $components)
111116
{
112117
if ($this->runtimeConfig->isHideNeedless()) {
113118
return;
114119
}
115120

121+
if ($this->checkerConfiguration->isIgnored($moduleName, $requirement)) {
122+
return;
123+
}
124+
116125
if ($this->isComposerDependencyNeeded($requirement, $components)) {
117126
return;
118127
}

Scan/ScanModuleXmlDependencies.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
use Yireo\ExtensionChecker\Config\RuntimeConfig;
88
use Yireo\ExtensionChecker\Message\MessageBucket;
99
use Yireo\ExtensionChecker\Message\MessageGroupLabels;
10+
use Yireo\ExtensionChecker\Util\CheckerConfiguration;
1011

1112
class ScanModuleXmlDependencies
1213
{
1314
private ModuleXmlComponentDetector $moduleXmlComponentDetector;
1415
private MessageBucket $messageBucket;
1516
private RuntimeConfig $runtimeConfig;
17+
private CheckerConfiguration $checkerConfiguration;
1618

1719
/**
1820
* @param ModuleXmlComponentDetector $moduleXmlComponentDetector
@@ -21,11 +23,13 @@ class ScanModuleXmlDependencies
2123
public function __construct(
2224
ModuleXmlComponentDetector $moduleXmlComponentDetector,
2325
MessageBucket $messageBucket,
24-
RuntimeConfig $runtimeConfig
26+
RuntimeConfig $runtimeConfig,
27+
CheckerConfiguration $checkerConfiguration
2528
) {
2629
$this->moduleXmlComponentDetector = $moduleXmlComponentDetector;
2730
$this->messageBucket = $messageBucket;
2831
$this->runtimeConfig = $runtimeConfig;
32+
$this->checkerConfiguration = $checkerConfiguration;
2933
}
3034

3135
/**
@@ -50,7 +54,7 @@ public function scan(string $moduleName, array $components)
5054
}
5155

5256
if (!$isComponentFoundInModuleXml) {
53-
$message = 'Module "' . $component->getComponentName() . '" has no module.xml entry';
57+
$message = 'Module "'.$component->getComponentName().'" has no module.xml entry';
5458
$this->messageBucket->add($message, MessageGroupLabels::GROUP_MISSING_MODULEXML_DEP, '', $moduleName);
5559
}
5660
}
@@ -62,6 +66,11 @@ public function scan(string $moduleName, array $components)
6266

6367
$isModuleXmlComponentFoundInDetectedComponents = false;
6468
foreach ($components as $component) {
69+
if ($this->checkerConfiguration->isIgnored($moduleName, $moduleXmlComponent->getComponentName())) {
70+
$isModuleXmlComponentFoundInDetectedComponents = true;
71+
break;
72+
}
73+
6574
if ($component->getComponentName() === $moduleXmlComponent->getComponentName()) {
6675
$isModuleXmlComponentFoundInDetectedComponents = true;
6776
break;

Util/CheckerConfiguration.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Yireo\ExtensionChecker\Util;
4+
5+
use Magento\Framework\Component\ComponentRegistrar;
6+
7+
class CheckerConfiguration
8+
{
9+
public function __construct(
10+
private ComponentRegistrar $componentRegistrar,
11+
) {
12+
}
13+
14+
public function getIgnoredComponents(string $moduleName): array
15+
{
16+
$configuration = $this->getConfiguration($moduleName);
17+
if (array_key_exists('ignore', $configuration)) {
18+
return $configuration['ignore'];
19+
}
20+
21+
return [];
22+
}
23+
24+
public function isIgnored(string $moduleName, string $componentName): bool
25+
{
26+
return in_array($componentName, $this->getIgnoredComponents($moduleName));
27+
}
28+
29+
private function getConfiguration(string $moduleName): array
30+
{
31+
$modulePath = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName);
32+
$configurationFile = $modulePath.'/.yireo-extension-checker.json';
33+
if (false === file_exists($configurationFile)) {
34+
return [];
35+
}
36+
37+
return json_decode(file_get_contents($configurationFile), true);
38+
}
39+
}

0 commit comments

Comments
 (0)