Skip to content

Commit

Permalink
Apply styles; add cs fix workflow; generate psalm baseline
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Dec 13, 2024
1 parent 87e3b8e commit 028d7fb
Show file tree
Hide file tree
Showing 52 changed files with 561 additions and 376 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/cs-fix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---

on: # yamllint disable-line rule:truthy
push:
branches:
- '*'

name: Fix Code Style

jobs:
cs-fix:
permissions:
contents: write
uses: spiral/gh-actions/.github/workflows/cs-fix.yml@master

...
199 changes: 199 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
<file src="src/Bootloader/SchedulerBootloader.php">
<MixedArgument>
<code><![CDATA[$alias]]></code>
<code><![CDATA[$container->get(JobMutexInterface::class)]]></code>
<code><![CDATA[$expression]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$alias]]></code>
<code><![CDATA[$expression]]></code>
</MixedAssignment>
<PossiblyNullIterator>
<code><![CDATA[$config->getExpressionAliases()]]></code>
</PossiblyNullIterator>
<UndefinedInterfaceMethod>
<code><![CDATA[get]]></code>
</UndefinedInterfaceMethod>
</file>
<file src="src/CommandBuilder.php">
<RiskyTruthyFalsyComparison>
<code><![CDATA[$user]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/CommandRunner.php">
<MixedInferredReturnType>
<code><![CDATA[string]]></code>
</MixedInferredReturnType>
<MixedReturnStatement>
<code><![CDATA[\defined('SPIRAL_BINARY') ? SPIRAL_BINARY : 'app.php']]></code>
</MixedReturnStatement>
<RiskyTruthyFalsyComparison>
<code><![CDATA[! $binary]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/CommandUtils.php">
<MixedArgument>
<code><![CDATA[$value]]></code>
<code><![CDATA[$value]]></code>
<code><![CDATA[$value]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$value]]></code>
</MixedAssignment>
<MixedOperand>
<code><![CDATA[\is_numeric($key) ? $value : "{$key}={$value}"]]></code>
</MixedOperand>
<PossiblyInvalidArgument>
<code><![CDATA[$key]]></code>
<code><![CDATA[$key]]></code>
</PossiblyInvalidArgument>
</file>
<file src="src/Commands/ScheduleFinishCommand.php">
<InvalidClassConstantType>
<code><![CDATA[DESCRIPTION]]></code>
<code><![CDATA[SIGNATURE]]></code>
</InvalidClassConstantType>
<MixedAssignment>
<code><![CDATA[$exitCode]]></code>
<code><![CDATA[$id]]></code>
</MixedAssignment>
<PossiblyNullArgument>
<code><![CDATA[$this->container]]></code>
</PossiblyNullArgument>
</file>
<file src="src/Commands/ScheduleListCommand.php">
<InvalidClassConstantType>
<code><![CDATA[DESCRIPTION]]></code>
<code><![CDATA[NAME]]></code>
</InvalidClassConstantType>
<PossiblyNullArgument>
<code><![CDATA[$this->output]]></code>
</PossiblyNullArgument>
</file>
<file src="src/Commands/ScheduleRunCommand.php">
<InvalidClassConstantType>
<code><![CDATA[DESCRIPTION]]></code>
<code><![CDATA[NAME]]></code>
</InvalidClassConstantType>
<PossiblyNullArgument>
<code><![CDATA[$this->container]]></code>
</PossiblyNullArgument>
</file>
<file src="src/Commands/ScheduleWorkCommand.php">
<InvalidClassConstantType>
<code><![CDATA[DESCRIPTION]]></code>
<code><![CDATA[NAME]]></code>
</InvalidClassConstantType>
</file>
<file src="src/Config/SchedulerConfig.php">
<MixedArgument>
<code><![CDATA[$timezone]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$timezone]]></code>
</MixedAssignment>
<MixedInferredReturnType>
<code><![CDATA[?array]]></code>
<code><![CDATA[?string]]></code>
<code><![CDATA[?string]]></code>
</MixedInferredReturnType>
<MixedReturnStatement>
<code><![CDATA[$this->config['cacheStorage'] ?? null]]></code>
<code><![CDATA[$this->config['cacheStorage'] ?? null]]></code>
<code><![CDATA[$this->config['expression']['aliases'] ?? null]]></code>
<code><![CDATA[$this->config['expression']['aliases'] ?? null]]></code>
<code><![CDATA[$this->config['queueConnection'] ?? null]]></code>
<code><![CDATA[$this->config['queueConnection'] ?? null]]></code>
</MixedReturnStatement>
</file>
<file src="src/EveryMinuteCommandRunner.php">
<MixedArgument>
<code><![CDATA[$execution->getIncrementalErrorOutput()]]></code>
<code><![CDATA[$execution->getIncrementalOutput()]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$execution]]></code>
</MixedAssignment>
<MixedMethodCall>
<code><![CDATA[getIncrementalErrorOutput]]></code>
<code><![CDATA[getIncrementalOutput]]></code>
<code><![CDATA[isRunning]]></code>
</MixedMethodCall>
<PossiblyNullFunctionCall>
<code><![CDATA[$onError($errorOutput)]]></code>
<code><![CDATA[$onSuccess($output)]]></code>
</PossiblyNullFunctionCall>
</file>
<file src="src/Job/CallbackJob.php">
<MixedAssignment>
<code><![CDATA[$config]]></code>
<code><![CDATA[$invoker]]></code>
<code><![CDATA[$queue]]></code>
</MixedAssignment>
<MixedMethodCall>
<code><![CDATA[getConnection]]></code>
<code><![CDATA[getQueueConnection]]></code>
<code><![CDATA[invoke]]></code>
<code><![CDATA[pushCallable]]></code>
</MixedMethodCall>
<PossiblyNullOperand>
<code><![CDATA[$this->description]]></code>
</PossiblyNullOperand>
<RiskyTruthyFalsyComparison>
<code><![CDATA[$this->name]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Job/Job.php">
<MixedAssignment>
<code><![CDATA[$callback]]></code>
<code><![CDATA[$callback]]></code>
<code><![CDATA[$callback]]></code>
<code><![CDATA[$callback]]></code>
<code><![CDATA[$invoker]]></code>
<code><![CDATA[$invoker]]></code>
<code><![CDATA[$invoker]]></code>
</MixedAssignment>
<MixedMethodCall>
<code><![CDATA[invoke]]></code>
<code><![CDATA[invoke]]></code>
<code><![CDATA[invoke]]></code>
<code><![CDATA[invoke]]></code>
</MixedMethodCall>
</file>
<file src="src/JobsLocator.php">
<RiskyTruthyFalsyComparison>
<code><![CDATA[$schedule->runAs]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Schedule.php">
<PossiblyNullArgument>
<code><![CDATA[$commandName]]></code>
</PossiblyNullArgument>
<RedundantConditionGivenDocblockType>
<code><![CDATA[$command instanceof Command]]></code>
</RedundantConditionGivenDocblockType>
</file>
<file src="src/Testing/FakeJobHandler.php">
<MixedAssignment>
<code><![CDATA[$job]]></code>
<code><![CDATA[$jobs[]]]></code>
</MixedAssignment>
</file>
<file src="src/Testing/FakeJobMutex.php">
<MixedArgument>
<code><![CDATA[$this->created[$id]]]></code>
</MixedArgument>
</file>
<file src="src/Testing/FakeJobRegistry.php">
<MixedAssignment>
<code><![CDATA[$job]]></code>
<code><![CDATA[$jobs[]]]></code>
</MixedAssignment>
<MixedReturnTypeCoercion>
<code><![CDATA[$jobs]]></code>
<code><![CDATA[$this->registered]]></code>
</MixedReturnTypeCoercion>
</file>
</files>
8 changes: 3 additions & 5 deletions src/Attribute/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

namespace Spiral\Scheduler\Attribute;

use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;

#[Attribute(Attribute::TARGET_CLASS), NamedArgumentConstructor]
#[\Attribute(\Attribute::TARGET_CLASS), NamedArgumentConstructor]
class Schedule
{
public function __construct(
Expand All @@ -17,7 +16,6 @@ public function __construct(
public readonly ?string $runAs = null,
public readonly bool|int $withoutOverlapping = false,
public readonly bool $runInBackground = false,
public readonly array $parameters = []
) {
}
public readonly array $parameters = [],
) {}
}
22 changes: 10 additions & 12 deletions src/Bootloader/SchedulerBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class SchedulerBootloader extends Bootloader
TokenizerBootloader::class,
CacheBootloader::class,
];

protected const SINGLETONS = [
JobHandlerInterface::class => JobHandler::class,
PeriodicCommandRunnerInterface::class => EveryMinuteCommandRunner::class,
Expand All @@ -52,18 +51,17 @@ class SchedulerBootloader extends Bootloader
];

public function __construct(
private readonly ConfiguratorInterface $config
) {
}
private readonly ConfiguratorInterface $config,
) {}

