Skip to content

Commit 6e7c3ad

Browse files
committed
use constructor property promotion
1 parent bc9a36f commit 6e7c3ad

14 files changed

+75
-117
lines changed

Diff for: Dumper/MermaidDumper.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,18 @@ class MermaidDumper implements DumperInterface
3939
self::TRANSITION_TYPE_WORKFLOW,
4040
];
4141

42-
private string $direction;
43-
private string $transitionType;
44-
4542
/**
4643
* Just tracking the transition id is in some cases inaccurate to
4744
* get the link's number for styling purposes.
4845
*/
4946
private int $linkCount = 0;
5047

51-
public function __construct(string $transitionType, string $direction = self::DIRECTION_LEFT_TO_RIGHT)
52-
{
48+
public function __construct(
49+
private string $transitionType,
50+
private string $direction = self::DIRECTION_LEFT_TO_RIGHT,
51+
) {
5352
$this->validateDirection($direction);
5453
$this->validateTransitionType($transitionType);
55-
56-
$this->direction = $direction;
57-
$this->transitionType = $transitionType;
5854
}
5955

6056
public function dump(Definition $definition, ?Marking $marking = null, array $options = []): string

Diff for: Dumper/PlantUmlDumper.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,12 @@ class PlantUmlDumper implements DumperInterface
5151
],
5252
];
5353

