Skip to content

Commit 2315a83

Browse files
FRW-7289 Fixed Development module dependency BC-break. (#10806)
FRW-7289 Fixed Development module dependency BC-break.
1 parent 9b9de5b commit 2315a83

7 files changed

+170
-8
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Development module",
55
"license": "proprietary",
66
"require": {
7-
"nette/di": "^2.4.7 || ^3.0.0",
7+
"nette/di": "^2.4.7 || ^3.2.0",
88
"php": ">=8.1",
99
"phpmd/phpmd": "^2.0.0",
1010
"spryker/config": "^3.0.0",

phpstan.neon

+2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ parameters:
99
- '#Call to an undefined method ReflectionType::getName\(\)#'
1010
- '#Call to function method_exists\(\) with Symfony\\Component\\Console\\Helper\\ProgressBar and ''maxSecondsBetweenRe…'' will always evaluate to false.#'
1111
- '#Call to an undefined method ReflectionType::isBuiltin\(\)#'
12+
- '#Call to an undefined method Nette\\DI\\Config\\Adapter::dump\(\)#'
1213
- '#Comparison operation ">" between int<2, max> and 1 is always true.#'
14+
- '#Instanceof between string and Nette\\DI\\Config\\Adapter will always evaluate to false.#'
1315
- '#Parameter \#1 \$[a-zA-Z]* of class ReflectionClass constructor expects class-string<T of object>\|T of object, string given.#'
1416
- '#Parameter \#1 \$callback of function spl_autoload_unregister expects callable\(\): mixed, array given.#'
1517
- '#Parameter \#1 \$callback of function spl_autoload_unregister expects callable\(\): mixed, non-empty-array given.#'

src/Spryker/Zed/Development/Business/DevelopmentBusinessFactory.php

+26-1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@
189189
use Spryker\Zed\Development\Business\Phpstan\Config\PhpstanConfigFileFinderInterface;
190190
use Spryker\Zed\Development\Business\Phpstan\Config\PhpstanConfigFileManager;
191191
use Spryker\Zed\Development\Business\Phpstan\Config\PhpstanConfigFileManagerInterface;
192+
use Spryker\Zed\Development\Business\Phpstan\Config\PhpstanConfigFileSaver;
193+
use Spryker\Zed\Development\Business\Phpstan\Config\PhpstanConfigFileSaverInterface;
192194
use Spryker\Zed\Development\Business\Phpstan\PhpstanRunner;
193195
use Spryker\Zed\Development\Business\Propel\PropelAbstractClassValidator;
194196
use Spryker\Zed\Development\Business\Propel\PropelAbstractClassValidatorInterface;
@@ -2114,7 +2116,12 @@ protected function createPhpstanConfigFileFinder(): PhpstanConfigFileFinderInter
21142116
*/
21152117
protected function createPhpstanConfigFileManager(): PhpstanConfigFileManagerInterface
21162118
{
2117-
return new PhpstanConfigFileManager($this->getFilesystem(), $this->getConfig(), $this->getConfigLoader());
2119+
return new PhpstanConfigFileManager(
2120+
$this->getFilesystem(),
2121+
$this->getConfig(),
2122+
$this->getConfigLoader(),
2123+
$this->createPhpstanConfigFileSaver(),
2124+
);
21182125
}
21192126

21202127
/**
@@ -2176,4 +2183,22 @@ protected function createTargetDirectoryResolver(): TargetDirectoryResolver
21762183
$this->getConfig(),
21772184
);
21782185
}
2186+
2187+
/**
2188+
* @return \Spryker\Zed\Development\Business\Phpstan\Config\PhpstanConfigFileSaverInterface
2189+
*/
2190+
public function createPhpstanConfigFileSaver(): PhpstanConfigFileSaverInterface
2191+
{
2192+
return new PhpstanConfigFileSaver(
2193+
$this->getPhpstanFileAdapters(),
2194+
);
2195+
}
2196+
2197+
/**
2198+
* @return array<string, string>
2199+
*/
2200+
public function getPhpstanFileAdapters(): array
2201+
{
2202+
return $this->getProvidedDependency(DevelopmentDependencyProvider::PHPSTAN_ADAPTERS);
2203+
}
21792204
}

src/Spryker/Zed/Development/Business/Phpstan/Config/PhpstanConfigFileManager.php

+20-6
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,39 @@ class PhpstanConfigFileManager implements PhpstanConfigFileManagerInterface
1616
/**
1717
* @var \Symfony\Component\Filesystem\Filesystem
1818
*/
19-
protected $filesystem;
19+
protected Filesystem $filesystem;
2020

2121
/**
2222
* @var \Spryker\Zed\Development\DevelopmentConfig
2323
*/
24-
protected $config;
24+
protected DevelopmentConfig $config;
2525

2626
/**
2727
* @var \Nette\DI\Config\Loader
2828
*/
29-
protected $configLoader;
29+
protected Loader $configLoader;
30+
31+
/**
32+
* @var \Spryker\Zed\Development\Business\Phpstan\Config\PhpstanConfigFileSaverInterface
33+
*/
34+
protected PhpstanConfigFileSaverInterface $phpstanConfigFileSaver;
3035

3136
/**
3237
* @param \Symfony\Component\Filesystem\Filesystem $filesystem
3338
* @param \Spryker\Zed\Development\DevelopmentConfig $config
3439
* @param \Nette\DI\Config\Loader $configLoader
40+
* @param \Spryker\Zed\Development\Business\Phpstan\Config\PhpstanConfigFileSaverInterface $phpstanConfigFileSaver
3541
*/
36-
public function __construct(Filesystem $filesystem, DevelopmentConfig $config, Loader $configLoader)
37-
{
42+
public function __construct(
43+
Filesystem $filesystem,
44+
DevelopmentConfig $config,
45+
Loader $configLoader,
46+
PhpstanConfigFileSaverInterface $phpstanConfigFileSaver
47+
) {
3848
$this->filesystem = $filesystem;
3949
$this->config = $config;
4050
$this->configLoader = $configLoader;
51+
$this->phpstanConfigFileSaver = $phpstanConfigFileSaver;
4152
}
4253

4354
/**
@@ -113,7 +124,10 @@ protected function saveConfig(string $newConfigFileName, array $mergedConfig): s
113124
}
114125

115126
$newConfigFilePath = $directory . $newConfigFileName;
116-
$this->configLoader->save($mergedConfig, $newConfigFilePath . $this->config->getPhpstanConfigFilename());
127+
$this->phpstanConfigFileSaver->save(
128+
$newConfigFilePath . $this->config->getPhpstanConfigFilename(),
129+
$mergedConfig,
130+
);
117131

118132
return $newConfigFilePath;
119133
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
/**
4+
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5+
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6+
*/
7+
8+
namespace Spryker\Zed\Development\Business\Phpstan\Config;
9+
10+
use InvalidArgumentException;
11+
use Nette\DI\Config\Adapter;
12+
use RuntimeException;
13+
14+
class PhpstanConfigFileSaver implements PhpstanConfigFileSaverInterface
15+
{
16+
/**
17+
* @var string
18+
*/
19+
protected const ERROR_CANNOT_WRITE_FILE = "Cannot write file '%s'.";
20+
21+
/**
22+
* @var string
23+
*/
24+
protected const ERROR_UNKNOWN_FILE_EXTENSION = "Unknown file extension '%s'.";
25+
26+
/**
27+
* @var array<string, string>
28+
*/
29+
protected array $fileAdapters;
30+
31+
/**
32+
* @param array<string, string> $fileAdapters
33+
*/
34+
public function __construct(array $fileAdapters = [])
35+
{
36+
$this->fileAdapters = $fileAdapters;
37+
}
38+
39+
/**
40+
* @param string $configFilePath
41+
* @param array<mixed> $data
42+
*
43+
* @throws \RuntimeException
44+
*
45+
* @return void
46+
*/
47+
public function save(string $configFilePath, array $data): void
48+
{
49+
if (file_put_contents($configFilePath, $this->getAdapter($configFilePath)->dump($data)) === false) {
50+
throw new RuntimeException(sprintf(static::ERROR_CANNOT_WRITE_FILE, $configFilePath));
51+
}
52+
}
53+
54+
/**
55+
* @param string $filePath
56+
*
57+
* @throws \InvalidArgumentException
58+
*
59+
* @return \Nette\DI\Config\Adapter
60+
*/
61+
protected function getAdapter(string $filePath): Adapter
62+
{
63+
$extension = strtolower(pathinfo($filePath, PATHINFO_EXTENSION));
64+
if (!isset($this->fileAdapters[$extension])) {
65+
throw new InvalidArgumentException(sprintf(static::ERROR_UNKNOWN_FILE_EXTENSION, $filePath));
66+
}
67+
68+
if ($this->fileAdapters[$extension] instanceof Adapter) {
69+
return $this->fileAdapters[$extension];
70+
}
71+
72+
/** @var \Nette\DI\Config\Adapter $adapter */
73+
$adapter = new $this->fileAdapters[$extension]();
74+
75+
return $adapter;
76+
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/**
4+
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5+
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6+
*/
7+
8+
namespace Spryker\Zed\Development\Business\Phpstan\Config;
9+
10+
interface PhpstanConfigFileSaverInterface
11+
{
12+
/**
13+
* @param string $configFilePath
14+
* @param array<mixed> $data
15+
*
16+
* @return void
17+
*/
18+
public function save(string $configFilePath, array $data): void;
19+
}

src/Spryker/Zed/Development/DevelopmentDependencyProvider.php

+25
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Spryker\Zed\Development;
99

10+
use Nette\DI\Config\Adapters\NeonAdapter;
11+
use Nette\DI\Config\Adapters\PhpAdapter;
1012
use Nette\DI\Config\Loader;
1113
use Spryker\Zed\Development\Dependency\Facade\DevelopmentToModuleFinderFacadeBridge;
1214
use Spryker\Zed\Graph\Communication\Plugin\GraphPlugin;
@@ -57,6 +59,11 @@ class DevelopmentDependencyProvider extends AbstractBundleDependencyProvider
5759
*/
5860
public const TWIG_LOADER_FILESYSTEM = 'twig loader filesystem';
5961

62+
/**
63+
* @var string
64+
*/
65+
public const PHPSTAN_ADAPTERS = 'PHPSTAN_ADAPTERS';
66+
6067
/**
6168
* @param \Spryker\Zed\Kernel\Container $container
6269
*
@@ -89,6 +96,7 @@ public function provideBusinessLayerDependencies(Container $container)
8996
});
9097

9198
$container = $this->addModuleFinderFacade($container);
99+
$container = $this->addPhpstanAdapters($container);
92100

93101
return $container;
94102
}
@@ -158,4 +166,21 @@ protected function addModuleFinderFacade(Container $container): Container
158166

159167
return $container;
160168
}
169+
170+
/**
171+
* @param \Spryker\Zed\Kernel\Container $container
172+
*
173+
* @return \Spryker\Zed\Kernel\Container
174+
*/
175+
protected function addPhpstanAdapters(Container $container): Container
176+
{
177+
$container->set(static::PHPSTAN_ADAPTERS, function (Container $container) {
178+
return [
179+
'php' => PhpAdapter::class,
180+
'neon' => NeonAdapter::class,
181+
];
182+
});
183+
184+
return $container;
185+
}
161186
}

0 commit comments

Comments
 (0)