Skip to content

Commit 775c310

Browse files
oshmyheliukshiftedreality
authored andcommitted
MAGECLOUD-3997: Fix autoload error in ece-tools (#574)
1 parent 699ca21 commit 775c310

File tree

4 files changed

+70
-2
lines changed

4 files changed

+70
-2
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@
8787
"phpmd": "phpmd src xml tests/static/phpmd-ruleset.xml",
8888
"phpunit": "phpunit --configuration tests/unit",
8989
"coverage": "phpunit --configuration tests/unit --coverage-clover tests/unit/tmp/clover.xml && php tests/unit/code-coverage.php tests/unit/tmp/clover.xml",
90-
"coverage-generate": "phpunit --configuration tests/unit --coverage-html tests/unit/tmp/coverage"
90+
"coverage-generate": "phpunit --configuration tests/unit --coverage-html tests/unit/tmp/coverage",
91+
"pre-autoload-dump": [
92+
"Magento\\MagentoCloud\\Composer\\ClearAutoload::preAutoloadDump"
93+
]
9194
},
9295
"config": {
9396
"sort-packages": true

src/Composer/ClearAutoload.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MagentoCloud\Composer;
9+
10+
use Composer\Package\Package;
11+
use Composer\Package\PackageInterface;
12+
use Composer\Script\Event;
13+
14+
/**
15+
* Clears registration.php file of magento/magento-cloud-components package from composer autoload
16+
*
17+
* @codeCoverageIgnore
18+
*/
19+
class ClearAutoload
20+
{
21+
/**
22+
* @param Event $event
23+
*/
24+
public static function preAutoloadDump(Event $event)
25+
{
26+
$composer = $event->getComposer();
27+
28+
$generator = $composer->getAutoloadGenerator();
29+
$packages = $composer->getRepositoryManager()->getLocalRepository()->getCanonicalPackages();
30+
$packageMap = $generator->buildPackageMap(
31+
$composer->getInstallationManager(),
32+
$composer->getPackage(),
33+
$packages
34+
);
35+
36+
foreach ($packageMap as $item) {
37+
/** @var Package $package */
38+
$package = reset($item);
39+
40+
if (!$package instanceof PackageInterface ||
41+
$package->getName() !== 'magento/magento-cloud-components'
42+
) {
43+
continue;
44+
}
45+
46+
$autoload = $package->getAutoload();
47+
48+
if (!isset($autoload['files'])) {
49+
continue;
50+
}
51+
52+
foreach ($autoload['files'] as $index => $fileName) {
53+
if ($fileName === 'registration.php') {
54+
unset($autoload['files'][$index]);
55+
}
56+
}
57+
58+
$package->setAutoload($autoload);
59+
}
60+
}
61+
}

tests/static/phpstan.neon

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ parameters:
55
excludes_analyse:
66
- %currentWorkingDirectory%/src/Test/*
77
ignoreErrors:
8+
- message: "#.*ComponentRegistrar.*#"
9+
path: %currentWorkingDirectory%/src/StaticContent/ThemeResolver.php
810
- message: "#Strict comparison using === between bool and null will always evaluate to false.#"
9-
path: %currentWorkingDirectory%/src/Filesystem/Driver/File.php
11+
path: %currentWorkingDirectory%/src/Filesystem/Driver/File.php

tests/static/phpstan7.0.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
parameters:
22
excludes_analyse:
33
- %currentWorkingDirectory%/src/Test/*
4+
ignoreErrors:
5+
- "#.*ComponentRegistrar not found.#"

0 commit comments

Comments
 (0)