Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
parameters:
level: max
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
paths:
- src/batch/src/
- src/batch-box-spout/src/
Expand Down
8 changes: 6 additions & 2 deletions src/batch-box-spout/src/FlatFileReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class FlatFileReader implements
private string $type;

/**
* @var array
* @phpstan-var array{delimiter?: string, enclosure?: string}
*/
private array $options;

Expand All @@ -48,7 +48,7 @@ final class FlatFileReader implements
private string $headersMode;

/**
* @var array|null
* @phpstan-var list<string>|null
*/
private ?array $headers;

Expand All @@ -57,6 +57,10 @@ final class FlatFileReader implements
*/
private ?string $filePath;

/**
* @phpstan-param array{delimiter?: string, enclosure?: string} $options
* @phpstan-param list<string>|null $headers
*/
public function __construct(
string $type,
array $options = [],
Expand Down
8 changes: 6 additions & 2 deletions src/batch-box-spout/src/FlatFileWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class FlatFileWriter implements
private string $type;

/**
* @var array|null
* @phpstan-var list<string>|null
*/
private ?array $headers;

Expand All @@ -53,10 +53,14 @@ final class FlatFileWriter implements
private ?string $filePath;

/**
* @var array
* @phpstan-var array{delimiter?: string, enclosure?: string}
*/
private array $options;

/**
* @phpstan-param list<string>|null $headers
* @phpstan-param array{delimiter?: string, enclosure?: string} $options
*/
public function __construct(string $type, array $headers = null, string $filePath = null, array $options = [])
{
$this->type = $type;
Expand Down
34 changes: 27 additions & 7 deletions src/batch-doctrine-dbal/src/DoctrineDBALJobExecutionStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Persistence\ConnectionRegistry;
use Generator;
use Yokai\Batch\Exception\CannotStoreJobExecutionException;
use Yokai\Batch\Exception\JobExecutionNotFoundException;
use Yokai\Batch\Exception\RuntimeException;
Expand All @@ -36,11 +37,11 @@ final class DoctrineDBALJobExecutionStorage implements QueryableJobExecutionStor
*/
private string $table;

private JobExecutionRowNormalizer $normalizer;

/**
* @var JobExecutionRowNormalizer|null
* @phpstan-param array{connection?: string, table?: string} $options
*/
private ?JobExecutionRowNormalizer $normalizer = null;

public function __construct(ConnectionRegistry $doctrine, array $options)
{
$options = array_filter($options) + self::DEFAULT_OPTIONS;
Expand Down Expand Up @@ -230,6 +231,9 @@ private function getSchema(): Schema
return $schema;
}

/**
* @phpstan-return array<string, string>
*/
private function types(): array
{
return [
Expand All @@ -247,6 +251,9 @@ private function types(): array
];
}

/**
* @phpstan-return array<string, string>
*/
private function identity(JobExecution $execution): array
{
return [
Expand All @@ -255,6 +262,9 @@ private function identity(JobExecution $execution): array
];
}

/**
* @phpstan-return array<string, string>
*/
private function fetchRow(string $jobName, string $id): array
{
$qb = $this->connection->createQueryBuilder();
Expand Down Expand Up @@ -289,7 +299,13 @@ private function fetchRow(string $jobName, string $id): array
}
}

private function queryList(string $query, array $parameters, array $types): iterable
/**
* @phpstan-param array<string, mixed> $parameters
* @phpstan-param array<string, int|string> $types
*
* @phpstan-return Generator<JobExecution>
*/
private function queryList(string $query, array $parameters, array $types): Generator
{
/** @var Result $statement */
$statement = $this->connection->executeQuery($query, $parameters, $types);
Expand All @@ -301,21 +317,25 @@ private function queryList(string $query, array $parameters, array $types): iter
$statement->free();
}

/**
* @phpstan-return array<string, mixed>
*/
private function toRow(JobExecution $jobExecution): array
{
return $this->getNormalizer()->toRow($jobExecution);
}

/**
* @phpstan-param array<string, mixed> $row
*/
private function fromRow(array $row): JobExecution
{
return $this->getNormalizer()->fromRow($row);
}

private function getNormalizer(): JobExecutionRowNormalizer
{
if ($this->normalizer === null) {
$this->normalizer = new JobExecutionRowNormalizer($this->connection->getDatabasePlatform());
}
$this->normalizer ??= new JobExecutionRowNormalizer($this->connection->getDatabasePlatform());

return $this->normalizer;
}
Expand Down
1 change: 1 addition & 0 deletions src/batch-doctrine-dbal/src/DoctrineDBALQueryReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function __construct(ConnectionRegistry $doctrine, string $sql, string $c

/**
* @inheritdoc
* @phpstan-return Generator<array<string, string>>
*/
public function read(): Generator
{
Expand Down
24 changes: 24 additions & 0 deletions src/batch-doctrine-dbal/src/JobExecutionRowNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public function __construct(AbstractPlatform $platform)
$this->platform = $platform;
}

/**
* @phpstan-return array<string, mixed>
*/
public function toRow(JobExecution $jobExecution): array
{
return [
Expand All @@ -48,6 +51,9 @@ public function toRow(JobExecution $jobExecution): array
];
}

/**
* @phpstan-param array<string, mixed> $data
*/
public function fromRow(array $data, JobExecution $parent = null): JobExecution
{
$data['status'] = intval($data['status']);
Expand Down Expand Up @@ -93,6 +99,9 @@ public function fromRow(array $data, JobExecution $parent = null): JobExecution
return $jobExecution;
}

/**
* @phpstan-return array<string, mixed>
*/
public function toChildRow(JobExecution $jobExecution): array
{
return [
Expand All @@ -112,6 +121,9 @@ public function toChildRow(JobExecution $jobExecution): array
* @param array|string $value
*
* @return array
*
* @phpstan-param array<int|string, mixed>|string $value
* @phpstan-return array<int|string, mixed>
*/
private function jsonFromString($value): array
{
Expand All @@ -135,6 +147,9 @@ private function dateFromString(?string $date): ?DateTimeImmutable
return DateTimeImmutable::createFromFormat($this->platform->getDateTimeFormatString(), $date) ?: null;
}

/**
* @phpstan-return array<string, mixed>
*/
private function failureToArray(Failure $failure): array
{
return [
Expand All @@ -146,6 +161,9 @@ private function failureToArray(Failure $failure): array
];
}

/**
* @phpstan-param array<string, mixed> $array
*/
private function failureFromArray(array $array): Failure
{
return new Failure(
Expand All @@ -157,6 +175,9 @@ private function failureFromArray(array $array): Failure
);
}

/**
* @phpstan-return array<string, mixed>
*/
private function warningToArray(Warning $warning): array
{
return [
Expand All @@ -166,6 +187,9 @@ private function warningToArray(Warning $warning): array
];
}

/**
* @phpstan-param array<string, mixed> $array
*/
private function warningFromArray(array $array): Warning
{
return new Warning($array['message'], $array['parameters'], $array['context']);
Expand Down
10 changes: 5 additions & 5 deletions src/batch-symfony-console/src/CommandRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,15 @@ public function __construct(string $binDir, string $logDir, PhpExecutableFinder
}

/**
* @param string $commandName
* @param array $arguments
* @phpstan-param array<string, mixed> $arguments
*/
public function run(string $commandName, array $arguments = []): void
{
$this->exec($this->buildCommand($commandName, $arguments));
}

/**
* @param string $commandName
* @param string $logFilename
* @param array $arguments
* @phpstan-param array<string, mixed> $arguments
*/
public function runAsync(string $commandName, string $logFilename, array $arguments = []): void
{
Expand All @@ -64,6 +61,9 @@ protected function exec(string $command): void
exec($command);
}

/**
* @phpstan-param array<string, mixed> $arguments
*/
private function buildCommand(string $commandName, array $arguments): string
{
return sprintf(
Expand Down
12 changes: 7 additions & 5 deletions src/batch-symfony-console/src/RunJobCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

final class RunJobCommand extends Command
{
protected static $defaultName = 'yokai:batch:run';

public const EXIT_SUCCESS_CODE = 0;
public const EXIT_ERROR_CODE = 1;
public const EXIT_WARNING_CODE = 2;
Expand All @@ -29,7 +31,7 @@ final class RunJobCommand extends Command
*/
public function __construct(JobLauncherInterface $jobLauncher)
{
parent::__construct(null);
parent::__construct();
$this->jobLauncher = $jobLauncher;
}

Expand All @@ -38,10 +40,8 @@ public function __construct(JobLauncherInterface $jobLauncher)
*/
protected function configure(): void
{
$this
->setName('yokai:batch:run')
->addArgument('job', InputArgument::REQUIRED)
->addArgument('configuration', InputArgument::OPTIONAL);
$this->addArgument('job', InputArgument::REQUIRED);
$this->addArgument('configuration', InputArgument::OPTIONAL);
}

/**
Expand Down Expand Up @@ -118,6 +118,8 @@ private function outputExecution(JobExecution $jobExecution, OutputInterface $ou
*
* @throws InvalidArgumentException
* @return array
*
* @phpstan-return array<string, mixed>
*/
private function decodeConfiguration(string $data): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ final class YokaiBatchExtension extends Extension
{
/**
* @inheritDoc
* @phpstan-param list<array<string, mixed>> $configs
*/
public function load(array $configs, ContainerBuilder $container): void
{
Expand Down Expand Up @@ -79,6 +80,9 @@ private function getLoader(ContainerBuilder $container): ConfigLoader\LoaderInte
return new ConfigLoader\DelegatingLoader($resolver);
}

/**
* @param array<string, mixed> $config
*/
private function configureStorage(ContainerBuilder $container, array $config): void
{
if (isset($config['service'])) {
Expand Down
8 changes: 7 additions & 1 deletion src/batch-symfony-messenger/src/LaunchJobMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ final class LaunchJobMessage
private string $jobName;

/**
* @var array
* @phpstan-var array<string, mixed>
*/
private array $configuration;

/**
* @phpstan-param array<string, mixed> $configuration
*/
public function __construct(string $jobName, array $configuration = [])
{
$this->jobName = $jobName;
Expand All @@ -27,6 +30,9 @@ public function getJobName(): string
return $this->jobName;
}

/**
* @phpstan-return array<string, mixed>
*/
public function getConfiguration(): array
{
return $this->configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ final class DenormalizeItemProcessor implements ItemProcessorInterface
private ?string $format;

/**
* @var array
* @phpstan-var array<string, mixed>
*/
private array $context;

/**
* @phpstan-param array<string, mixed> $context
*/
public function __construct(
DenormalizerInterface $denormalizer,
string $type,
Expand Down
5 changes: 4 additions & 1 deletion src/batch-symfony-serializer/src/NormalizeItemProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ final class NormalizeItemProcessor implements ItemProcessorInterface
private ?string $format;

/**
* @var array
* @phpstan-var array<string, mixed>
*/
private array $context;

/**
* @phpstan-param array<string, mixed> $context
*/
public function __construct(NormalizerInterface $normalizer, string $format = null, array $context = [])
{
$this->normalizer = $normalizer;
Expand Down
Loading