Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): static analysis improved #252

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
5 changes: 5 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@
'no_trailing_comma_in_singleline_array' => true,
'no_unused_imports' => true,
'no_useless_return' => true,
'ordered_imports' => true,
'return_assignment' => true,
'semicolon_after_instruction' => true,
'short_scalar_cast' => true,
'simplified_null_return' => true,
'single_line_throw' => true,
'static_lambda' => true,
'strict_comparison' => true,
'strict_param' => true,
'ternary_to_null_coalescing' => true,
'use_arrow_functions' => true,
'void_return' => true,
'yoda_style' => true,
])->setFinder($finder);
26 changes: 14 additions & 12 deletions src/Bridge/Doctrine/Transport/Configuration/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

namespace SchedulerBundle\Bridge\Doctrine\Transport\Configuration;

use function array_map;
use function array_walk;

use Closure;
use Doctrine\DBAL\Connection as DbalConnection;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Result;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Query\Expr;
Expand All @@ -17,12 +21,10 @@
use SchedulerBundle\Exception\LogicException;
use SchedulerBundle\Exception\RuntimeException;
use SchedulerBundle\Exception\TransportException;

use SchedulerBundle\Transport\Configuration\ExternalConnectionInterface;
use Throwable;

use function array_map;
use function array_walk;

/**
* @author Guillaume Loulier <contact@guillaumeloulier.fr>
*/
Expand All @@ -34,7 +36,7 @@ public function __construct(
private DbalConnection $connection,
private bool $autoSetup
) {
parent::__construct($connection);
parent::__construct(driverConnection: $connection);
}

/**
Expand Down Expand Up @@ -285,7 +287,7 @@ public function toArray(): array
$statement = $this->executeQuery($queryBuilder->getSQL());

$keys = $statement->fetchAllAssociative();
if (!$keys) {
if ([] === $keys) {
throw new RuntimeException('No result found');
}

Expand All @@ -310,7 +312,7 @@ public function count(): int
$statement = $this->executeQuery($queryBuilder->getSQL());
$result = $statement->fetchAssociative();

if (!$result) {
if (false === $result || [] === $result) {
throw new RuntimeException('No result found');
}

Expand Down Expand Up @@ -345,10 +347,10 @@ protected function addTableToSchema(Schema $schema): void
/**
* {@inheritdoc}
*/
protected function executeQuery(string $sql, array $parameters = [], array $types = [])
protected function executeQuery(string $sql, array $parameters = [], array $types = []): Result
{
try {
return $this->connection->executeQuery($sql, $parameters, $types);
return $this->connection->executeQuery(sql: $sql, params: $parameters, types: $types);
} catch (Throwable $throwable) {
if ($this->connection->isTransactionActive()) {
throw $throwable;
Expand All @@ -358,7 +360,7 @@ protected function executeQuery(string $sql, array $parameters = [], array $type
$this->setup();
}

return $this->connection->executeQuery($sql, $parameters, $types);
return $this->connection->executeQuery(sql: $sql, params: $parameters, types: $types);
}
}

Expand All @@ -371,11 +373,11 @@ public function configureSchema(Schema $schema, DBALConnection $dbalConnection):
return;
}

if ($schema->hasTable(self::TABLE_NAME)) {
if ($schema->hasTable(name: self::TABLE_NAME)) {
return;
}

$this->addTableToSchema($schema);
$this->addTableToSchema(schema: $schema);
}

/**
Expand All @@ -387,7 +389,7 @@ private function setup(): void
$schemaAssetsFilter = $configuration->getSchemaAssetsFilter();
$configuration->setSchemaAssetsFilter();
$this->updateSchema();
$configuration->setSchemaAssetsFilter($schemaAssetsFilter);
$configuration->setSchemaAssetsFilter(callable: $schemaAssetsFilter);

$this->autoSetup = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
use SchedulerBundle\Exception\InvalidArgumentException;
use SchedulerBundle\Transport\Configuration\ConfigurationFactoryInterface;
use SchedulerBundle\Transport\Dsn;
use Symfony\Component\Serializer\SerializerInterface;

use function sprintf;

use Symfony\Component\Serializer\SerializerInterface;

/**
* @author Guillaume Loulier <contact@guillaumeloulier.fr>
*/
Expand Down
18 changes: 12 additions & 6 deletions src/Bridge/Doctrine/Transport/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@