public function init(
EnvironmentInterface $env,
AbstractKernel $kernel,
ConsoleBootloader $console
ConsoleBootloader $console,
): void {
$this->initConfig($env);

$kernel->booting(static function (SchedulerConfig $config) {
$kernel->booting(static function (SchedulerConfig $config): void {
foreach ($config->getExpressionAliases() as $alias => $expression) {
if (! CronExpression::supportsAlias($alias)) {
CronExpression::registerAlias($alias, $expression);
Expand All @@ -87,7 +85,7 @@ private function initSchedule(
FactoryInterface $container,
ProcessFactory $processFactory,
JobRegistryInterface $registry,
CommandRunner $commandRunner
CommandRunner $commandRunner,
): Schedule {
return new Schedule(
$container,
Expand All @@ -100,23 +98,23 @@ private function initSchedule(

private function initJobsLocator(
ClassesInterface $classes,
JobMutexInterface $mutex
JobMutexInterface $mutex,
): JobsLocatorInterface {
return new JobsLocator($classes, new AttributeReader(), $mutex);
}

private function initEventMutex(
CacheStorageProviderInterface $provider,
SchedulerConfig $config
SchedulerConfig $config,
): JobMutexInterface {
return new CacheJobMutex(
$provider->storage(
$config->getCacheStorage()
)
$config->getCacheStorage(),
),
);
}

private function initConfig(EnvironmentInterface $env)
private function initConfig(EnvironmentInterface $env): void
{
$this->config->setDefaults(SchedulerConfig::CONFIG, [
'cacheStorage' => $env->get('SCHEDULER_MUTEX_CACHE_STORAGE'),
Expand Down
23 changes: 11 additions & 12 deletions src/CommandBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@
final class CommandBuilder
{
public function __construct(
private readonly CommandRunner $commandRunner
) {
}
private readonly CommandRunner $commandRunner,
) {}

public function buildForegroundCommand(
string $command,
bool $appendOutput = false,
string $output = '/dev/null',
?string $user = null
?string $user = null,
): string {
$output = ProcessUtils::escapeArgument($output);

return $this->ensureCorrectUser(
$command.($appendOutput ? ' >> ' : ' > ').$output.' 2>&1',
$user
$command . ($appendOutput ? ' >> ' : ' > ') . $output . ' 2>&1',
$user,
);
}

Expand All @@ -30,18 +29,18 @@ public function buildBackgroundCommand(
string $id,
bool $appendOutput = false,
string $output = '/dev/null',
?string $user = null
?string $user = null,
): string {
$output = ProcessUtils::escapeArgument($output);

$redirect = $appendOutput ? ' >> ' : ' > ';

$finished = $this->commandRunner->formatCommandString('schedule:finish').' "'.$id.'"';
$finished = $this->commandRunner->formatCommandString('schedule:finish') . ' "' . $id . '"';

return $this->ensureCorrectUser(
'('.$command.$redirect.$output.' 2>&1 ; '.$finished.' "$?") > '
.ProcessUtils::escapeArgument('/dev/null').' 2>&1 &',
$user
'(' . $command . $redirect . $output . ' 2>&1 ; ' . $finished . ' "$?") > '
. ProcessUtils::escapeArgument('/dev/null') . ' 2>&1 &',
$user,
);
}

Expand All @@ -50,6 +49,6 @@ public function buildBackgroundCommand(
*/
protected function ensureCorrectUser(string $command, ?string $user = null): string
{
return $user ? 'sudo -u '.$user.' -- sh -c \''.$command.'\'' : $command;
return $user ? 'sudo -u ' . $user . ' -- sh -c \'' . $command . '\'' : $command;
}
}
9 changes: 3 additions & 6 deletions src/CommandRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@
final class CommandRunner
{
public function __construct(
private readonly PhpExecutableFinder $phpFinder
) {
}
private readonly PhpExecutableFinder $phpFinder,
) {}

public function run(string $command): void
{
}
public function run(string $command): void {}

/**
* Determine the proper PHP executable.
Expand Down
Loading

0 comments on commit 028d7fb

Please sign in to comment.