Skip to content

Commit 1cde1a4

Browse files
committed
Codestyle fixes
1 parent ef5be94 commit 1cde1a4

12 files changed

+64
-35
lines changed

.php-cs-fixer.dist.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@
6464
// Empty body of class, interface, trait, enum or function must be abbreviated as {} and placed on the same line
6565
'single_line_empty_body' => false,
6666

67-
// Class DateTimeImmutable should be used instead of DateTime.
68-
'date_time_immutable' => true,
69-
7067
// Functions should be used with $strict param set to true.
7168
'strict_param' => true,
7269

psalm.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@
1313
<directory name="src" />
1414
<ignoreFiles>
1515
<directory name="vendor" />
16+
<file name="src/config/configuration.php" />
1617
</ignoreFiles>
1718
</projectFiles>
19+
20+
<issueHandlers>
21+
<UnresolvableInclude>
22+
<errorLevel type="suppress">
23+
<directory name="src" />
24+
</errorLevel>
25+
</UnresolvableInclude>
26+
<ForbiddenCode>
27+
<errorLevel type="suppress">
28+
<directory name="src" />
29+
</errorLevel>
30+
</ForbiddenCode>
31+
</issueHandlers>
1832
</psalm>

src/Internal/Functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static function cpuCount(): int
1717
{
1818
if (\PHP_VERSION_ID >= 80300) {
1919
return \posix_sysconf(\POSIX_SC_NPROCESSORS_ONLN);
20-
} else if (\DIRECTORY_SEPARATOR === '/' && \function_exists('shell_exec')) {
20+
} elseif (\DIRECTORY_SEPARATOR === '/' && \function_exists('shell_exec')) {
2121
return \strtolower(\PHP_OS) === 'darwin'
2222
? (int) \shell_exec('sysctl -n machdep.cpu.core_count')
2323
: (int) \shell_exec('nproc');

src/KernelFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
private bool $isDebug;
1313
private string $projectDir;
1414

15+
/** @psalm-suppress InvalidPropertyAssignmentValue */
1516
public function __construct(private \Closure $app, private array $args, array $options)
1617
{
1718
$this->projectDir = $options['project_dir'];

src/Scheduler/Trigger/CronExpressionTrigger.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,23 @@
66

77
use Cron\CronExpression;
88

9+
/**
10+
* @psalm-suppress UndefinedClass
11+
*/
912
final class CronExpressionTrigger implements TriggerInterface
1013
{
1114
private CronExpression $expression;
1215

1316
public function __construct(string $expression)
1417
{
15-
if (!class_exists(CronExpression::class)) {
16-
throw new \LogicException(sprintf('You cannot use "%s" as the "cron expression" package is not installed. Try running "composer require dragonmantank/cron-expression".', __CLASS__));
18+
if (!\class_exists(CronExpression::class)) {
19+
throw new \LogicException(\sprintf('You cannot use "%s" as the "cron expression" package is not installed. Try running "composer require dragonmantank/cron-expression".', __CLASS__));
1720
}
1821

1922
try {
2023
$this->expression = new CronExpression($expression);
2124
} catch (\InvalidArgumentException $e) {
22-
throw new \InvalidArgumentException(sprintf('Invalid cron expression "%s"', $expression), 0, $e);
25+
throw new \InvalidArgumentException(\sprintf('Invalid cron expression "%s"', $expression), 0, $e);
2326
}
2427
}
2528

@@ -31,6 +34,6 @@ public function __toString(): string
3134
public function getNextRunDate(\DateTimeImmutable $now): \DateTimeImmutable|null
3235
{
3336
$next = $this->expression->getNextRunDate($now);
34-
return $next instanceof \Datetime ? \DateTimeImmutable::createFromMutable($next) : $next;
37+
return $next instanceof \DateTime ? \DateTimeImmutable::createFromMutable($next) : $next;
3538
}
3639
}

src/Scheduler/Trigger/DateTimeTrigger.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ final class DateTimeTrigger implements TriggerInterface
1010

1111
public function __construct(string|\DateTimeImmutable $date)
1212
{
13-
if (is_string($date) && $iso8601Date = \DateTimeImmutable::createFromFormat(\DateTimeInterface::ATOM, $date)) {
13+
if (\is_string($date) && $iso8601Date = \DateTimeImmutable::createFromFormat(\DateTimeInterface::ATOM, $date)) {
1414
$date = $iso8601Date;
1515
}
1616

17-
if (is_string($date)) {
17+
if (\is_string($date)) {
1818
try {
1919
$this->date = new \DateTimeImmutable($date);
2020
} catch (\Exception $e) {
21-
throw new \InvalidArgumentException(sprintf('Invalid date string "%s": %s', $date, $e->getMessage()), 0, $e);
21+
throw new \InvalidArgumentException(\sprintf('Invalid date string "%s": %s', $date, $e->getMessage()), 0, $e);
2222
}
2323
} else {
2424
$this->date = $date;

src/Scheduler/Trigger/JitterTrigger.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ public function __construct(private readonly TriggerInterface $trigger, private
1212

1313
public function __toString(): string
1414
{
15-
return sprintf('%s with 0-%d second jitter', $this->trigger, $this->jitter);
15+
return \sprintf('%s with 0-%d second jitter', $this->trigger, $this->jitter);
1616
}
1717

18+
/**
19+
* @psalm-suppress FalsableReturnStatement
20+
* @psalm-suppress InvalidFalsableReturnType
21+
*/
1822
public function getNextRunDate(\DateTimeImmutable $now): \DateTimeImmutable|null
1923
{
20-
return $this->trigger->getNextRunDate($now)?->modify(sprintf('+%d seconds', random_int(0, $this->jitter)));
24+
return $this->trigger->getNextRunDate($now)?->modify(\sprintf('+%d seconds', \random_int(0, $this->jitter)));
2125
}
2226
}

src/Scheduler/Trigger/PeriodicalTrigger.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ final class PeriodicalTrigger implements TriggerInterface
1212
public function __construct(string|int|\DateInterval $interval)
1313
{
1414
try {
15-
if (is_numeric($interval)) {
16-
$this->interval = \DateInterval::createFromDateString(sprintf('%d seconds', $interval));
17-
$this->description = sprintf('every %s seconds', $interval);
18-
} elseif (\is_string($interval) && str_starts_with($interval, 'P')) {
15+
if (\is_numeric($interval)) {
16+
$this->interval = \DateInterval::createFromDateString(\sprintf('%d seconds', $interval));
17+
$this->description = \sprintf('every %s seconds', $interval);
18+
} elseif (\is_string($interval) && \str_starts_with($interval, 'P')) {
1919
$this->interval = new \DateInterval($interval);
20-
$this->description = sprintf('DateInterval (%s)', $interval);
20+
$this->description = \sprintf('DateInterval (%s)', $interval);
2121
} elseif (\is_string($interval)) {
2222
$this->interval = @\DateInterval::createFromDateString($interval);
23-
$this->description = sprintf('every %s', $interval);
23+
$this->description = \sprintf('every %s', $interval);
2424
} else {
2525
$this->interval = $interval;
2626
$a = (array) $interval;
27-
$this->description = isset($a['from_string']) ? sprintf('every %s', $a['date_string']) : 'DateInterval';
27+
$this->description = isset($a['from_string']) ? \sprintf('every %s', $a['date_string']) : 'DateInterval';
2828
}
2929
} catch (\Throwable $e) {
30-
throw new \InvalidArgumentException(sprintf('Invalid interval "%s": %s', $interval instanceof \DateInterval ? 'instance of \DateInterval' : $interval, $e->getMessage()), 0, $e);
30+
throw new \InvalidArgumentException(\sprintf('Invalid interval "%s": %s', $interval instanceof \DateInterval ? 'instance of \DateInterval' : $interval, $e->getMessage()), 0, $e);
3131
}
3232
}
3333

src/Scheduler/Trigger/TriggerFactory.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ final class TriggerFactory
2727
*/
2828
public static function create(string|int|\DateInterval|\DateTimeImmutable $expression, int $jitter = 0): TriggerInterface
2929
{
30-
$expression = \DateTimeImmutable::createFromFormat(\DateTimeInterface::ATOM, $expression) ?: $expression;
30+
if (\is_string($expression)) {
31+
$expression = \DateTimeImmutable::createFromFormat(\DateTimeInterface::ATOM, $expression) ?: $expression;
32+
}
3133

3234
$trigger = match (true) {
3335
$expression instanceof \DateTimeImmutable => new DateTimeTrigger($expression),
34-
count(explode(' ', $expression)) === 5 && str_contains($expression, '*'),
35-
str_starts_with($expression, '@') => new CronExpressionTrigger($expression),
36+
\is_string($expression) && \count(\explode(' ', $expression)) === 5 && \str_contains($expression, '*'),
37+
\is_string($expression) && \str_starts_with($expression, '@') => new CronExpressionTrigger($expression),
3638
default => new PeriodicalTrigger($expression),
3739
};
3840

src/Worker/HttpServerWorker.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
use Luzrain\PhpRunnerBundle\Event\HttpServerStartEvent;
1212
use Luzrain\PhpRunnerBundle\KernelFactory;
1313
use Psr\Http\Message\ServerRequestInterface;
14-
use Psr\Log\LoggerInterface;
15-
use Symfony\Component\ErrorHandler\ErrorHandler;
1614
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
1715

1816
final class HttpServerWorker extends WorkerProcess

0 commit comments

Comments
 (0)