Skip to content

Commit

Permalink
Merge pull request #64 from job-runner/coding-standard-10
Browse files Browse the repository at this point in the history
Update doctrine/coding-standard requirement from ^9.0 to ^10.0
  • Loading branch information
fezfez committed Oct 14, 2022
2 parents 43f6266 + ac09c43 commit cfb135d
Show file tree
Hide file tree
Showing 24 changed files with 61 additions and 121 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -17,7 +17,7 @@
"symfony/process": "^6.0"
},
"require-dev": {
"doctrine/coding-standard": "^9.0",
"doctrine/coding-standard": "^10.0",
"infection/infection": "^0.26.15",
"phpunit/phpunit": "^9.5.25",
"psalm/plugin-phpunit": "^0.17.0",
Expand Down
22 changes: 10 additions & 12 deletions src/CronJobRunner.php
Expand Up @@ -15,18 +15,16 @@

final class CronJobRunner implements JobRunner
{
private CreateProcess $createProcess;
private WaitForJobsToEnd $waitForJobsToEnd;
private PersistingStoreInterface $persistingStore;
/** @var array<array-key, JobEvent> */
private array $jobEvent;

public function __construct(CreateProcess $createProcess, WaitForJobsToEnd $waitForJobsToEnd, PersistingStoreInterface $persistingStore, JobEvent ...$jobEvent)
{
$this->createProcess = $createProcess;
$this->waitForJobsToEnd = $waitForJobsToEnd;
$this->persistingStore = $persistingStore;
$this->jobEvent = $jobEvent;
public function __construct(
private readonly CreateProcess $createProcess,
private readonly WaitForJobsToEnd $waitForJobsToEnd,
private readonly PersistingStoreInterface $persistingStore,
JobEvent ...$jobEvent,
) {
$this->jobEvent = $jobEvent;
}

public static function create(): self
Expand All @@ -36,7 +34,7 @@ public static function create(): self
return new self(
new CreateProcess(new LockFactory($persistingStore), new JobEventRunner()),
new WaitForJobsToEnd(new JobEventRunner()),
$persistingStore
$persistingStore,
);
}

Expand All @@ -50,7 +48,7 @@ public function withEventListener(JobEvent $jobEvent): self
new CreateProcess(new LockFactory($this->persistingStore), $jobEventRunner),
new WaitForJobsToEnd($jobEventRunner),
$this->persistingStore,
...$this->jobEvent
...$this->jobEvent,
);
}

Expand All @@ -62,7 +60,7 @@ public function withPersistingStore(PersistingStoreInterface $persistingStore):
new CreateProcess(new LockFactory($persistingStore), $jobEventRunner),
new WaitForJobsToEnd($jobEventRunner),
$persistingStore,
...$this->jobEvent
...$this->jobEvent,
);
}

Expand Down
10 changes: 4 additions & 6 deletions src/Event/JobEventRunner.php
Expand Up @@ -6,10 +6,12 @@

use JobRunner\JobRunner\Job\Job;

use function array_filter;

