Skip to content

Commit fae7ee8

Browse files
authored
Add conventions around PHP code in the project (#68)
* Add convention tests over packages definitions * Add conventions around classes docblocks * Add conventions around public method docblocks
1 parent 6c98389 commit fae7ee8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+229
-28
lines changed

src/Event/JobEvent.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
use Yokai\Batch\JobExecution;
88

9+
/**
10+
* Base class for all job execution related events.
11+
*/
912
class JobEvent
1013
{
1114
public function __construct(

src/Event/PostExecuteEvent.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
namespace Yokai\Batch\Event;
66

7+
/**
8+
* This event is triggered by {@see JobExecutor}
9+
* whenever a job execution fails or succeed.
10+
*/
711
final class PostExecuteEvent extends JobEvent
812
{
913
}

src/Event/PreExecuteEvent.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
namespace Yokai\Batch\Event;
66

7+
use Yokai\Batch\Job\JobExecutor;
8+
9+
/**
10+
* This event is triggered by {@see JobExecutor}
11+
* whenever a job execution starts.
12+
*/
713
final class PreExecuteEvent extends JobEvent
814
{
915
}

src/Exception/ExceptionInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
use Throwable;
88

9+
/**
10+
* Interface for all exceptions triggered by this library.
11+
*/
912
interface ExceptionInterface extends Throwable
1013
{
1114
}

src/Exception/UndefinedJobException.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
namespace Yokai\Batch\Exception;
66

7+
use Throwable;
8+
79
class UndefinedJobException extends InvalidArgumentException
810
{
9-
public function __construct(string $name)
11+
public function __construct(string $name, Throwable $previous = null)
1012
{
11-
parent::__construct(sprintf('Job "%s" is undefined', $name));
13+
parent::__construct(sprintf('Job "%s" is undefined', $name), $previous);
1214
}
1315
}

src/Factory/JobExecutionFactory.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
use Yokai\Batch\JobExecution;
88
use Yokai\Batch\JobParameters;
99

10+
/**
11+
* Create a {@see JobExecution} from scalar members.
12+
*/
1013
final class JobExecutionFactory
1114
{
1215
public function __construct(
@@ -15,6 +18,8 @@ public function __construct(
1518
}
1619

1720
/**
21+
* Create a {@see JobExecution}.
22+
*
1823
* @phpstan-param array<string, mixed> $configuration
1924
*/
2025
public function create(string $name, array $configuration = []): JobExecution

src/Factory/JobExecutionIdGeneratorInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
*/
1212
interface JobExecutionIdGeneratorInterface
1313
{
14+
/**
15+
* Generate and return a new id for the {@see JobExecution}.
16+
*/
1417
public function generate(): string;
1518
}

src/Factory/UniqidJobExecutionIdGenerator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
namespace Yokai\Batch\Factory;
66

7+
/**
8+
* This {@see JobExecutionIdGeneratorInterface} will use
9+
* php {@see uniqid} function to generate job ids.
10+
*/
711
final class UniqidJobExecutionIdGenerator implements JobExecutionIdGeneratorInterface
812
{
913
/**

src/Failure.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public function __construct(
3838
}
3939

4040
/**
41+
* Static constructor from an exception.
42+
*
4143
* @phpstan-param array<string, string> $parameters
4244
*/
4345
public static function fromException(Throwable $exception, array $parameters = []): self

src/Job/Item/Processor/CallbackProcessor.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
use Closure;
88
use Yokai\Batch\Job\Item\ItemProcessorInterface;
99

10+
/**
11+
* This {@see ItemProcessorInterface} will transform every item
12+
* with a closure provided at object's construction.
13+
*/
1014
final class CallbackProcessor implements ItemProcessorInterface
1115
{
12-
private Closure $callback;
13-
14-
public function __construct(Closure $callback)
15-
{
16-
$this->callback = $callback;
16+
public function __construct(
17+
private Closure $callback,
18+
) {
1719
}
1820

1921
public function process(mixed $item): mixed

0 commit comments

Comments
 (0)