54-
private string $transitionType = self::STATEMACHINE_TRANSITION;
55-
56-
public function __construct(string $transitionType)
57-
{
54+
public function __construct(
55+
private string $transitionType,
56+
) {
5857
if (!\in_array($transitionType, self::TRANSITION_TYPES, true)) {
5958
throw new \InvalidArgumentException("Transition type '$transitionType' does not exist.");
6059
}
61-
$this->transitionType = $transitionType;
6260
}
6361

6462
public function dump(Definition $definition, ?Marking $marking = null, array $options = []): string

Diff for: Event/Event.php

+6-11
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,12 @@
2323
*/
2424
class Event extends BaseEvent
2525
{
26-
private object $subject;
27-
private Marking $marking;
28-
private ?Transition $transition;
29-
private ?WorkflowInterface $workflow;
30-
31-
public function __construct(object $subject, Marking $marking, ?Transition $transition = null, ?WorkflowInterface $workflow = null)
32-
{
33-
$this->subject = $subject;
34-
$this->marking = $marking;
35-
$this->transition = $transition;
36-
$this->workflow = $workflow;
26+
public function __construct(
27+
private object $subject,
28+
private Marking $marking,
29+
private ?Transition $transition = null,
30+
private ?WorkflowInterface $workflow = null,
31+
) {
3732
}
3833

3934
public function getMarking(): Marking

Diff for: EventListener/AuditTrailListener.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020
*/
2121
class AuditTrailListener implements EventSubscriberInterface
2222
{
23-
private LoggerInterface $logger;
24-
25-
public function __construct(LoggerInterface $logger)
26-
{
27-
$this->logger = $logger;
23+
public function __construct(
24+
private LoggerInterface $logger,
25+
) {
2826
}
2927

3028
public function onLeave(Event $event): void

Diff for: EventListener/GuardExpression.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@
1515

1616
class GuardExpression
1717
{
18-
private Transition $transition;
19-
private string $expression;
20-
21-
public function __construct(Transition $transition, string $expression)
22-
{
23-
$this->transition = $transition;
24-
$this->expression = $expression;
18+
public function __construct(
19+
private Transition $transition,
20+
private string $expression,
21+
) {
2522
}
2623

2724
public function getTransition(): Transition

Diff for: EventListener/GuardListener.php

+9-17
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,15 @@
2424
*/
2525
class GuardListener
2626
{
27-
private array $configuration;
28-
private ExpressionLanguage $expressionLanguage;
29-
private TokenStorageInterface $tokenStorage;
30-
private AuthorizationCheckerInterface $authorizationChecker;
31-
private AuthenticationTrustResolverInterface $trustResolver;
32-
private ?RoleHierarchyInterface $roleHierarchy;
33-
private ?ValidatorInterface $validator;
34-
35-
public function __construct(array $configuration, ExpressionLanguage $expressionLanguage, TokenStorageInterface $tokenStorage, AuthorizationCheckerInterface $authorizationChecker, AuthenticationTrustResolverInterface $trustResolver, ?RoleHierarchyInterface $roleHierarchy = null, ?ValidatorInterface $validator = null)
36-
{
37-
$this->configuration = $configuration;
38-
$this->expressionLanguage = $expressionLanguage;
39-
$this->tokenStorage = $tokenStorage;
40-
$this->authorizationChecker = $authorizationChecker;
41-
$this->trustResolver = $trustResolver;
42-
$this->roleHierarchy = $roleHierarchy;
43-
$this->validator = $validator;
27+
public function __construct(
28+
private array $configuration,
29+
private ExpressionLanguage $expressionLanguage,
30+
private TokenStorageInterface $tokenStorage,
31+
private AuthorizationCheckerInterface $authorizationChecker,
32+
private AuthenticationTrustResolverInterface $trustResolver,
33+
private ?RoleHierarchyInterface $roleHierarchy = null,
34+
private ?ValidatorInterface $validator = null,
35+
) {
4436
}
4537

4638
public function onTransition(GuardEvent $event, string $eventName): void

Diff for: Exception/NotEnabledTransitionException.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121
*/
2222
class NotEnabledTransitionException extends TransitionException
2323
{
24-
private TransitionBlockerList $transitionBlockerList;
25-
26-
public function __construct(object $subject, string $transitionName, WorkflowInterface $workflow, TransitionBlockerList $transitionBlockerList, array $context = [])
27-
{
24+
public function __construct(
25+
object $subject,
26+
string $transitionName,
27+
WorkflowInterface $workflow,
28+
private TransitionBlockerList $transitionBlockerList,
29+
array $context = [],
30+
) {
2831
parent::__construct($subject, $transitionName, $workflow, sprintf('Transition "%s" is not enabled for workflow "%s".', $transitionName, $workflow->getName()), $context);
29-
30-
$this->transitionBlockerList = $transitionBlockerList;
3132
}
3233

3334
public function getTransitionBlockerList(): TransitionBlockerList

Diff for: Exception/TransitionException.php

+7-12
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,14 @@
1919
*/
2020
class TransitionException extends LogicException
2121
{
22-
private object $subject;
23-
private string $transitionName;
24-
private WorkflowInterface $workflow;
25-
private array $context;
26-
27-
public function __construct(object $subject, string $transitionName, WorkflowInterface $workflow, string $message, array $context = [])
28-
{
22+
public function __construct(
23+
private object $subject,
24+
private string $transitionName,
25+
private WorkflowInterface $workflow,
26+
string $message,
27+
private array $context = [],
28+
) {
2929
parent::__construct($message);
30-
31-
$this->subject = $subject;
32-
$this->transitionName = $transitionName;
33-
$this->workflow = $workflow;
34-
$this->context = $context;
3530
}
3631

3732
public function getSubject(): object

Diff for: Metadata/InMemoryMetadataStore.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@ final class InMemoryMetadataStore implements MetadataStoreInterface
2020
{
2121
use GetMetadataTrait;
2222

23-
private array $workflowMetadata;
24-
private array $placesMetadata;
2523
private \SplObjectStorage $transitionsMetadata;
2624

2725
/**
2826
* @param \SplObjectStorage<Transition, array>|null $transitionsMetadata
2927
*/
30-
public function __construct(array $workflowMetadata = [], array $placesMetadata = [], ?\SplObjectStorage $transitionsMetadata = null)
31-
{
32-
$this->workflowMetadata = $workflowMetadata;
33-
$this->placesMetadata = $placesMetadata;
28+
public function __construct(
29+
private array $workflowMetadata = [],
30+
private array $placesMetadata = [],
31+
?\SplObjectStorage $transitionsMetadata = null,
32+
) {
3433
$this->transitionsMetadata = $transitionsMetadata ?? new \SplObjectStorage();
3534
}
3635

Diff for: SupportStrategy/InstanceOfSupportStrategy.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@
1919
*/
2020
final class InstanceOfSupportStrategy implements WorkflowSupportStrategyInterface
2121
{
22-
private string $className;
23-
24-
public function __construct(string $className)
25-
{
26-
$this->className = $className;
22+
public function __construct(
23+
private string $className,
24+
) {
2725
}
2826

2927
public function supports(WorkflowInterface $workflow, object $subject): bool

Diff for: Transition.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@
1717
*/
1818
class Transition
1919
{
20-
private string $name;
2120
private array $froms;
2221
private array $tos;
2322

2423
/**
2524
* @param string|string[] $froms
2625
* @param string|string[] $tos
2726
*/
28-
public function __construct(string $name, string|array $froms, string|array $tos)
29-
{
30-
$this->name = $name;
27+
public function __construct(
28+
private string $name,
29+
string|array $froms,
30+
string|array $tos,
31+
) {
3132
$this->froms = (array) $froms;
3233
$this->tos = (array) $tos;
3334
}

Diff for: TransitionBlocker.php

+5-9
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,17 @@ final class TransitionBlocker
2020
public const BLOCKED_BY_EXPRESSION_GUARD_LISTENER = '326a1e9c-0c12-11e8-ba89-0ed5f89f718b';
2121
public const UNKNOWN = 'e8b5bbb9-5913-4b98-bfa6-65dbd228a82a';
2222

23-
private string $message;
24-
private string $code;
25-
private array $parameters;
26-
2723
/**
2824
* @param string $code Code is a machine-readable string, usually an UUID
2925
* @param array $parameters This is useful if you would like to pass around the condition values, that
3026
* blocked the transition. E.g. for a condition "distance must be larger than
3127
* 5 miles", you might want to pass around the value of 5.
3228
*/
33-
public function __construct(string $message, string $code, array $parameters = [])
34-
{
35-
$this->message = $message;
36-
$this->code = $code;
37-
$this->parameters = $parameters;
29+
public function __construct(
30+
private string $message,
31+
private string $code,
32+
private array $parameters = [],
33+
) {
3834
}
3935

4036
/**

Diff for: Validator/WorkflowValidator.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020
*/
2121
class WorkflowValidator implements DefinitionValidatorInterface
2222
{
23-
private bool $singlePlace;
24-
25-
public function __construct(bool $singlePlace = false)
26-
{
27-
$this->singlePlace = $singlePlace;
23+
public function __construct(
24+
private bool $singlePlace = false,
25+
) {
2826
}
2927

3028
public function validate(Definition $definition, string $name): void

Diff for: Workflow.php

+11-17
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,22 @@ class Workflow implements WorkflowInterface
5252
WorkflowEvents::ANNOUNCE => self::DISABLE_ANNOUNCE_EVENT,
5353
];
5454

55-
private Definition $definition;
5655
private MarkingStoreInterface $markingStore;
57-
private ?EventDispatcherInterface $dispatcher;
58-
private string $name;
5956

6057
/**
61-
* When `null` fire all events (the default behaviour).
62-
* Setting this to an empty array `[]` means no events are dispatched (except the {@see GuardEvent}).
63-
* Passing an array with WorkflowEvents will allow only those events to be dispatched plus
64-
* the {@see GuardEvent}.
65-
*
66-
* @var array|string[]|null
58+
* @param array|string[]|null $eventsToDispatch When `null` fire all events (the default behaviour).
59+
* Setting this to an empty array `[]` means no events are dispatched (except the {@see GuardEvent}).
60+
* Passing an array with WorkflowEvents will allow only those events to be dispatched plus
61+
* the {@see GuardEvent}.
6762
*/
68-
private ?array $eventsToDispatch = null;
69-
70-
public function __construct(Definition $definition, ?MarkingStoreInterface $markingStore = null, ?EventDispatcherInterface $dispatcher = null, string $name = 'unnamed', ?array $eventsToDispatch = null)
71-
{
72-
$this->definition = $definition;
63+
public function __construct(
64+
private Definition $definition,
65+
?MarkingStoreInterface $markingStore = null,
66+
private ?EventDispatcherInterface $dispatcher = null,
67+
private string $name = 'unnamed',
68+
private ?array $eventsToDispatch = null,
69+
) {
7370
$this->markingStore = $markingStore ?? new MethodMarkingStore();
74-
$this->dispatcher = $dispatcher;
75-
$this->name = $name;
76-
$this->eventsToDispatch = $eventsToDispatch;
7771
}
7872

7973
public function getMarking(object $subject, array $context = []): Marking

0 commit comments

Comments
 (0)