Skip to content

Commit 8317d4c

Browse files
authored
[TASK] Activate order rector (#26)
1 parent 27548e2 commit 8317d4c

File tree

2 files changed

+96
-96
lines changed

2 files changed

+96
-96
lines changed

rector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
$containerConfigurator->import(SetList::CODING_STYLE);
3636
$containerConfigurator->import(SetList::DEAD_CODE);
3737
$containerConfigurator->import(SetList::NAMING);
38-
//$containerConfigurator->import(SetList::ORDER);
38+
$containerConfigurator->import(SetList::ORDER);
3939
$containerConfigurator->import(SetList::PRIVATIZATION);
4040
$containerConfigurator->import(SetList::PSR_4);
4141
//$containerConfigurator->import(SetList::TYPE_DECLARATION);

src/Utility/ComposerUtils.php

Lines changed: 95 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,22 @@ public function __construct(Composer $composer, IOInterface $io)
8484
}
8585

8686
/**
87-
* @return array<string, string>
87+
* @return array<int, string>
8888
*/
89-
private function getPreferredInstall(): array
89+
private function getPreferredInstallChanged(): array
9090
{
9191
$config = $this->configFile->read();
9292

9393
if (
9494
!is_array($config)
95-
|| !is_array($config[self::CONFIG] ?? null)
96-
|| !is_array($config[self::CONFIG][self::CONFIG_PREFERRED_INSTALL] ?? null)
95+
|| !is_array($config[self::EXTRA] ?? null)
96+
|| !is_array($config[self::EXTRA][self::EXTRA_BASE] ?? null)
97+
|| !is_array($config[self::EXTRA][self::EXTRA_BASE][self::EXTRA_PREFERRED_INSTALL_CHANGED] ?? null)
9798
) {
9899
return [];
99100
}
100101

101-
return $config[self::CONFIG][self::CONFIG_PREFERRED_INSTALL];
102+
return $config[self::EXTRA][self::EXTRA_BASE][self::EXTRA_PREFERRED_INSTALL_CHANGED];
102103
}
103104

104105
/**
@@ -121,93 +122,75 @@ private function getAppliedChanges(): array
121122
}
122123

123124
/**
124-
* @return array<int, string>
125-
*/
126-
private function getPreferredInstallChanged(): array
127-
{
128-
$config = $this->configFile->read();
129-
130-
if (
131-
!is_array($config)
132-
|| !is_array($config[self::EXTRA] ?? null)
133-
|| !is_array($config[self::EXTRA][self::EXTRA_BASE] ?? null)
134-
|| !is_array($config[self::EXTRA][self::EXTRA_BASE][self::EXTRA_PREFERRED_INSTALL_CHANGED] ?? null)
135-
) {
136-
return [];
137-
}
138-
139-
return $config[self::EXTRA][self::EXTRA_BASE][self::EXTRA_PREFERRED_INSTALL_CHANGED];
140-
}
141-
142-
/**
143-
* @return array<string, array<string, string>>
125+
* @return array<string, string>
144126
*/
145-
private function getPatches(): array
127+
private function getPreferredInstall(): array
146128
{
147129
$config = $this->configFile->read();
148130

149131
if (
150132
!is_array($config)
151-
|| !is_array($config[self::EXTRA] ?? null)
152-
|| !is_array($config[self::EXTRA]['patches'] ?? null)
133+
|| !is_array($config[self::CONFIG] ?? null)
134+
|| !is_array($config[self::CONFIG][self::CONFIG_PREFERRED_INSTALL] ?? null)
153135
) {
154136
return [];
155137
}
156138

157-
return $config[self::EXTRA]['patches'];
158-
}
159-
160-
/**
161-
* @param array<string, array<string, string>> $patches
162-
*/
163-
private function addPatchesToConfigFile(array $patches): void
164-
{
165-
foreach ($patches as $packageName => $packagePatches) {
166-
$this->configSource->addProperty(sprintf('extra.patches.%s', $packageName), $packagePatches);
167-
}
168-
}
169-
170-
/**
171-
* @param array<string, array<string, string>> $patches
172-
*/
173-
private function removePatchesFromConfigFile(array $patches): void
174-
{
175-
foreach (array_keys($patches) as $packageName) {
176-
$this->configSource->removeProperty(sprintf('extra.patches.%s', $packageName));
177-
}
139+
return $config[self::CONFIG][self::CONFIG_PREFERRED_INSTALL];
178140
}
179141