namespace SchedulerBundle\Bridge\Doctrine\Transport;

use function array_map;

use Doctrine\DBAL\Connection as DBALConnection;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Result;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Query\Expr;
use Exception;

use const FILTER_VALIDATE_BOOLEAN;

use function filter_var;

use SchedulerBundle\Bridge\Doctrine\Connection\AbstractDoctrineConnection;
use SchedulerBundle\Exception\InvalidArgumentException;
use SchedulerBundle\Exception\LogicException;
Expand All @@ -20,15 +27,14 @@
use SchedulerBundle\Task\TaskList;
use SchedulerBundle\Task\TaskListInterface;
use SchedulerBundle\Transport\Configuration\ConfigurationInterface;

use SchedulerBundle\Transport\ConnectionInterface;
use Symfony\Component\Serializer\SerializerInterface;
use Throwable;

use function array_map;
use function filter_var;
use function sprintf;

use const FILTER_VALIDATE_BOOLEAN;
use Symfony\Component\Serializer\SerializerInterface;

use Throwable;

/**
* @author Guillaume Loulier <contact@guillaumeloulier.fr>
Expand All @@ -49,7 +55,7 @@ public function __construct(
*/
public function list(): TaskListInterface
{
$existingTasksCount = $this->createQueryBuilder(table: $this->configuration->get(key: 'table_name'), alias: 't')
$existingTasksCount = $this->createQueryBuilder(table: (string) $this->configuration->get(key: 'table_name'), alias: 't')
->select(select: (new Expr())->countDistinct(x: 't.id'))
;

Expand Down
3 changes: 2 additions & 1 deletion src/Bridge/Doctrine/Transport/DoctrineTransportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
use SchedulerBundle\Transport\Configuration\ConfigurationInterface;
use SchedulerBundle\Transport\Dsn;
use SchedulerBundle\Transport\TransportFactoryInterface;
use Symfony\Component\Serializer\SerializerInterface;

use function sprintf;

use Symfony\Component\Serializer\SerializerInterface;

/**
* @author Guillaume Loulier <contact@guillaumeloulier.fr>
*/
Expand Down
8 changes: 5 additions & 3 deletions src/Bridge/Redis/Transport/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace SchedulerBundle\Bridge\Redis\Transport;

use function array_map;

use Redis;
use SchedulerBundle\Exception\InvalidArgumentException;
use SchedulerBundle\Exception\TransportException;
Expand All @@ -12,12 +14,12 @@
use SchedulerBundle\Task\TaskListInterface;
use SchedulerBundle\Transport\Configuration\ConfigurationInterface;
use SchedulerBundle\Transport\ConnectionInterface;
use Symfony\Component\Serializer\SerializerInterface;
use Throwable;

use function array_map;
use function sprintf;

use Symfony\Component\Serializer\SerializerInterface;
use Throwable;

/**
* @author Guillaume Loulier <contact@guillaumeloulier.fr>
*/
Expand Down
6 changes: 4 additions & 2 deletions src/Bridge/Redis/Transport/RedisTransportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@

namespace SchedulerBundle\Bridge\Redis\Transport;

use function class_exists;
use function phpversion;

use Redis;
use SchedulerBundle\Exception\LogicException;
use SchedulerBundle\Exception\RuntimeException;
use SchedulerBundle\SchedulePolicy\SchedulePolicyOrchestratorInterface;
use SchedulerBundle\Transport\Configuration\ConfigurationInterface;
use SchedulerBundle\Transport\Dsn;

use SchedulerBundle\Transport\TransportFactoryInterface;
use Symfony\Component\Serializer\SerializerInterface;

use function class_exists;
use function phpversion;
use function version_compare;

/**
Expand Down
31 changes: 18 additions & 13 deletions src/Command/ConsumeTasksCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,40 @@

namespace SchedulerBundle\Command;

use function array_pop;

use DateTimeImmutable;

use function implode;
use function in_array;

use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use SchedulerBundle\Event\TaskExecutedEvent;
use SchedulerBundle\Event\WorkerSleepingEvent;
use SchedulerBundle\EventListener\StopWorkerOnFailureLimitSubscriber;
use SchedulerBundle\EventListener\StopWorkerOnTaskLimitSubscriber;
use SchedulerBundle\EventListener\StopWorkerOnTimeLimitSubscriber;
use SchedulerBundle\SchedulerInterface;
use SchedulerBundle\Task\Output;
use SchedulerBundle\Task\ProbeTask;
use SchedulerBundle\Task\TaskInterface;
use SchedulerBundle\Worker\WorkerConfiguration;
use SchedulerBundle\Worker\WorkerInterface;

use function sprintf;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;

use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use SchedulerBundle\Event\TaskExecutedEvent;
use SchedulerBundle\EventListener\StopWorkerOnFailureLimitSubscriber;
use SchedulerBundle\EventListener\StopWorkerOnTaskLimitSubscriber;
use SchedulerBundle\EventListener\StopWorkerOnTimeLimitSubscriber;
use SchedulerBundle\SchedulerInterface;
use SchedulerBundle\Task\Output;
use SchedulerBundle\Worker\WorkerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Throwable;

use function array_pop;
use function implode;
use function in_array;
use function sprintf;

/**
* @author Guillaume Loulier <contact@guillaumeloulier.fr>
*/
Expand Down Expand Up @@ -123,7 +128,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

if (false === $force) {
$nonPausedTasks = $dueTasks->filter(static fn (TaskInterface $task): bool => $task->getState() !== TaskInterface::PAUSED);
$nonPausedTasks = $dueTasks->filter(static fn (TaskInterface $task): bool => TaskInterface::PAUSED !== $task->getState());
if (0 === $nonPausedTasks->count()) {
$symfonyStyle->warning([
'Each tasks has already been executed for the current minute',
Expand Down
6 changes: 4 additions & 2 deletions src/Command/DebugConfigurationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
namespace SchedulerBundle\Command;

use SchedulerBundle\Transport\Configuration\ConfigurationInterface;

use function sprintf;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

use function sprintf;
use Symfony\Component\Console\Style\SymfonyStyle;

/**
* @author Guillaume Loulier <contact@guillaumeloulier.fr>
Expand Down
11 changes: 7 additions & 4 deletions src/Command/DebugMiddlewareCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace SchedulerBundle\Command;

use function array_map;
use function count;

use ReflectionClass;
use SchedulerBundle\Middleware\OrderedMiddlewareInterface;
use SchedulerBundle\Middleware\PostExecutionMiddlewareInterface;
Expand All @@ -13,17 +16,17 @@
use SchedulerBundle\Middleware\RequiredMiddlewareInterface;
use SchedulerBundle\Middleware\SchedulerMiddlewareStackInterface;
use SchedulerBundle\Middleware\WorkerMiddlewareStackInterface;

use function sprintf;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

use function array_map;
use function count;
use function sprintf;

/**
* @author Guillaume Loulier <contact@guillaumeloulier.fr>
*/
Expand Down
6 changes: 4 additions & 2 deletions src/Command/DebugProbeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
use SchedulerBundle\SchedulerInterface;
use SchedulerBundle\Task\ProbeTask;
use SchedulerBundle\Task\TaskInterface;

use function sprintf;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

use function sprintf;
use Symfony\Component\Console\Style\SymfonyStyle;

/**
* @author Guillaume Loulier <contact@guillaumeloulier.fr>
Expand Down
6 changes: 4 additions & 2 deletions src/Command/ExecuteExternalProbeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
use SchedulerBundle\Task\TaskInterface;
use SchedulerBundle\Worker\WorkerConfiguration;
use SchedulerBundle\Worker\WorkerInterface;

use function sprintf;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Throwable;

use function sprintf;
use Throwable;

/**
* @author Guillaume Loulier <contact@guillaumeloulier.fr>
Expand Down
Loading