Skip to content

Commit 87abd9a

Browse files
authored
Fix errors reported by PHPStorm (#70)
1 parent d57176c commit 87abd9a

8 files changed

+32
-38
lines changed

README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This library supports the parallelization of Symfony Console commands.
66
How it works
77
------------
88

9-
When you launch a command with multi-processing enabled (`--processes 2`), a
9+
When you launch a command with multiprocessing enabled (`--processes 2`), a
1010
master process fetches *items* and distributes them across the given number of
1111
child processes. Child processes are killed after a fixed number of items
1212
(a *segment*) in order to prevent them from slowing down over time.
@@ -103,7 +103,7 @@ Items
103103
-----
104104

105105
The master process fetches all the items that need to be processed and passes
106-
them to the child processes through their Standard Input. Hence items must
106+
them to the child processes through their Standard Input. Hence, items must
107107
fulfill two requirements:
108108

109109
* Items must be strings
@@ -118,9 +118,9 @@ master process to the child process. Some typical examples for items:
118118
Segments
119119
--------
120120

121-
When you run a command with multi-processing enabled, the items returned by
121+
When you run a command with multiprocessing enabled, the items returned by
122122
`fetchItems()` are split into segments of a fixed size. Each child processes
123-
processes a single segment and kills itself after that.
123+
process a single segment and kills itself after that.
124124

125125
By default, the segment size is the same as the batch size (see below), but you
126126
can try to tweak the performance of your command by choosing a different segment
@@ -173,12 +173,12 @@ Hooks
173173
The `Parallelization` trait supports more hooks than the one mentioned in the
174174
last section. In the table below you can find a complete list of them:
175175

176-
Method | Scope | Description
177-
------------------------------------------- | ----------------- | ---------------------------------------------
178-
`runBeforeFirstCommand($input, $output)` | Master process | Run before any child process is spawned
179-
`runAfterLastCommand($input, $output)` | Master process | Run after all child processes have completed
180-
`runBeforeBatch($input, $output, $items)` | Child process | Run before each batch in the child process
181-
`runAfterBatch($input, $output, $items)` | Child process | Run after each batch in the child process
176+
| Method | Scope | Description |
177+
|-------------------------------------------|----------------|----------------------------------------------|
178+
| `runBeforeFirstCommand($input, $output)` | Master process | Run before any child process is spawned |
179+
| `runAfterLastCommand($input, $output)` | Master process | Run after all child processes have completed |
180+
| `runBeforeBatch($input, $output, $items)` | Child process | Run before each batch in the child process |
181+
| `runAfterBatch($input, $output, $items)` | Child process | Run after each batch in the child process |
182182

183183
Authors
184184
-------
@@ -206,4 +206,4 @@ All contents of this package are licensed under the [MIT license].
206206
[The Community Contributors]: https://github.com/webmozarts/console-parallelization/graphs/contributors
207207
[issue tracker]: https://github.com/webmozarts/console-parallelization/issues
208208
[Git repository]: https://github.com/webmozarts/console-parallelization
209-
[MIT license]: LICENSE
209+
[MIT license]: LICENSE.md_

src/ChunkedItemsIterator.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626

2727
final class ChunkedItemsIterator
2828
{
29-
private $items;
30-
private $numberOfItems;
31-
private $itemsChunks;
29+
private array $items;
30+
private int $numberOfItems;
31+
private array $itemsChunks;
3232

3333
/**
3434
* @param list<string> $items
@@ -48,7 +48,6 @@ public function __construct(array $items, int $batchSize)
4848
$this->itemsChunks = array_chunk(
4949
$this->items,
5050
$batchSize,
51-
false,
5251
);
5352
$this->numberOfItems = count($this->items);
5453
}

src/Configuration.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
final class Configuration
2121
{
22-
private $segmentSize;
23-
private $rounds;
24-
private $batches;
22+
private int $segmentSize;
23+
private int $rounds;
24+
private int $batches;
2525

2626
public function __construct(
2727
bool $numberOfProcessesDefined,

src/ContainerAwareCommand.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020

2121
abstract class ContainerAwareCommand extends Command implements ContainerAwareInterface
2222
{
23-
/**
24-
* @var ContainerInterface|null
25-
*/
26-
private $container;
23+
private ?ContainerInterface $container = null;
2724

2825
public function setContainer(?ContainerInterface $container = null): void
2926
{

src/Parallelization.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use function sprintf;
2828
use const STDIN;
2929
use function stream_get_contents;
30-
use Symfony\Component\Console\Application;
3130
use Symfony\Component\Console\Command\Command;
3231
use Symfony\Component\Console\Helper\ProgressBar;
3332
use Symfony\Component\Console\Input\InputInterface;
@@ -72,7 +71,7 @@
7271
*/
7372
trait Parallelization
7473
{
75-
private $logError = true;
74+
private bool $logError = true;
7675

7776
/**
7877
* Provided by Symfony Command class.
@@ -311,7 +310,7 @@ function () use ($input) {
311310
$this->runBeforeBatch($input, $output, $items);
312311

313312
foreach ($items as $item) {
314-
$this->runTolerantSingleCommand((string) $item, $input, $output);
313+
$this->runTolerantSingleCommand($item, $input, $output);
315314

316315
$progressBar->advance();
317316
}

src/ParallelizationInput.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ final class ParallelizationInput
2727
private const PROCESSES_OPTION = 'processes';
2828
private const CHILD_OPTION = 'child';
2929

30-
private $numberOfProcessesDefined;
31-
private $numberOfProcesses = 1;
32-
private $item;
33-
private $childProcess;
30+
private bool $numberOfProcessesDefined;
31+
private int $numberOfProcesses = 1;
32+
private ?string $item;
33+
private bool $childProcess;
3434

3535
public function __construct(InputInterface $input)
3636
{
@@ -96,7 +96,6 @@ public static function configureParallelization(Command $command): void
9696
'p',
9797
InputOption::VALUE_OPTIONAL,
9898
'The number of parallel processes to run',
99-
null,
10099
)
101100
->addOption(
102101
self::CHILD_OPTION,

src/ProcessLauncher.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,24 @@
2929
*/
3030
class ProcessLauncher
3131
{
32-
private $command;
32+
private string $command;
3333

34-
private $workingDirectory;
34+
private string $workingDirectory;
3535

36-
private $environmentVariables;
36+
private array $environmentVariables;
3737

38-
private $processLimit;
38+
private int $processLimit;
3939

40-
private $segmentSize;
40+
private int $segmentSize;
4141

4242
private $logger;
4343

44-
private $callback;
44+
private Closure $callback;
4545

4646
/**
4747
* @var Process[]
4848
*/
49-
private $runningProcesses = [];
49+
private array $runningProcesses = [];
5050

5151
public function __construct(
5252
string $command, // @TODO change to array for 2.0

tests/Integration/TestLogger.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function recordBeforeBatch(): void
5252
$this->write(self::formatMethodName(__METHOD__));
5353
}
5454

55-
public function recordSingleCommand(string $movieFileName, string $movieFileContent)
55+
public function recordSingleCommand(string $movieFileName, string $movieFileContent): void
5656
{
5757
$this->write(
5858
sprintf(

0 commit comments

Comments
 (0)