180-
private function setSourceInstall(string $packageName): void
142+
private function addPreferredInstallChanged(string $packageName): void
181143
{
182-
$currentValue = $this->getPreferredInstall();
144+
$currentValue = $this->getPreferredInstallChanged();
183145

184-
if (isset($currentValue[$packageName]) && $currentValue[$packageName] === 'source') {
185-
// source install for this package is already configured, skip it
146+
if (in_array($packageName, $currentValue, true)) {
147+
// the package is already listed, skip addition
186148
return;
187149
}
188150

189-
$this->configSource->addConfigSetting(
190-
'preferred-install.' . $packageName,
191-
'source'
192-
);
151+
$currentValue[] = $packageName;
152+
sort($currentValue);
193153

194-
$this->addPreferredInstallChanged($packageName);
154+
$this->configSource->addProperty(
155+
sprintf(
156+
'extra.%s.%s',
157+
self::EXTRA_BASE,
158+
self::EXTRA_PREFERRED_INSTALL_CHANGED
159+
),
160+
$currentValue
161+
);
195162
}
196163

197-
private function unsetSourceInstall(string $packageName): void
164+
private function removePreferredInstallChanged(string $packageName): void
198165
{
199166
$currentValue = $this->getPreferredInstallChanged();
200167

201168
if (!in_array($packageName, $currentValue, true)) {
202-
// source was not set by this package, skip removal
169+
// the package is not listed, skip removal
203170
return;
204171
}
205172

206-
$this->configSource->removeConfigSetting(
207-
'preferred-install.' . $packageName
173+
$currentValue = array_filter($currentValue, fn ($value): bool => $value !== $packageName);
174+
sort($currentValue);
175+
176+
$this->configSource->addProperty(
177+
sprintf(
178+
'extra.%s.%s',
179+
self::EXTRA_BASE,
180+
self::EXTRA_PREFERRED_INSTALL_CHANGED
181+
),
182+
$currentValue
208183
);
184+
}
209185

210-
$this->removePreferredInstallChanged($packageName);
186+
/**
187+
* @param array<string, array<string, string>> $patches
188+
*/
189+
private function addPatchesToConfigFile(array $patches): void
190+
{
191+
foreach ($patches as $packageName => $packagePatches) {
192+
$this->configSource->addProperty(sprintf('extra.patches.%s', $packageName), $packagePatches);
193+
}
211194
}
212195

213196
private function addAppliedChange(int $numericId): void
@@ -232,67 +215,84 @@ private function addAppliedChange(int $numericId): void
232215
);
233216
}
234217

235-
private function removeAppliedChange(int $numericId): void
218+
private function setSourceInstall(string $packageName): void
236219
{
237-
$currentValue = $this->getAppliedChanges();
220+
$currentValue = $this->getPreferredInstall();
238221

239-
if (!in_array($numericId, $currentValue, true)) {
240-
// the package is not listed, skip removal
222+
if (isset($currentValue[$packageName]) && $currentValue[$packageName] === 'source') {
223+
// source install for this package is already configured, skip it
241224
return;
242225
}
243226

244-
$currentValue = array_filter($currentValue, fn ($value): bool => $value !== $numericId);
245-
sort($currentValue);
246-
247-
$this->configSource->addProperty(
248-
sprintf(
249-
'extra.%s.%s',
250-
self::EXTRA_BASE,
251-
self::EXTRA_APPLIED_CHANGES
252-
),
253-
$currentValue
227+
$this->configSource->addConfigSetting(
228+
'preferred-install.' . $packageName,
229+
'source'
254230
);
231+
232+
$this->addPreferredInstallChanged($packageName);
255233
}
256234

257-
private function addPreferredInstallChanged(string $packageName): void
235+
/**
236+
* @return array<string, array<string, string>>
237+
*/
238+
private function getPatches(): array
258239
{
259-
$currentValue = $this->getPreferredInstallChanged();
240+
$config = $this->configFile->read();
260241

261-
if (in_array($packageName, $currentValue, true)) {
262-
// the package is already listed, skip addition
263-
return;
242+
if (
243+
!is_array($config)
244+
|| !is_array($config[self::EXTRA] ?? null)
245+
|| !is_array($config[self::EXTRA]['patches'] ?? null)
246+
) {
247+
return [];
264248
}
265249

266-
$currentValue[] = $packageName;
267-
sort($currentValue);
250+
return $config[self::EXTRA]['patches'];
251+
}
268252

269-
$this->configSource->addProperty(
270-
sprintf(
271-
'extra.%s.%s',
272-
self::EXTRA_BASE,
273-
self::EXTRA_PREFERRED_INSTALL_CHANGED
274-
),
275-
$currentValue
276-
);
253+
/**
254+
* @param array<string, array<string, string>> $patches
255+
*/
256+
private function removePatchesFromConfigFile(array $patches): void
257+
{
258+
foreach (array_keys($patches) as $packageName) {
259+
$this->configSource->removeProperty(sprintf('extra.patches.%s', $packageName));
260+
}
277261
}
278262

279-
private function removePreferredInstallChanged(string $packageName): void
263+
private function unsetSourceInstall(string $packageName): void
280264
{
281265
$currentValue = $this->getPreferredInstallChanged();
282266

283267
if (!in_array($packageName, $currentValue, true)) {
268+
// source was not set by this package, skip removal
269+
return;
270+
}
271+
272+
$this->configSource->removeConfigSetting(
273+
'preferred-install.' . $packageName
274+
);
275+
276+
$this->removePreferredInstallChanged($packageName);
277+
}
278+
279+
private function removeAppliedChange(int $numericId): void
280+
{
281+
$currentValue = $this->getAppliedChanges();
282+
283+
if (!in_array($numericId, $currentValue, true)) {
284284
// the package is not listed, skip removal
285285
return;
286286
}
287287

288-
$currentValue = array_filter($currentValue, fn ($value): bool => $value !== $packageName);
288+
$currentValue = array_filter($currentValue, fn ($value): bool => $value !== $numericId);
289289
sort($currentValue);
290290

291291
$this->configSource->addProperty(
292292
sprintf(
293293
'extra.%s.%s',
294294
self::EXTRA_BASE,
295-
self::EXTRA_PREFERRED_INSTALL_CHANGED
295+
self::EXTRA_APPLIED_CHANGES
296296
),
297297
$currentValue
298298
);

0 commit comments

Comments
 (0)