class JobEventRunner implements JobStartEvent, JobSuccessEvent, JobFailEvent, JobNotDueEvent, JobIsLockedEvent
{
/** @var array<array-key, JobEvent> */
private array $jobEvent;
private readonly array $jobEvent;

public function __construct(JobEvent ...$jobEvent)
{
Expand Down Expand Up @@ -54,11 +56,7 @@ public function isLocked(Job $job): void
/** @param class-string $classNam e*/
private function apply(string $className, callable $callable): void
{
foreach ($this->jobEvent as $event) {
if (! ($event instanceof $className)) {
continue;
}

foreach (array_filter($this->jobEvent, static fn (JobEvent $event) => $event instanceof $className) as $event) {
$callable($event);
}
}
Expand Down
19 changes: 8 additions & 11 deletions src/Job/CliJob.php
Expand Up @@ -8,19 +8,16 @@

class CliJob implements Job
{
private string $command;
private string $cronExpression;
private string $name;
private int $ttl;
private bool $autoRelease;

public function __construct(string $command, string $cronExpression, ?string $name = null, int $ttl = 300, bool $autoRelease = true)
{
$this->command = $command;
$this->cronExpression = $cronExpression;
$this->name = $name ?? $command;
$this->ttl = $ttl;
$this->autoRelease = $autoRelease;
public function __construct(
private readonly string $command,
private readonly string $cronExpression,
string|null $name = null,
private readonly int $ttl = 300,
private readonly bool $autoRelease = true,
) {
$this->name = $name ?? $command;
}

public function getProcess(): Process
Expand Down
20 changes: 7 additions & 13 deletions src/Job/PhpJob.php
Expand Up @@ -9,19 +9,13 @@

class PhpJob implements Job
{
private string $cronExpression;
private string $name;
private int $ttl;
private bool $autoRelease;
private string $script;

public function __construct(string $script, string $cronExpression, string $name, int $ttl = 300, bool $autoRelease = true)
{
$this->cronExpression = $cronExpression;
$this->name = $name;
$this->ttl = $ttl;
$this->autoRelease = $autoRelease;
$this->script = $script;
public function __construct(
private readonly string $script,
private readonly string $cronExpression,
private readonly string $name,
private readonly int $ttl = 300,
private readonly bool $autoRelease = true,
) {
}

public function getProcess(): Process
Expand Down
15 changes: 5 additions & 10 deletions src/Process/CreateProcess.php
Expand Up @@ -14,18 +14,13 @@
use JobRunner\JobRunner\Process\Dto\ProcessAndLockList;
use Symfony\Component\Lock\LockFactory;

/**
* @internal
*/
/** @internal */
class CreateProcess
{
private LockFactory $lock;
private JobEventRunner $jobEventRunner;

public function __construct(LockFactory $lock, JobEventRunner $jobEventRunner)
{
$this->lock = $lock;
$this->jobEventRunner = $jobEventRunner;
public function __construct(
private readonly LockFactory $lock,
private readonly JobEventRunner $jobEventRunner,
) {
}

public function __invoke(JobList $jobs): ProcessAndLockList
Expand Down
18 changes: 6 additions & 12 deletions src/Process/Dto/ProcessAndLock.php
Expand Up @@ -8,20 +8,14 @@
use Symfony\Component\Lock\LockInterface;
use Symfony\Component\Process\Process;

/**
* @internal
*/
/** @internal */
class ProcessAndLock
{
private LockInterface $lock;
private Process $process;
private Job $job;

public function __construct(LockInterface $lock, Process $process, Job $job)
{
$this->lock = $lock;
$this->process = $process;
$this->job = $job;
public function __construct(
private readonly LockInterface $lock,
private readonly Process $process,
private readonly Job $job,
) {
}

public function getLock(): LockInterface
Expand Down
4 changes: 1 addition & 3 deletions src/Process/Dto/ProcessAndLockList.php
Expand Up @@ -10,9 +10,7 @@
use function array_key_exists;
use function array_values;

/**
* @internal
*/
/** @internal */
class ProcessAndLockList
{
/** @var array<string, ProcessAndLock> */
Expand Down
12 changes: 4 additions & 8 deletions src/Process/WaitForJobsToEnd.php
Expand Up @@ -8,16 +8,12 @@
use JobRunner\JobRunner\Process\Dto\ProcessAndLock;
use JobRunner\JobRunner\Process\Dto\ProcessAndLockList;

/**
* @internal
*/
/** @internal */
class WaitForJobsToEnd
{
private JobEventRunner $eventRunner;

public function __construct(JobEventRunner $eventRunner)
{
$this->eventRunner = $eventRunner;
public function __construct(
private readonly JobEventRunner $eventRunner,
) {
}

public function __invoke(ProcessAndLockList $jobsToRun): void
Expand Down
4 changes: 1 addition & 3 deletions tests/E2e/TestCliJob.php
Expand Up @@ -9,9 +9,7 @@
use JobRunner\JobRunner\Job\JobList;
use PHPUnit\Framework\TestCase;

/**
* @coversNothing
*/
/** @coversNothing */
class TestCliJob extends TestCase
{
public function testOk(): void
Expand Down
4 changes: 1 addition & 3 deletions tests/E2e/TestPhpJob.php
Expand Up @@ -9,9 +9,7 @@
use JobRunner\JobRunner\Job\PhpJob;
use PHPUnit\Framework\TestCase;

/**
* @coversNothing
*/
/** @coversNothing */
class TestPhpJob extends TestCase
{
public function testOk(): void
Expand Down
4 changes: 1 addition & 3 deletions tests/Unit/CronJobRunnerTest.php
Expand Up @@ -15,9 +15,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Lock\PersistingStoreInterface;

/**
* @covers \JobRunner\JobRunner\CronJobRunner
*/
/** @covers \JobRunner\JobRunner\CronJobRunner */
class CronJobRunnerTest extends TestCase
{
public function testOk(): void
Expand Down
4 changes: 1 addition & 3 deletions tests/Unit/Event/JobEventRunnerTest.php
Expand Up @@ -13,9 +13,7 @@
use JobRunner\JobRunner\Job\Job;
use PHPUnit\Framework\TestCase;

/**
* @covers \JobRunner\JobRunner\Event\JobEventRunner
*/
/** @covers \JobRunner\JobRunner\Event\JobEventRunner */
class JobEventRunnerTest extends TestCase
{
public function testOk(): void
Expand Down
4 changes: 1 addition & 3 deletions tests/Unit/Exceptions/DuplicateJobTest.php
Expand Up @@ -8,9 +8,7 @@
use JobRunner\JobRunner\Job\Job;
use PHPUnit\Framework\TestCase;

/**
* @covers \JobRunner\JobRunner\Exceptions\DuplicateJob
*/
/** @covers \JobRunner\JobRunner\Exceptions\DuplicateJob */
class DuplicateJobTest extends TestCase
{
public function testOk(): void
Expand Down
4 changes: 1 addition & 3 deletions tests/Unit/Exceptions/LockedJobTest.php
Expand Up @@ -8,9 +8,7 @@
use JobRunner\JobRunner\Job\Job;
use PHPUnit\Framework\TestCase;

/**
* @covers \JobRunner\JobRunner\Exceptions\LockedJob
*/
/** @covers \JobRunner\JobRunner\Exceptions\LockedJob */
class LockedJobTest extends TestCase
{
public function testOk(): void
Expand Down
4 changes: 1 addition & 3 deletions tests/Unit/Exceptions/NotDueJobTest.php
Expand Up @@ -8,9 +8,7 @@
use JobRunner\JobRunner\Job\Job;
use PHPUnit\Framework\TestCase;

/**
* @covers \JobRunner\JobRunner\Exceptions\NotDueJob
*/
/** @covers \JobRunner\JobRunner\Exceptions\NotDueJob */
class NotDueJobTest extends TestCase
{
public function testOk(): void
Expand Down
4 changes: 1 addition & 3 deletions tests/Unit/Exceptions/UnknownProcessTest.php
Expand Up @@ -9,9 +9,7 @@
use JobRunner\JobRunner\Process\Dto\ProcessAndLock;
use PHPUnit\Framework\TestCase;

/**
* @covers \JobRunner\JobRunner\Exceptions\UnknownProcess
*/
/** @covers \JobRunner\JobRunner\Exceptions\UnknownProcess */
class UnknownProcessTest extends TestCase
{
public function testOk(): void
Expand Down
4 changes: 1 addition & 3 deletions tests/Unit/Job/CliJobTest.php
Expand Up @@ -7,9 +7,7 @@
use JobRunner\JobRunner\Job\CliJob;
use PHPUnit\Framework\TestCase;

/**
* @covers \JobRunner\JobRunner\Job\CliJob
*/
/** @covers \JobRunner\JobRunner\Job\CliJob */
class CliJobTest extends TestCase
{
public function testOkWithDefaultValue(): void
Expand Down
4 changes: 1 addition & 3 deletions tests/Unit/Job/JobListTest.php
Expand Up @@ -9,9 +9,7 @@
use JobRunner\JobRunner\Job\JobList;
use PHPUnit\Framework\TestCase;

/**
* @covers \JobRunner\JobRunner\Job\JobList
*/
/** @covers \JobRunner\JobRunner\Job\JobList */
class JobListTest extends TestCase
{
public function testOk(): void
Expand Down
4 changes: 1 addition & 3 deletions tests/Unit/Job/PhpJobTest.php
Expand Up @@ -7,9 +7,7 @@
use JobRunner\JobRunner\Job\PhpJob;
use PHPUnit\Framework\TestCase;

/**
* @covers \JobRunner\JobRunner\Job\PhpJob
*/
/** @covers \JobRunner\JobRunner\Job\PhpJob */
class PhpJobTest extends TestCase
{
public function testOkWithDefaultValue(): void
Expand Down
4 changes: 1 addition & 3 deletions tests/Unit/Process/CreateProcessTest.php
Expand Up @@ -13,9 +13,7 @@
use Symfony\Component\Lock\LockInterface;
use Symfony\Component\Process\Process;

/**
* @covers \JobRunner\JobRunner\Process\CreateProcess
*/
/** @covers \JobRunner\JobRunner\Process\CreateProcess */
class CreateProcessTest extends TestCase
{
public function testNoNeedToRun(): void
Expand Down
4 changes: 1 addition & 3 deletions tests/Unit/Process/Dto/ProcessAndLockListTest.php
Expand Up @@ -11,9 +11,7 @@
use JobRunner\JobRunner\Process\Dto\ProcessAndLockList;
use PHPUnit\Framework\TestCase;

/**
* @covers \JobRunner\JobRunner\Process\Dto\ProcessAndLockList
*/
/** @covers \JobRunner\JobRunner\Process\Dto\ProcessAndLockList */
class ProcessAndLockListTest extends TestCase
{
public function testOk(): void
Expand Down
4 changes: 1 addition & 3 deletions tests/Unit/Process/Dto/ProcessAndLockTest.php
Expand Up @@ -10,9 +10,7 @@
use Symfony\Component\Lock\LockInterface;
use Symfony\Component\Process\Process;

/**
* @covers \JobRunner\JobRunner\Process\Dto\ProcessAndLock
*/
/** @covers \JobRunner\JobRunner\Process\Dto\ProcessAndLock */
class ProcessAndLockTest extends TestCase
{
public function testOk(): void
Expand Down
4 changes: 1 addition & 3 deletions tests/Unit/Process/WaitForJobsToEndTest.php
Expand Up @@ -13,9 +13,7 @@
use Symfony\Component\Lock\LockInterface;
use Symfony\Component\Process\Process;

/**
* @covers \JobRunner\JobRunner\Process\WaitForJobsToEnd
*/
/** @covers \JobRunner\JobRunner\Process\WaitForJobsToEnd */
class WaitForJobsToEndTest extends TestCase
{
public function testOkWithTwoElements(): void
Expand Down

0 comments on commit cfb135d

Please sign in to comment.