From 9074a6e846795a3f49a6499d47d6e8c5f984982e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20Eugon=C3=A9?= Date: Fri, 18 Dec 2020 18:14:31 +0100 Subject: [PATCH 1/2] Add typed properties --- src/batch-box-spout/src/FlatFileReader.php | 10 +++--- src/batch-box-spout/src/FlatFileWriter.php | 12 +++---- .../src/DoctrineDBALJobExecutionStorage.php | 32 +++++++++---------- .../src/JobExecutionRowNormalizer.php | 24 +++++++------- .../DoctrineDBALJobExecutionStorageTest.php | 2 +- src/batch-doctrine-orm/src/EntityReader.php | 4 +-- src/batch-doctrine-orm/tests/User.php | 2 +- .../src/ObjectWriter.php | 8 ++--- .../tests/Group.php | 2 +- .../tests/Product.php | 2 +- src/batch-doctrine-persistence/tests/User.php | 2 +- .../src/CommandRunner.php | 6 ++-- .../src/RunCommandJobLauncher.php | 8 ++--- .../src/RunJobCommand.php | 2 +- .../src/DispatchMessageJobLauncher.php | 6 ++-- .../src/LaunchJobMessage.php | 4 +-- .../src/LaunchJobMessageHandler.php | 2 +- .../src/DenormalizeItemProcessor.php | 8 ++--- .../src/NormalizeItemProcessor.php | 6 ++-- .../src/SkipInvalidItemProcessor.php | 4 +-- .../docs/domain/job-execution-storage.md | 2 +- src/batch/src/BatchStatus.php | 2 +- src/batch/src/Event/JobEvent.php | 2 +- src/batch/src/Failure.php | 10 +++--- .../src/Job/Item/InvalidItemException.php | 2 +- src/batch/src/Job/Item/ItemJob.php | 12 +++---- .../src/Job/Item/Processor/ChainProcessor.php | 2 +- .../src/Job/Item/Reader/SequenceReader.php | 2 +- .../Job/Item/Reader/StaticIterableReader.php | 2 +- src/batch/src/Job/Item/Writer/ChainWriter.php | 2 +- src/batch/src/Job/JobExecutionAwareTrait.php | 2 +- src/batch/src/Job/JobParametersAwareTrait.php | 2 +- src/batch/src/Job/JobWithChildJobs.php | 6 ++-- src/batch/src/Job/SummaryAwareTrait.php | 2 +- src/batch/src/JobExecution.php | 26 +++++++-------- src/batch/src/JobExecutionLogger.php | 12 +++---- src/batch/src/JobExecutionLogs.php | 2 +- src/batch/src/JobParameters.php | 2 +- src/batch/src/Launcher/SimpleJobLauncher.php | 8 ++--- src/batch/src/Registry/JobRegistry.php | 2 +- .../Storage/FilesystemJobExecutionStorage.php | 4 +-- src/batch/src/Storage/Query.php | 12 +++---- src/batch/src/Storage/QueryBuilder.php | 12 +++---- src/batch/src/Summary.php | 2 +- src/batch/src/Warning.php | 6 ++-- .../Item/Reader/StaticIterableReaderTest.php | 2 +- 46 files changed, 142 insertions(+), 144 deletions(-) diff --git a/src/batch-box-spout/src/FlatFileReader.php b/src/batch-box-spout/src/FlatFileReader.php index acb8c480..87a0c59b 100644 --- a/src/batch-box-spout/src/FlatFileReader.php +++ b/src/batch-box-spout/src/FlatFileReader.php @@ -35,27 +35,27 @@ final class FlatFileReader implements /** * @var string */ - private $type; + private string $type; /** * @var array */ - private $options; + private array $options; /** * @var string */ - private $headersMode; + private string $headersMode; /** * @var array|null */ - private $headers; + private ?array $headers; /** * @var string|null */ - private $filePath; + private ?string $filePath; public function __construct( string $type, diff --git a/src/batch-box-spout/src/FlatFileWriter.php b/src/batch-box-spout/src/FlatFileWriter.php index 791c9227..42548208 100644 --- a/src/batch-box-spout/src/FlatFileWriter.php +++ b/src/batch-box-spout/src/FlatFileWriter.php @@ -30,32 +30,32 @@ final class FlatFileWriter implements /** * @var string */ - private $type; + private string $type; /** * @var array|null */ - private $headers; + private ?array $headers; /** * @var WriterInterface|null */ - private $writer; + private ?WriterInterface $writer = null; /** * @var bool */ - private $headersAdded = false; + private bool $headersAdded = false; /** * @var string|null */ - private $filePath; + private ?string $filePath; /** * @var array */ - private $options; + private array $options; public function __construct(string $type, array $headers = null, string $filePath = null, array $options = []) { diff --git a/src/batch-doctrine-dbal/src/DoctrineDBALJobExecutionStorage.php b/src/batch-doctrine-dbal/src/DoctrineDBALJobExecutionStorage.php index b7e544f8..18c53ddf 100644 --- a/src/batch-doctrine-dbal/src/DoctrineDBALJobExecutionStorage.php +++ b/src/batch-doctrine-dbal/src/DoctrineDBALJobExecutionStorage.php @@ -23,82 +23,82 @@ final class DoctrineDBALJobExecutionStorage implements QueryableJobExecutionStor /** * @var Connection */ - private $connection; + private Connection $connection; /** * @var string */ - private $table = 'yokai_batch_job_execution'; + private string $table = 'yokai_batch_job_execution'; /** * @var string */ - private $idCol = 'id'; + private string $idCol = 'id'; /** * @var string */ - private $jobNameCol = 'job_name'; + private string $jobNameCol = 'job_name'; /** * @var string */ - private $statusCol = 'status'; + private string $statusCol = 'status'; /** * @var string */ - private $parametersCol = 'parameters'; + private string $parametersCol = 'parameters'; /** * @var string */ - private $startTimeCol = 'start_time'; + private string $startTimeCol = 'start_time'; /** * @var string */ - private $endTimeCol = 'end_time'; + private string $endTimeCol = 'end_time'; /** * @var string */ - private $summaryCol = 'summary'; + private string $summaryCol = 'summary'; /** * @var string */ - private $failuresCol = 'failures'; + private string $failuresCol = 'failures'; /** * @var string */ - private $warningsCol = 'warnings'; + private string $warningsCol = 'warnings'; /** * @var string */ - private $childExecutionsCol = 'child_executions'; + private string $childExecutionsCol = 'child_executions'; /** * @var string */ - private $logsCol = 'logs'; + private string $logsCol = 'logs'; /** * @var array */ - private $types; + private array $types; /** * @var Schema */ - private $schema; + private Schema $schema; /** * @var JobExecutionRowNormalizer|null */ - private $normalizer; + private ?JobExecutionRowNormalizer $normalizer = null; public function __construct(Connection $connection, array $options) { diff --git a/src/batch-doctrine-dbal/src/JobExecutionRowNormalizer.php b/src/batch-doctrine-dbal/src/JobExecutionRowNormalizer.php index 84f01d00..fe58e900 100644 --- a/src/batch-doctrine-dbal/src/JobExecutionRowNormalizer.php +++ b/src/batch-doctrine-dbal/src/JobExecutionRowNormalizer.php @@ -23,62 +23,62 @@ final class JobExecutionRowNormalizer /** * @var string */ - private $idCol = 'id'; + private string $idCol; /** * @var string */ - private $jobNameCol = 'job_name'; + private string $jobNameCol; /** * @var string */ - private $statusCol = 'status'; + private string $statusCol; /** * @var string */ - private $parametersCol = 'parameters'; + private string $parametersCol; /** * @var string */ - private $startTimeCol = 'start_time'; + private string $startTimeCol; /** * @var string */ - private $endTimeCol = 'end_time'; + private string $endTimeCol; /** * @var string */ - private $summaryCol = 'summary'; + private string $summaryCol; /** * @var string */ - private $failuresCol = 'failures'; + private string $failuresCol; /** * @var string */ - private $warningsCol = 'warnings'; + private string $warningsCol; /** * @var string */ - private $childExecutionsCol = 'child_executions'; + private string $childExecutionsCol; /** * @var string */ - private $logsCol; + private string $logsCol; /** * @var string */ - private $dateFormat; + private string $dateFormat; public function __construct( string $idCol, diff --git a/src/batch-doctrine-dbal/tests/DoctrineDBALJobExecutionStorageTest.php b/src/batch-doctrine-dbal/tests/DoctrineDBALJobExecutionStorageTest.php index 42d7ee5b..baf00125 100644 --- a/src/batch-doctrine-dbal/tests/DoctrineDBALJobExecutionStorageTest.php +++ b/src/batch-doctrine-dbal/tests/DoctrineDBALJobExecutionStorageTest.php @@ -35,7 +35,7 @@ class DoctrineDBALJobExecutionStorageTest extends TestCase /** * @var Connection */ - private $connection; + private Connection $connection; protected function setUp(): void { diff --git a/src/batch-doctrine-orm/src/EntityReader.php b/src/batch-doctrine-orm/src/EntityReader.php index c0260343..8b227f82 100644 --- a/src/batch-doctrine-orm/src/EntityReader.php +++ b/src/batch-doctrine-orm/src/EntityReader.php @@ -14,12 +14,12 @@ final class EntityReader implements ItemReaderInterface /** * @var ManagerRegistry */ - private $doctrine; + private ManagerRegistry $doctrine; /** * @var string */ - private $class; + private string $class; public function __construct(ManagerRegistry $doctrine, string $class) { diff --git a/src/batch-doctrine-orm/tests/User.php b/src/batch-doctrine-orm/tests/User.php index 8c2fdd06..b4367937 100644 --- a/src/batch-doctrine-orm/tests/User.php +++ b/src/batch-doctrine-orm/tests/User.php @@ -6,7 +6,7 @@ class User { - public $id; + public string $id; public function __construct(string $id) { diff --git a/src/batch-doctrine-persistence/src/ObjectWriter.php b/src/batch-doctrine-persistence/src/ObjectWriter.php index 14339dfe..4a23c810 100644 --- a/src/batch-doctrine-persistence/src/ObjectWriter.php +++ b/src/batch-doctrine-persistence/src/ObjectWriter.php @@ -14,22 +14,22 @@ final class ObjectWriter implements ItemWriterInterface /** * @var ManagerRegistry */ - private $doctrine; + private ManagerRegistry $doctrine; /** * @var ObjectManager[] */ - private $encounteredManagers = []; + private array $encounteredManagers = []; /** * @var ObjectManager[] */ - private $encounteredClasses = []; + private array $encounteredClasses = []; /** * @var ObjectManager[] */ - private $managerForClass = []; + private array $managerForClass = []; public function __construct(ManagerRegistry $doctrine) { diff --git a/src/batch-doctrine-persistence/tests/Group.php b/src/batch-doctrine-persistence/tests/Group.php index ddf3590a..6a0c8046 100644 --- a/src/batch-doctrine-persistence/tests/Group.php +++ b/src/batch-doctrine-persistence/tests/Group.php @@ -6,7 +6,7 @@ class Group { - public $id; + public string $id; public function __construct(string $id) { diff --git a/src/batch-doctrine-persistence/tests/Product.php b/src/batch-doctrine-persistence/tests/Product.php index 963bc563..d4bdb9f5 100644 --- a/src/batch-doctrine-persistence/tests/Product.php +++ b/src/batch-doctrine-persistence/tests/Product.php @@ -6,7 +6,7 @@ class Product { - public $id; + public string $id; public function __construct(string $id) { diff --git a/src/batch-doctrine-persistence/tests/User.php b/src/batch-doctrine-persistence/tests/User.php index bf7726fa..856c3c4b 100644 --- a/src/batch-doctrine-persistence/tests/User.php +++ b/src/batch-doctrine-persistence/tests/User.php @@ -6,7 +6,7 @@ class User { - public $id; + public string $id; public function __construct(string $id) { diff --git a/src/batch-symfony-console/src/CommandRunner.php b/src/batch-symfony-console/src/CommandRunner.php index 5d7bbc69..9ea4ecd2 100644 --- a/src/batch-symfony-console/src/CommandRunner.php +++ b/src/batch-symfony-console/src/CommandRunner.php @@ -12,17 +12,17 @@ class CommandRunner /** * @var string */ - private $consolePath; + private string $consolePath; /** * @var string */ - private $logDir; + private string $logDir; /** * @var PhpExecutableFinder|null */ - private $phpLocator; + private ?PhpExecutableFinder $phpLocator; public function __construct(string $binDir, string $logDir, PhpExecutableFinder $phpLocator = null) { diff --git a/src/batch-symfony-console/src/RunCommandJobLauncher.php b/src/batch-symfony-console/src/RunCommandJobLauncher.php index af49553e..c0ae698b 100644 --- a/src/batch-symfony-console/src/RunCommandJobLauncher.php +++ b/src/batch-symfony-console/src/RunCommandJobLauncher.php @@ -15,22 +15,22 @@ final class RunCommandJobLauncher implements JobLauncherInterface /** * @var JobExecutionFactory */ - private $jobExecutionFactory; + private JobExecutionFactory $jobExecutionFactory; /** * @var CommandRunner */ - private $commandRunner; + private CommandRunner $commandRunner; /** * @var string */ - private $logFilename; + private string $logFilename; /** * @var JobExecutionStorageInterface */ - private $jobExecutionStorage; + private JobExecutionStorageInterface $jobExecutionStorage; public function __construct( JobExecutionFactory $jobExecutionFactory, diff --git a/src/batch-symfony-console/src/RunJobCommand.php b/src/batch-symfony-console/src/RunJobCommand.php index 7d201c08..ec00f226 100644 --- a/src/batch-symfony-console/src/RunJobCommand.php +++ b/src/batch-symfony-console/src/RunJobCommand.php @@ -22,7 +22,7 @@ final class RunJobCommand extends Command /** * @var JobLauncherInterface */ - private $jobLauncher; + private JobLauncherInterface $jobLauncher; /** * @param JobLauncherInterface $jobLauncher diff --git a/src/batch-symfony-messenger/src/DispatchMessageJobLauncher.php b/src/batch-symfony-messenger/src/DispatchMessageJobLauncher.php index c11fb285..202d2730 100644 --- a/src/batch-symfony-messenger/src/DispatchMessageJobLauncher.php +++ b/src/batch-symfony-messenger/src/DispatchMessageJobLauncher.php @@ -16,17 +16,17 @@ final class DispatchMessageJobLauncher implements JobLauncherInterface /** * @var JobExecutionFactory */ - private $jobExecutionFactory; + private JobExecutionFactory $jobExecutionFactory; /** * @var JobExecutionStorageInterface */ - private $jobExecutionStorage; + private JobExecutionStorageInterface $jobExecutionStorage; /** * @var MessageBusInterface */ - private $messageBus; + private MessageBusInterface $messageBus; public function __construct( JobExecutionFactory $jobExecutionFactory, diff --git a/src/batch-symfony-messenger/src/LaunchJobMessage.php b/src/batch-symfony-messenger/src/LaunchJobMessage.php index be1c23dc..de2cf538 100644 --- a/src/batch-symfony-messenger/src/LaunchJobMessage.php +++ b/src/batch-symfony-messenger/src/LaunchJobMessage.php @@ -9,12 +9,12 @@ final class LaunchJobMessage /** * @var string */ - private $jobName; + private string $jobName; /** * @var array */ - private $configuration; + private array $configuration; public function __construct(string $jobName, array $configuration = []) { diff --git a/src/batch-symfony-messenger/src/LaunchJobMessageHandler.php b/src/batch-symfony-messenger/src/LaunchJobMessageHandler.php index 2a49d8a8..bfed8e1b 100644 --- a/src/batch-symfony-messenger/src/LaunchJobMessageHandler.php +++ b/src/batch-symfony-messenger/src/LaunchJobMessageHandler.php @@ -12,7 +12,7 @@ final class LaunchJobMessageHandler implements MessageHandlerInterface /** * @var JobLauncherInterface */ - private $jobLauncher; + private JobLauncherInterface $jobLauncher; public function __construct(JobLauncherInterface $jobLauncher) { diff --git a/src/batch-symfony-serializer/src/DenormalizeItemProcessor.php b/src/batch-symfony-serializer/src/DenormalizeItemProcessor.php index 358ec60f..48a29d4f 100644 --- a/src/batch-symfony-serializer/src/DenormalizeItemProcessor.php +++ b/src/batch-symfony-serializer/src/DenormalizeItemProcessor.php @@ -14,22 +14,22 @@ final class DenormalizeItemProcessor implements ItemProcessorInterface /** * @var DenormalizerInterface */ - private $denormalizer; + private DenormalizerInterface $denormalizer; /** * @var string */ - private $type; + private string $type; /** * @var string|null */ - private $format; + private ?string $format; /** * @var array */ - private $context; + private array $context; public function __construct( DenormalizerInterface $denormalizer, diff --git a/src/batch-symfony-serializer/src/NormalizeItemProcessor.php b/src/batch-symfony-serializer/src/NormalizeItemProcessor.php index 3a90be3e..4336335d 100644 --- a/src/batch-symfony-serializer/src/NormalizeItemProcessor.php +++ b/src/batch-symfony-serializer/src/NormalizeItemProcessor.php @@ -14,17 +14,17 @@ final class NormalizeItemProcessor implements ItemProcessorInterface /** * @var NormalizerInterface */ - private $normalizer; + private NormalizerInterface $normalizer; /** * @var string|null */ - private $format; + private ?string $format; /** * @var array */ - private $context; + private array $context; public function __construct(NormalizerInterface $normalizer, string $format = null, array $context = []) { diff --git a/src/batch-symfony-validator/src/SkipInvalidItemProcessor.php b/src/batch-symfony-validator/src/SkipInvalidItemProcessor.php index 641b3571..a0acb5c8 100644 --- a/src/batch-symfony-validator/src/SkipInvalidItemProcessor.php +++ b/src/batch-symfony-validator/src/SkipInvalidItemProcessor.php @@ -15,12 +15,12 @@ final class SkipInvalidItemProcessor implements ItemProcessorInterface /** * @var ValidatorInterface */ - private $validator; + private ValidatorInterface $validator; /** * @var array|null */ - private $groups; + private ?array $groups; public function __construct(ValidatorInterface $validator, array $groups = null) { diff --git a/src/batch/docs/domain/job-execution-storage.md b/src/batch/docs/domain/job-execution-storage.md index 4f0ad550..77f1be19 100644 --- a/src/batch/docs/domain/job-execution-storage.md +++ b/src/batch/docs/domain/job-execution-storage.md @@ -9,7 +9,7 @@ use Yokai\Batch\Storage\JobExecutionStorageInterface; class InMemoryJobExecutionStorage implements JobExecutionStorageInterface { - private $memory = []; + private array$memory = []; public function store(JobExecution $execution) : void { diff --git a/src/batch/src/BatchStatus.php b/src/batch/src/BatchStatus.php index 19c71c16..56e7020a 100644 --- a/src/batch/src/BatchStatus.php +++ b/src/batch/src/BatchStatus.php @@ -25,7 +25,7 @@ final class BatchStatus /** * @var int */ - private $value; + private int $value; /** * @param int $value diff --git a/src/batch/src/Event/JobEvent.php b/src/batch/src/Event/JobEvent.php index 243f927b..b646c006 100644 --- a/src/batch/src/Event/JobEvent.php +++ b/src/batch/src/Event/JobEvent.php @@ -11,7 +11,7 @@ class JobEvent /** * @var JobExecution */ - private $execution; + private JobExecution $execution; public function __construct(JobExecution $execution) { diff --git a/src/batch/src/Failure.php b/src/batch/src/Failure.php index 06220a88..d030f40a 100644 --- a/src/batch/src/Failure.php +++ b/src/batch/src/Failure.php @@ -11,27 +11,27 @@ final class Failure /** * @var string */ - private $class; + private string $class; /** * @var string */ - private $message; + private string $message; /** * @var int */ - private $code; + private int $code; /** * @var array */ - private $parameters; + private array $parameters; /** * @var string|null */ - private $trace; + private ?string $trace; /** * @param string $class diff --git a/src/batch/src/Job/Item/InvalidItemException.php b/src/batch/src/Job/Item/InvalidItemException.php index 0d08179d..5e293882 100644 --- a/src/batch/src/Job/Item/InvalidItemException.php +++ b/src/batch/src/Job/Item/InvalidItemException.php @@ -11,7 +11,7 @@ class InvalidItemException extends \RuntimeException /** * @var array */ - private $parameters; + private array $parameters; public function __construct(string $message, array $parameters = [], int $code = 0, Throwable $previous = null) { diff --git a/src/batch/src/Job/Item/ItemJob.php b/src/batch/src/Job/Item/ItemJob.php index 14fa7551..94c3553d 100644 --- a/src/batch/src/Job/Item/ItemJob.php +++ b/src/batch/src/Job/Item/ItemJob.php @@ -16,32 +16,32 @@ class ItemJob extends AbstractJob /** * @var int */ - private $batchSize; + private int $batchSize; /** * @var ItemReaderInterface */ - private $reader; + private ItemReaderInterface $reader; /** * @var ItemProcessorInterface */ - private $processor; + private ItemProcessorInterface $processor; /** * @var ItemWriterInterface */ - private $writer; + private ItemWriterInterface $writer; /** * @var array */ - private $elements; + private array $elements; /** * @var JobExecutionStorageInterface */ - private $executionStorage; + private JobExecutionStorageInterface $executionStorage; /** * @param int $batchSize diff --git a/src/batch/src/Job/Item/Processor/ChainProcessor.php b/src/batch/src/Job/Item/Processor/ChainProcessor.php index bdbcd7de..0e36cf91 100644 --- a/src/batch/src/Job/Item/Processor/ChainProcessor.php +++ b/src/batch/src/Job/Item/Processor/ChainProcessor.php @@ -23,7 +23,7 @@ final class ChainProcessor implements /** * @var iterable|ItemProcessorInterface[] */ - private $processors; + private iterable $processors; /** * @param iterable|ItemProcessorInterface[] $processors diff --git a/src/batch/src/Job/Item/Reader/SequenceReader.php b/src/batch/src/Job/Item/Reader/SequenceReader.php index f26cf8bd..45430ff9 100644 --- a/src/batch/src/Job/Item/Reader/SequenceReader.php +++ b/src/batch/src/Job/Item/Reader/SequenceReader.php @@ -23,7 +23,7 @@ final class SequenceReader implements /** * @var iterable|ItemReaderInterface[] */ - private $readers; + private iterable $readers; /** * @param iterable|ItemReaderInterface[] $readers diff --git a/src/batch/src/Job/Item/Reader/StaticIterableReader.php b/src/batch/src/Job/Item/Reader/StaticIterableReader.php index 6d475522..33290387 100644 --- a/src/batch/src/Job/Item/Reader/StaticIterableReader.php +++ b/src/batch/src/Job/Item/Reader/StaticIterableReader.php @@ -11,7 +11,7 @@ final class StaticIterableReader implements ItemReaderInterface /** * @var iterable */ - private $items; + private iterable $items; public function __construct(iterable $items) { diff --git a/src/batch/src/Job/Item/Writer/ChainWriter.php b/src/batch/src/Job/Item/Writer/ChainWriter.php index ddf551d8..58adeaeb 100644 --- a/src/batch/src/Job/Item/Writer/ChainWriter.php +++ b/src/batch/src/Job/Item/Writer/ChainWriter.php @@ -23,7 +23,7 @@ final class ChainWriter implements /** * @var iterable|ItemWriterInterface[] */ - private $writers; + private iterable $writers; /** * @param iterable|ItemWriterInterface[] $writers diff --git a/src/batch/src/Job/JobExecutionAwareTrait.php b/src/batch/src/Job/JobExecutionAwareTrait.php index 03aa4db2..171106cc 100644 --- a/src/batch/src/Job/JobExecutionAwareTrait.php +++ b/src/batch/src/Job/JobExecutionAwareTrait.php @@ -11,7 +11,7 @@ trait JobExecutionAwareTrait /** * @var JobExecution */ - private $jobExecution; + private JobExecution $jobExecution; public function setJobExecution(JobExecution $jobExecution): void { diff --git a/src/batch/src/Job/JobParametersAwareTrait.php b/src/batch/src/Job/JobParametersAwareTrait.php index 4fb21818..6fbedbd5 100644 --- a/src/batch/src/Job/JobParametersAwareTrait.php +++ b/src/batch/src/Job/JobParametersAwareTrait.php @@ -11,7 +11,7 @@ trait JobParametersAwareTrait /** * @var JobParameters */ - private $jobParameters; + private JobParameters $jobParameters; /** * @param JobParameters $jobParameters diff --git a/src/batch/src/Job/JobWithChildJobs.php b/src/batch/src/Job/JobWithChildJobs.php index a7c34d5f..048580bf 100644 --- a/src/batch/src/Job/JobWithChildJobs.php +++ b/src/batch/src/Job/JobWithChildJobs.php @@ -14,17 +14,17 @@ final class JobWithChildJobs extends AbstractJob /** * @var JobExecutionStorageInterface */ - private $executionStorage; + private JobExecutionStorageInterface $executionStorage; /** * @var JobRegistry */ - private $jobRegistry; + private JobRegistry $jobRegistry; /** * @var iterable|string[] */ - private $childJobs; + private iterable $childJobs; /** * @param JobExecutionStorageInterface $executionStorage diff --git a/src/batch/src/Job/SummaryAwareTrait.php b/src/batch/src/Job/SummaryAwareTrait.php index ec4df4cb..bf7d2f37 100644 --- a/src/batch/src/Job/SummaryAwareTrait.php +++ b/src/batch/src/Job/SummaryAwareTrait.php @@ -11,7 +11,7 @@ trait SummaryAwareTrait /** * @var Summary */ - private $summary; + private Summary $summary; /** * @param Summary $summary diff --git a/src/batch/src/JobExecution.php b/src/batch/src/JobExecution.php index d23cc426..17988c50 100644 --- a/src/batch/src/JobExecution.php +++ b/src/batch/src/JobExecution.php @@ -16,67 +16,67 @@ final class JobExecution /** * @var string */ - private $id; + private string $id; /** * @var string */ - private $jobName; + private string $jobName; /** * @var BatchStatus */ - private $status; + private BatchStatus $status; /** * @var DateTimeInterface|null */ - private $startTime; + private ?DateTimeInterface $startTime = null; /** * @var DateTimeInterface|null */ - private $endTime; + private ?DateTimeInterface $endTime = null; /** * @var Failure[] */ - private $failures = []; + private array $failures = []; /** * @var Warning[] */ - private $warnings = []; + private array $warnings = []; /** * @var Summary */ - private $summary; + private Summary $summary; /** * @var JobParameters */ - private $parameters; + private JobParameters $parameters; /** * @var null|JobExecution */ - private $parentExecution; + private ?JobExecution $parentExecution; /** * @var JobExecution[] */ - private $childExecutions = []; + private array $childExecutions = []; /** * @var JobExecutionLogs */ - private $logs; + private JobExecutionLogs $logs; /** * @var LoggerInterface */ - private $logger; + private LoggerInterface $logger; /** * @param null|JobExecution $parentExecution diff --git a/src/batch/src/JobExecutionLogger.php b/src/batch/src/JobExecutionLogger.php index 8deca8fa..2290f368 100644 --- a/src/batch/src/JobExecutionLogger.php +++ b/src/batch/src/JobExecutionLogger.php @@ -25,12 +25,12 @@ final class JobExecutionLogger extends AbstractLogger /** * @var DateTimeZone|null */ - private static $timezone; + private static ?DateTimeZone $timezone = null; /** * @var JobExecutionLogs */ - private $logs; + private JobExecutionLogs $logs; public function __construct(JobExecutionLogs $logs) { @@ -55,12 +55,10 @@ public function log($level, $message, array $context = []): void private function date(): string { - if (!static::$timezone) { - static::$timezone = new DateTimeZone(date_default_timezone_get() ?: 'UTC'); - } + self::$timezone ??= new DateTimeZone(date_default_timezone_get() ?: 'UTC'); - $date = new DateTime('now', static::$timezone); - $date->setTimezone(static::$timezone); + $date = new DateTime('now', self::$timezone); + $date->setTimezone(self::$timezone); return $date->format('Y-m-d H:i:s'); } diff --git a/src/batch/src/JobExecutionLogs.php b/src/batch/src/JobExecutionLogs.php index 390ef7e4..5df059d6 100644 --- a/src/batch/src/JobExecutionLogs.php +++ b/src/batch/src/JobExecutionLogs.php @@ -9,7 +9,7 @@ final class JobExecutionLogs /** * @var string */ - private $logs; + private string $logs; public function __construct(string $logs = '') { diff --git a/src/batch/src/JobParameters.php b/src/batch/src/JobParameters.php index 1711d0c0..19243e3c 100644 --- a/src/batch/src/JobParameters.php +++ b/src/batch/src/JobParameters.php @@ -17,7 +17,7 @@ final class JobParameters implements /** * @var array */ - private $parameters; + private array $parameters; /** * @param array $parameters diff --git a/src/batch/src/Launcher/SimpleJobLauncher.php b/src/batch/src/Launcher/SimpleJobLauncher.php index 2b7e3bc2..e96ce641 100644 --- a/src/batch/src/Launcher/SimpleJobLauncher.php +++ b/src/batch/src/Launcher/SimpleJobLauncher.php @@ -21,22 +21,22 @@ class SimpleJobLauncher implements JobLauncherInterface /** * @var JobRegistry */ - private $jobRegistry; + private JobRegistry $jobRegistry; /** * @var JobExecutionFactory */ - private $jobExecutionFactory; + private JobExecutionFactory $jobExecutionFactory; /** * @var JobExecutionStorageInterface */ - private $jobExecutionStorage; + private JobExecutionStorageInterface $jobExecutionStorage; /** * @var EventDispatcherInterface|null */ - private $eventDispatcher; + private ?EventDispatcherInterface $eventDispatcher; /** * @param JobRegistry $jobRegistry diff --git a/src/batch/src/Registry/JobRegistry.php b/src/batch/src/Registry/JobRegistry.php index 35b087a8..9134b933 100644 --- a/src/batch/src/Registry/JobRegistry.php +++ b/src/batch/src/Registry/JobRegistry.php @@ -13,7 +13,7 @@ final class JobRegistry /** * @var ContainerInterface */ - private $jobs; + private ContainerInterface $jobs; /** * @param ContainerInterface $jobs diff --git a/src/batch/src/Storage/FilesystemJobExecutionStorage.php b/src/batch/src/Storage/FilesystemJobExecutionStorage.php index 9b29f6ff..b8d14bee 100644 --- a/src/batch/src/Storage/FilesystemJobExecutionStorage.php +++ b/src/batch/src/Storage/FilesystemJobExecutionStorage.php @@ -17,12 +17,12 @@ final class FilesystemJobExecutionStorage implements QueryableJobExecutionStorag /** * @var JobExecutionSerializerInterface */ - private $serializer; + private JobExecutionSerializerInterface $serializer; /** * @var string */ - private $directory; + private string $directory; /** * @param JobExecutionSerializerInterface $serializer diff --git a/src/batch/src/Storage/Query.php b/src/batch/src/Storage/Query.php index a064d660..bfda649d 100644 --- a/src/batch/src/Storage/Query.php +++ b/src/batch/src/Storage/Query.php @@ -14,32 +14,32 @@ final class Query /** * @var string[] */ - private $jobNames; + private array $jobNames; /** * @var string[] */ - private $ids; + private array $ids; /** * @var int[] */ - private $statuses; + private array $statuses; /** * @var string|null */ - private $sortBy; + private ?string $sortBy; /** * @var int */ - private $limit; + private int $limit; /** * @var int */ - private $offset; + private int $offset; /** * @internal diff --git a/src/batch/src/Storage/QueryBuilder.php b/src/batch/src/Storage/QueryBuilder.php index a4eb38bf..91f027cd 100644 --- a/src/batch/src/Storage/QueryBuilder.php +++ b/src/batch/src/Storage/QueryBuilder.php @@ -28,32 +28,32 @@ final class QueryBuilder /** * @var string[] */ - private $jobNames = []; + private array $jobNames = []; /** * @var string[] */ - private $ids = []; + private array $ids = []; /** * @var int[] */ - private $statuses = []; + private array $statuses = []; /** * @var string|null */ - private $sortBy = null; + private ?string $sortBy = null; /** * @var int */ - private $limit = 10; + private int $limit = 10; /** * @var int */ - private $offset = 0; + private int $offset = 0; public function jobs(array $names): self { diff --git a/src/batch/src/Summary.php b/src/batch/src/Summary.php index cd27effc..2f77fc1c 100644 --- a/src/batch/src/Summary.php +++ b/src/batch/src/Summary.php @@ -15,7 +15,7 @@ final class Summary implements /** * @var array */ - private $values = []; + private array $values; /** * @param array $values diff --git a/src/batch/src/Warning.php b/src/batch/src/Warning.php index f4b9f020..284d0f40 100644 --- a/src/batch/src/Warning.php +++ b/src/batch/src/Warning.php @@ -9,17 +9,17 @@ final class Warning /** * @var string */ - private $message; + private string $message; /** * @var array */ - private $parameters; + private array $parameters; /** * @var array */ - private $context; + private array $context; public function __construct(string $message, array $parameters = [], array $context = []) { diff --git a/src/batch/tests/Job/Item/Reader/StaticIterableReaderTest.php b/src/batch/tests/Job/Item/Reader/StaticIterableReaderTest.php index dd090169..3d115bb7 100644 --- a/src/batch/tests/Job/Item/Reader/StaticIterableReaderTest.php +++ b/src/batch/tests/Job/Item/Reader/StaticIterableReaderTest.php @@ -32,7 +32,7 @@ public function items(): \Iterator /** * @var array */ - private $items; + private array $items; public function __construct(array $items) { From bf2f9feed96f972794b2ae6ab1f67d360500175e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20Eugon=C3=A9?= Date: Fri, 18 Dec 2020 18:51:59 +0100 Subject: [PATCH 2/2] PHP 7.4 arrow function & static closures --- .../src/DoctrineDBALJobExecutionStorage.php | 2 +- .../tests/RunCommandJobLauncherTest.php | 2 +- .../tests/DispatchMessageJobLauncherTest.php | 4 ++-- src/batch/src/Factory/JobExecutionFactory.php | 2 +- .../Serializer/JsonJobExecutionSerializer.php | 4 ++-- .../Storage/FilesystemJobExecutionStorage.php | 2 +- src/batch/tests/Job/Item/ItemJobTest.php | 5 +++-- .../Job/Item/Processor/ChainProcessorTest.php | 12 +++--------- src/batch/tests/JobExecutionTest.php | 16 ++++------------ .../tests/Launcher/SimpleJobLauncherTest.php | 4 ++-- 10 files changed, 20 insertions(+), 33 deletions(-) diff --git a/src/batch-doctrine-dbal/src/DoctrineDBALJobExecutionStorage.php b/src/batch-doctrine-dbal/src/DoctrineDBALJobExecutionStorage.php index 18c53ddf..410c0ccc 100644 --- a/src/batch-doctrine-dbal/src/DoctrineDBALJobExecutionStorage.php +++ b/src/batch-doctrine-dbal/src/DoctrineDBALJobExecutionStorage.php @@ -165,7 +165,7 @@ public function createSchemaSql(): array $config = $this->connection->getConfiguration(); $previousFilter = $config->getSchemaAssetsFilter(); - $config->setSchemaAssetsFilter(function ($asset) use ($previousFilter, $toSchema): bool { + $config->setSchemaAssetsFilter(static function ($asset) use ($previousFilter, $toSchema): bool { $assetName = $asset instanceof AbstractAsset ? $asset->getName() : $asset; return $toSchema->hasTable($assetName) diff --git a/src/batch-symfony-console/tests/RunCommandJobLauncherTest.php b/src/batch-symfony-console/tests/RunCommandJobLauncherTest.php index a78e97db..f2a24486 100644 --- a/src/batch-symfony-console/tests/RunCommandJobLauncherTest.php +++ b/src/batch-symfony-console/tests/RunCommandJobLauncherTest.php @@ -34,7 +34,7 @@ public function testLaunch(): void $storage = $this->prophesize(JobExecutionStorageInterface::class); $jobExecutionAssertions = Argument::that( - function ($jobExecution): bool { + static function ($jobExecution): bool { return $jobExecution instanceof JobExecution && $jobExecution->getJobName() === 'testing' && $jobExecution->getId() === '123456789' diff --git a/src/batch-symfony-messenger/tests/DispatchMessageJobLauncherTest.php b/src/batch-symfony-messenger/tests/DispatchMessageJobLauncherTest.php index cb00db85..00c71a2c 100644 --- a/src/batch-symfony-messenger/tests/DispatchMessageJobLauncherTest.php +++ b/src/batch-symfony-messenger/tests/DispatchMessageJobLauncherTest.php @@ -26,7 +26,7 @@ public function testLaunch(): void { $storage = $this->prophesize(JobExecutionStorageInterface::class); $jobExecutionAssertions = Argument::that( - function ($jobExecution): bool { + static function ($jobExecution): bool { return $jobExecution instanceof JobExecution && $jobExecution->getJobName() === 'testing' && $jobExecution->getId() === '123456789' @@ -42,7 +42,7 @@ function ($jobExecution): bool { $messageBus = $this->prophesize(MessageBusInterface::class); $messageAssertions = Argument::that( - function ($message): bool { + static function ($message): bool { return $message instanceof LaunchJobMessage && $message->getJobName() === 'testing' && $message->getConfiguration() === ['_id' => '123456789', 'foo' => ['bar']]; diff --git a/src/batch/src/Factory/JobExecutionFactory.php b/src/batch/src/Factory/JobExecutionFactory.php index e096aa31..1e7f7d8a 100644 --- a/src/batch/src/Factory/JobExecutionFactory.php +++ b/src/batch/src/Factory/JobExecutionFactory.php @@ -30,7 +30,7 @@ public function __construct(JobExecutionIdGeneratorInterface $idGenerator) */ public function create(string $name, array $configuration = []): JobExecution { - $configuration['_id'] = $configuration['_id'] ?? $this->idGenerator->generate(); + $configuration['_id'] ??= $this->idGenerator->generate(); return JobExecution::createRoot($configuration['_id'], $name, null, new JobParameters($configuration)); } diff --git a/src/batch/src/Serializer/JsonJobExecutionSerializer.php b/src/batch/src/Serializer/JsonJobExecutionSerializer.php index 0a175c14..8d8444bd 100644 --- a/src/batch/src/Serializer/JsonJobExecutionSerializer.php +++ b/src/batch/src/Serializer/JsonJobExecutionSerializer.php @@ -129,7 +129,7 @@ private function fromArray(array $jobExecutionData, JobExecution $parentExecutio private function dateToString(?DateTimeInterface $date): ?string { if ($date === null) { - return $date; + return null; } return $date->format(DateTimeInterface::ISO8601); @@ -138,7 +138,7 @@ private function dateToString(?DateTimeInterface $date): ?string private function stringToDate(?string $date): ?DateTimeInterface { if ($date === null) { - return $date; + return null; } $dateObject = DateTimeImmutable::createFromFormat(DateTimeInterface::ISO8601, $date); diff --git a/src/batch/src/Storage/FilesystemJobExecutionStorage.php b/src/batch/src/Storage/FilesystemJobExecutionStorage.php index b8d14bee..bb887326 100644 --- a/src/batch/src/Storage/FilesystemJobExecutionStorage.php +++ b/src/batch/src/Storage/FilesystemJobExecutionStorage.php @@ -133,7 +133,7 @@ public function query(Query $query): iterable $order = null; switch ($query->sort()) { case Query::SORT_BY_START_ASC: - $order = function (JobExecution $left, JobExecution $right): int { + $order = static function (JobExecution $left, JobExecution $right): int { return $left->getStartTime() <=> $right->getStartTime(); }; break; diff --git a/src/batch/tests/Job/Item/ItemJobTest.php b/src/batch/tests/Job/Item/ItemJobTest.php index c380f3ca..9317e662 100644 --- a/src/batch/tests/Job/Item/ItemJobTest.php +++ b/src/batch/tests/Job/Item/ItemJobTest.php @@ -4,6 +4,7 @@ namespace Yokai\Batch\Tests\Job\Item; +use Generator; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; @@ -39,7 +40,7 @@ public function testExecute(): void $this->configureItemElement($reader, 'reader', $log); $reader->read() ->shouldBeCalledTimes(1) - ->will(function () { + ->will(function (): Generator { yield from [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]; }); @@ -48,7 +49,7 @@ public function testExecute(): void $this->configureItemElement($processor, 'processor', $log); $processor->process(Argument::type('int')) ->shouldBeCalledTimes(12) - ->will(function (array $args) { + ->will(function (array $args): int { if ($args[0] > 9) { throw new InvalidItemException('Item is greater than 9 got {value}', ['{value}' => $args[0]]); } diff --git a/src/batch/tests/Job/Item/Processor/ChainProcessorTest.php b/src/batch/tests/Job/Item/Processor/ChainProcessorTest.php index 20465fa3..34be2f43 100644 --- a/src/batch/tests/Job/Item/Processor/ChainProcessorTest.php +++ b/src/batch/tests/Job/Item/Processor/ChainProcessorTest.php @@ -32,17 +32,13 @@ public function testProcess(): void $subtract1Processor = $this->prophesize(ItemProcessorInterface::class); $subtract1Processor->process(Argument::type('int')) ->shouldBeCalled() - ->will(function (array $args): int { - return $args[0] - 1; - }); + ->will(fn(array $args): int => $args[0] - 1); /** @var ObjectProphecy|ItemProcessorInterface $multiplyBy2Processor */ $multiplyBy2Processor = $this->prophesize(ItemProcessorInterface::class); $multiplyBy2Processor->process(Argument::type('int')) ->shouldBeCalled() - ->will(function (array $args): int { - return $args[0] * 2; - }); + ->will(fn(array $args): int => $args[0] * 2); /** @var ObjectProphecy|ItemProcessorInterface|JobExecutionAwareInterface|JobParametersAwareInterface|SummaryAwareInterface|InitializableInterface|FlushableInterface $add10Processor */ $add10Processor = $this->prophesize(ItemProcessorInterface::class); @@ -68,9 +64,7 @@ public function testProcess(): void ->will(Util::createVarLogger('flush', $log)); $add10Processor->process(Argument::type('int')) ->shouldBeCalled() - ->will(function (array $args): int { - return $args[0] + 10; - }); + ->will(fn(array $args): int => $args[0] + 10); $processor = new ChainProcessor( [$subtract1Processor->reveal(), $multiplyBy2Processor->reveal(), $add10Processor->reveal()] diff --git a/src/batch/tests/JobExecutionTest.php b/src/batch/tests/JobExecutionTest.php index 457d5b56..ea25bf07 100644 --- a/src/batch/tests/JobExecutionTest.php +++ b/src/batch/tests/JobExecutionTest.php @@ -134,12 +134,8 @@ public function testChangeStatus(): void public function testManipulatesFailures() { - $failureMessage = function (Failure $failure): string { - return $failure->getMessage(); - }; - $failureToString = function (Failure $failure): string { - return (string)$failure; - }; + $failureMessage = fn(Failure $failure): string => $failure->getMessage(); + $failureToString = fn(Failure $failure): string => (string)$failure; $jobExecution = JobExecution::createRoot('123456789', 'export'); self::assertSame([], array_map($failureMessage, $jobExecution->getFailures())); @@ -166,12 +162,8 @@ public function testManipulatesFailures() public function testManipulatesWarnings() { - $warningMessage = function (Warning $warning): string { - return $warning->getMessage(); - }; - $warningToString = function (Warning $warning): string { - return (string)$warning; - }; + $warningMessage = fn(Warning $warning): string => $warning->getMessage(); + $warningToString = fn(Warning $warning): string => (string)$warning; $jobExecution = JobExecution::createRoot('123456789', 'export'); self::assertSame([], array_map($warningMessage, $jobExecution->getWarnings())); diff --git a/src/batch/tests/Launcher/SimpleJobLauncherTest.php b/src/batch/tests/Launcher/SimpleJobLauncherTest.php index 0605cbc8..74865394 100644 --- a/src/batch/tests/Launcher/SimpleJobLauncherTest.php +++ b/src/batch/tests/Launcher/SimpleJobLauncherTest.php @@ -31,7 +31,7 @@ public function testLaunch(): void $job = $this->prophesize(JobInterface::class); $job->execute($jobExecutionAssertions) ->shouldBeCalledTimes(1) - ->will(function (array $args) { + ->will(function (array $args): void { /** @var JobExecution $execution */ $execution = $args[0]; $execution->setStartTime(new \DateTime()); @@ -91,7 +91,7 @@ public function testLaunchJobCatchFatal(): void $job = $this->prophesize(JobInterface::class); $job->execute($jobExecutionAssertions) ->shouldBeCalledTimes(1) - ->will(function () { + ->will(function (): void { $var = 10 / 0; });