Skip to content

Commit ee2e2d6

Browse files
committed
Replace dependency steevanb/php-typed-array by steevanb/php-collection
1 parent a6502f2 commit ee2e2d6

37 files changed

+284
-308
lines changed

bin/ci/phpstan.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,35 @@
55
use Steevanb\ParallelProcess\{
66
Console\Application\ParallelProcessesApplication,
77
Process\Process,
8-
Process\ProcessInterfaceArray
8+
Process\ProcessInterfaceCollection
99
};
10-
use Steevanb\PhpTypedArray\ScalarArray\StringArray;
10+
use Steevanb\PhpCollection\ScalarCollection\StringCollection;
1111
use Symfony\Component\Console\Input\ArgvInput;
1212

1313
require dirname(__DIR__, 2) . '/vendor/autoload.php';
1414

15-
function getAvailableSymfonyVersions(): StringArray
15+
function getAvailableSymfonyVersions(): StringCollection
1616
{
17-
$return = new StringArray();
18-
foreach (new StringArray(['6.1', '6.2', '6.3']) as $symfonyVersion) {
19-
$return[] = $symfonyVersion;
17+
$return = new StringCollection();
18+
foreach ((new StringCollection(['6.1', '6.2', '6.3']))->toArray() as $symfonyVersion) {
19+
$return->add($symfonyVersion);
2020
}
2121

2222
return $return;
2323
}
2424

25-
function createPhpstanProcesses(string $phpVersion = null, string $symfonyVersion = null): ProcessInterfaceArray
25+
function createPhpstanProcesses(string $phpVersion = null, string $symfonyVersion = null): ProcessInterfaceCollection
2626
{
27-
$phpVersions = new StringArray(is_string($phpVersion) ? [$phpVersion] : ['8.1', '8.2']);
27+
$phpVersions = new StringCollection(is_string($phpVersion) ? [$phpVersion] : ['8.1', '8.2']);
2828

29-
$return = new ProcessInterfaceArray();
30-
foreach ($phpVersions as $loopPhpVersion) {
29+
$return = new ProcessInterfaceCollection();
30+
foreach ($phpVersions->toArray() as $loopPhpVersion) {
3131
$symfonyVersions = is_string($symfonyVersion)
3232
? [$symfonyVersion]
3333
: getAvailableSymfonyVersions()->toArray();
3434

3535
foreach ($symfonyVersions as $loopSymfonyVersion) {
36-
$return[] = createPhpstanProcess($loopPhpVersion, $loopSymfonyVersion);
36+
$return->add(createPhpstanProcess($loopPhpVersion, $loopSymfonyVersion));
3737
}
3838
}
3939

@@ -48,14 +48,14 @@ function createPhpstanProcess(string $phpVersion, string $symfonyVersion): Proce
4848

4949
$phpVersion = null;
5050
$symfonyVersion = null;
51-
$applicationArgv = new StringArray();
51+
$applicationArgv = new StringCollection();
5252
foreach ($argv as $arg) {
5353
if (str_starts_with($arg, '--php=')) {
5454
$phpVersion = substr($arg, 6);
5555
} elseif (str_starts_with($arg, '--symfony=')) {
5656
$symfonyVersion = substr($arg, 10);
5757
} else {
58-
$applicationArgv[] = $arg;
58+
$applicationArgv->add($arg);
5959
}
6060
}
6161

bin/ci/phpunit.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,35 @@
55
use Steevanb\ParallelProcess\{
66
Console\Application\ParallelProcessesApplication,
77
Process\Process,
8-
Process\ProcessInterfaceArray
8+
Process\ProcessInterfaceCollection
99
};
10-
use Steevanb\PhpTypedArray\ScalarArray\StringArray;
10+
use Steevanb\PhpCollection\ScalarCollection\StringCollection;
1111
use Symfony\Component\Console\Input\ArgvInput;
1212

1313
require dirname(__DIR__, 2) . '/vendor/autoload.php';
1414

15-
function getAvailableSymfonyVersions(): StringArray
15+
function getAvailableSymfonyVersions(): StringCollection
1616
{
17-
$return = new StringArray();
18-
foreach (new StringArray(['6.1', '6.2', '6.3']) as $symfonyVersion) {
19-
$return[] = $symfonyVersion;
17+
$return = new StringCollection();
18+
foreach (new StringCollection(['6.1', '6.2', '6.3']) as $symfonyVersion) {
19+
$return->add($symfonyVersion);
2020
}
2121

2222
return $return;
2323
}
2424

25-
function createPhpunitProcesses(string $phpVersion = null, string $symfonyVersion = null): ProcessInterfaceArray
25+
function createPhpunitProcesses(string $phpVersion = null, string $symfonyVersion = null): ProcessInterfaceCollection
2626
{
27-
$phpVersions = new StringArray(is_string($phpVersion) ? [$phpVersion] : ['8.1', '8.2']);
27+
$phpVersions = new StringCollection(is_string($phpVersion) ? [$phpVersion] : ['8.1', '8.2']);
2828

29-
$return = new ProcessInterfaceArray();
29+
$return = new ProcessInterfaceCollection();
3030
foreach ($phpVersions as $loopPhpVersion) {
3131
$symfonyVersions = is_string($symfonyVersion)
3232
? [$symfonyVersion]
3333
: getAvailableSymfonyVersions()->toArray();
3434

3535
foreach ($symfonyVersions as $loopSymfonyVersion) {
36-
$return[] = createPhpunitProcess($loopPhpVersion, $loopSymfonyVersion);
36+
$return->add(createPhpunitProcess($loopPhpVersion, $loopSymfonyVersion));
3737
}
3838
}
3939

@@ -48,14 +48,14 @@ function createPhpunitProcess(string $phpVersion, string $symfonyVersion): Proce
4848

4949
$phpVersion = null;
5050
$symfonyVersion = null;
51-
$applicationArgv = new StringArray();
51+
$applicationArgv = new StringCollection();
5252
foreach ($argv as $arg) {
5353
if (str_starts_with($arg, '--php=')) {
5454
$phpVersion = substr($arg, 6);
5555
} elseif (str_starts_with($arg, '--symfony=')) {
5656
$symfonyVersion = substr($arg, 10);
5757
} else {
58-
$applicationArgv[] = $arg;
58+
$applicationArgv->add($arg);
5959
}
6060
}
6161

changelog.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
- [#226](https://github.com/steevanb/php-parallel-processes/issues/226) Add compatibility with Symfony 6.3
55
- [#228](https://github.com/steevanb/php-parallel-processes/issues/228) Execute phpstan for each Symfony version
66
- [#224](https://github.com/steevanb/php-parallel-processes/issues/224) Add global timeout with ParallelProcessesApplication::setTimeout()
7+
- **[BC Break]** [#215](https://github.com/steevanb/php-parallel-processes/issues/215) Replace dependency `steevanb/php-typed-array` by `steevanb/php-collection`
8+
- **[BC Break]** Add `ProcessInterface::stop()` (it should not be a problem as it's a method already asked by symfony/process interface)
9+
- Use `ProcessInterface` as argument instead of `Process` everywhere
710

811
### [0.11.0](../../compare/0.10.0...0.11.0) - 2023-04-05
912

10-
- [BC Break] Replace `ProcessArray` by `ProcessInterfaceArray`
13+
- **[BC Break]** Replace `ProcessArray` by `ProcessInterfaceArray`
1114
- Add `ProcessInterface`, `BootstrapProcessInterface` and `TearDownProcessInterface`
1215
- Add `BootstrapProcess` and `TearDownProcess`
13-
- [BC Break] Add ProcessInterface::getOutputStatePrefix() and getOutputSummaryPrefix()
16+
- **[BC Break]** Add ProcessInterface::getOutputStatePrefix() and getOutputSummaryPrefix()
1417
- Add Process::setOutputStatePrefix(), getOutputStatePrefix(), setOutputSummaryPrefix(), getOutputSummaryPrefix() and setOutputPrefix()
1518

1619
### [0.10.0](../../compare/0.9.0...0.10.0) - 2023-02-21

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"require": {
1313
"php": "^8.1",
1414
"ext-pcntl": "*",
15-
"steevanb/php-typed-array": "^4.0",
15+
"steevanb/php-collection": "^5.0",
1616
"symfony/console": "^6.1",
1717
"symfony/process": "^6.1"
1818
},
@@ -28,7 +28,6 @@
2828
},
2929
"autoload-dev": {
3030
"psr-4": {
31-
"Steevanb\\PhpTypedArray\\Bridge\\Phpstan\\": "vendor/steevanb/php-typed-array/bridge/Phpstan/src",
3231
"Steevanb\\ParallelProcess\\Tests\\": "tests/"
3332
}
3433
},

config/ci/phpstan.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ parameters:
1515
message: '#Return type \(void\) of method Steevanb\\ParallelProcess\\Console\\Application\\ParallelProcessesApplication::handleSignal\(\) should be compatible with return type \(int\|false\) of method Symfony\\Component\\Console\\Command\\SignalableCommandInterface::handleSignal\(\)#'
1616
reportUnmatched: false
1717
includes:
18-
- ../../vendor/steevanb/php-typed-array/bridge/Phpstan/rules.neon
1918
- /composer/common/vendor/phpstan/phpstan-deprecation-rules/rules.neon
2019
- /composer/common/vendor/phpstan/phpstan-phpunit/extension.neon
2120
- /composer/common/vendor/phpstan/phpstan-phpunit/rules.neon

src/Console/Application/ParallelProcessesApplication.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
Exception\ParallelProcessException,
1313
Process\BootstrapProcessInterface,
1414
Process\ProcessInterface,
15-
Process\ProcessInterfaceArray,
15+
Process\ProcessInterfaceCollection,
1616
Process\TearDownProcessInterface
1717
};
1818
use Symfony\Component\Console\{
@@ -25,7 +25,7 @@
2525

2626
class ParallelProcessesApplication extends SingleCommandApplication implements SignalableCommandInterface
2727
{
28-
protected ProcessInterfaceArray $processes;
28+
protected ProcessInterfaceCollection $processes;
2929

3030
protected ThemeInterface $theme;
3131

@@ -47,20 +47,20 @@ public function __construct(string $name = null)
4747
{
4848
parent::__construct($name);
4949

50-
$this->processes = new ProcessInterfaceArray();
50+
$this->processes = new ProcessInterfaceCollection();
5151
$this
5252
->setCode([$this, 'runProcessesInParallel'])
5353
->setTheme(new DefaultTheme());
5454
}
5555

5656
public function addProcess(ProcessInterface $process): static
5757
{
58-
$this->processes[] = $process;
58+
$this->processes->add($process);
5959

6060
return $this;
6161
}
6262

63-
public function addProcesses(ProcessInterfaceArray $processes): static
63+
public function addProcesses(ProcessInterfaceCollection $processes): static
6464
{
6565
foreach ($processes->toArray() as $process) {
6666
$this->addProcess($process);
@@ -82,7 +82,7 @@ public function hasProcess(ProcessInterface $process): bool
8282
return $return;
8383
}
8484

85-
public function getProcesses(): ProcessInterfaceArray
85+
public function getProcesses(): ProcessInterfaceCollection
8686
{
8787
return $this->processes;
8888
}
@@ -217,10 +217,10 @@ protected function runProcessesInParallel(InputInterface $input, OutputInterface
217217

218218
protected function configureBootstrapProcesses(): static
219219
{
220-
$bootstrapProcesses = new ProcessInterfaceArray();
220+
$bootstrapProcesses = new ProcessInterfaceCollection();
221221
foreach ($this->getProcesses()->toArray() as $process) {
222222
if ($process instanceof BootstrapProcessInterface) {
223-
$bootstrapProcesses[] = $process;
223+
$bootstrapProcesses->add($process);
224224
}
225225
}
226226
$bootstrapProcesses->setReadOnly();
@@ -237,10 +237,10 @@ protected function configureBootstrapProcesses(): static
237237

238238
protected function configureTearDownProcesses(): static
239239
{
240-
$tearDownProcesses = new ProcessInterfaceArray();
240+
$tearDownProcesses = new ProcessInterfaceCollection();
241241
foreach ($this->getProcesses()->toArray() as $process) {
242242
if ($process instanceof TearDownProcessInterface) {
243-
$tearDownProcesses[] = $process;
243+
$tearDownProcesses->add($process);
244244
}
245245
}
246246
$tearDownProcesses->setReadOnly();
@@ -255,15 +255,15 @@ protected function configureTearDownProcesses(): static
255255
return $this;
256256
}
257257

258-
protected function getStandardProcesses(): ProcessInterfaceArray
258+
protected function getStandardProcesses(): ProcessInterfaceCollection
259259
{
260-
$return = new ProcessInterfaceArray();
260+
$return = new ProcessInterfaceCollection();
261261
foreach ($this->getProcesses()->toArray() as $process) {
262262
if (
263263
$process instanceof BootstrapProcessInterface === false
264264
&& $process instanceof TearDownProcessInterface === false
265265
) {
266-
$return[] = $process;
266+
$return->add($process);
267267
}
268268
}
269269

src/Console/Application/Theme/DefaultTheme.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
Exception\ParallelProcessException,
1010
Process\Process,
1111
Process\ProcessInterface,
12-
Process\ProcessInterfaceArray
12+
Process\ProcessInterfaceCollection
1313
};
1414
use Symfony\Component\Console\{
1515
Color,
1616
Output\OutputInterface
1717
};
18-
use Steevanb\PhpTypedArray\ScalarArray\StringArray;
18+
use Steevanb\PhpCollection\ScalarCollection\StringCollection;
1919

2020
class DefaultTheme implements ThemeInterface
2121
{
@@ -183,7 +183,7 @@ public function getExecutionTimeVerbosity(): int
183183
return $this->executionTimeVerbosity;
184184
}
185185

186-
public function resetOutput(OutputInterface $output, ProcessInterfaceArray $processes): static
186+
public function resetOutput(OutputInterface $output, ProcessInterfaceCollection $processes): static
187187
{
188188
for ($reset = 0; $reset < $processes->count(); $reset++) {
189189
$output->write("\e[1A\e[K");
@@ -192,7 +192,7 @@ public function resetOutput(OutputInterface $output, ProcessInterfaceArray $proc
192192
return $this;
193193
}
194194

195-
public function outputStart(OutputInterface $output, ProcessInterfaceArray $processes): static
195+
public function outputStart(OutputInterface $output, ProcessInterfaceCollection $processes): static
196196
{
197197
foreach ($processes->toArray() as $process) {
198198
$this->outputProcessState($output, $process);
@@ -203,7 +203,7 @@ public function outputStart(OutputInterface $output, ProcessInterfaceArray $proc
203203
return $this;
204204
}
205205

206-
public function outputProcessesState(OutputInterface $output, ProcessInterfaceArray $processes): static
206+
public function outputProcessesState(OutputInterface $output, ProcessInterfaceCollection $processes): static
207207
{
208208
$this->resetOutput($output, $processes);
209209

@@ -216,7 +216,7 @@ public function outputProcessesState(OutputInterface $output, ProcessInterfaceAr
216216
return $this;
217217
}
218218

219-
public function outputSummary(OutputInterface $output, ProcessInterfaceArray $processes): static
219+
public function outputSummary(OutputInterface $output, ProcessInterfaceCollection $processes): static
220220
{
221221
$this->resetOutput($output, $processes);
222222

@@ -233,7 +233,7 @@ public function outputSummary(OutputInterface $output, ProcessInterfaceArray $pr
233233

234234
protected function outputProcessSummary(OutputInterface $output, ProcessInterface $process): static
235235
{
236-
$lines = new StringArray();
236+
$lines = new StringCollection();
237237

238238
if ($process->isTerminated()) {
239239
if ($process->isSuccessful()) {
@@ -287,7 +287,7 @@ protected function outputProcessSummary(OutputInterface $output, ProcessInterfac
287287
$this->removeLastEmptyLines($lines);
288288

289289
if ($lines->count() > 0) {
290-
$output->writeln($lines);
290+
$output->writeln($lines->toArray());
291291
}
292292

293293
return $this;
@@ -297,10 +297,10 @@ protected function mergeProcessOutput(
297297
OutputInterface $output,
298298
?string $prefix,
299299
string $processOutput,
300-
StringArray $lines
300+
StringCollection $lines
301301
): static {
302302
$lines->merge(
303-
new StringArray(
303+
new StringCollection(
304304
array_map(
305305
fn(string $line): string => $prefix . ($output->isDecorated() ? ' ' . $line : ' ' . $line),
306306
explode("\n", $processOutput)
@@ -311,14 +311,13 @@ protected function mergeProcessOutput(
311311
return $this;
312312
}
313313

314-
protected function removeLastEmptyLines(StringArray $lines): static
314+
protected function removeLastEmptyLines(StringCollection $lines): static
315315
{
316316
while (
317317
$lines->count() >= 1
318-
&& is_string($lines[$lines->count() - 1])
319-
&& trim($lines[$lines->count() - 1]) === ''
318+
&& trim($lines->get($lines->count() - 1)) === ''
320319
) {
321-
unset($lines[$lines->count() - 1]);
320+
$lines->remove($lines->count() - 1);
322321
}
323322

324323
return $this;

src/Console/Application/Theme/SummaryTheme.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
namespace Steevanb\ParallelProcess\Console\Application\Theme;
66

7-
use Steevanb\ParallelProcess\Process\ProcessInterfaceArray;
7+
use Steevanb\ParallelProcess\Process\ProcessInterfaceCollection;
88
use Symfony\Component\Console\Output\OutputInterface;
99

1010
class SummaryTheme extends DefaultTheme
1111
{
12-
public function outputStart(OutputInterface $output, ProcessInterfaceArray $processes): static
12+
public function outputStart(OutputInterface $output, ProcessInterfaceCollection $processes): static
1313
{
1414
$output->writeln(
1515
'Starting <info>'
@@ -23,12 +23,12 @@ public function outputStart(OutputInterface $output, ProcessInterfaceArray $proc
2323
return $this;
2424
}
2525

26-
public function outputProcessesState(OutputInterface $output, ProcessInterfaceArray $processes): static
26+
public function outputProcessesState(OutputInterface $output, ProcessInterfaceCollection $processes): static
2727
{
2828
return $this;
2929
}
3030

31-
public function resetOutput(OutputInterface $output, ProcessInterfaceArray $processes): static
31+
public function resetOutput(OutputInterface $output, ProcessInterfaceCollection $processes): static
3232
{
3333
return $this;
3434
}

0 commit comments

Comments
 (0)