Skip to content

[Workflow] Added parameter typhint where possible #32223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/Symfony/Component/Workflow/DefinitionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,9 @@ public function setInitialPlaces($initialPlaces)
}

/**
* @param string $place
*
* @return $this
*/
public function addPlace($place)
public function addPlace(string $place)
{
if (!$this->places) {
$this->initialPlaces = $place;
Expand Down
4 changes: 0 additions & 4 deletions src/Symfony/Component/Workflow/Dumper/DumperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ interface DumperInterface
/**
* Dumps a workflow definition.
*
* @param Definition $definition A Definition instance
* @param Marking|null $marking A Marking instance
* @param array $options An array of options
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be done on a lower branch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's minimize the changes that don't add value to the code. Keeping that in lower branches is fine by me.

* @return string The representation of the workflow
*/
public function dump(Definition $definition, Marking $marking = null, array $options = []);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Workflow/Dumper/GraphvizDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ protected function endDot()
/**
* @internal
*/
protected function dotize($id)
protected function dotize(string $id)
{
return hash('sha1', $id);
}
Expand Down
7 changes: 2 additions & 5 deletions src/Symfony/Component/Workflow/Event/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ class Event extends BaseEvent
private $transition;
private $workflow;

/**
* @param object $subject
*/
public function __construct($subject, Marking $marking, Transition $transition = null, WorkflowInterface $workflow = null)
public function __construct(object $subject, Marking $marking, Transition $transition = null, WorkflowInterface $workflow = null)
{
$this->subject = $subject;
$this->marking = $marking;
Expand Down Expand Up @@ -63,7 +60,7 @@ public function getWorkflowName()
return $this->workflow->getName();
}

public function getMetadata(string $key, $subject)
public function getMetadata(string $key, object $subject)
{
return $this->workflow->getMetadataStore()->getMetadata($key, $subject);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Symfony/Component/Workflow/Event/GuardEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\Workflow\Transition;
use Symfony\Component\Workflow\TransitionBlocker;
use Symfony\Component\Workflow\TransitionBlockerList;
use Symfony\Component\Workflow\WorkflowInterface;

/**
* @author Fabien Potencier <fabien@symfony.com>
Expand All @@ -27,9 +28,9 @@ class GuardEvent extends Event
/**
* {@inheritdoc}
*/
public function __construct($subject, Marking $marking, Transition $transition, $workflowName = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The $workflowName => WorkflowInterface $workflow = null change should be done on a lower branch.

public function __construct(object $subject, Marking $marking, Transition $transition, WorkflowInterface $workflow = null)
{
parent::__construct($subject, $marking, $transition, $workflowName);
parent::__construct($subject, $marking, $transition, $workflow);

$this->transitionBlockerList = new TransitionBlockerList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@
class GuardExpression
{
private $transition;

private $expression;

/**
* @param string $expression
*/
public function __construct(Transition $transition, $expression)
public function __construct(Transition $transition, string $expression)
{
$this->transition = $transition;
$this->expression = $expression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(array $configuration, ExpressionLanguage $expression
$this->validator = $validator;
}

public function onTransition(GuardEvent $event, $eventName)
public function onTransition(GuardEvent $event, string $eventName)
{
if (!isset($this->configuration[$eventName])) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class NotEnabledTransitionException extends TransitionException
{
private $transitionBlockerList;

public function __construct($subject, string $transitionName, WorkflowInterface $workflow, TransitionBlockerList $transitionBlockerList)
public function __construct(object $subject, string $transitionName, WorkflowInterface $workflow, TransitionBlockerList $transitionBlockerList)
{
parent::__construct($subject, $transitionName, $workflow, sprintf('Transition "%s" is not enabled for workflow "%s".', $transitionName, $workflow->getName()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TransitionException extends LogicException
private $transitionName;
private $workflow;

public function __construct($subject, string $transitionName, WorkflowInterface $workflow, string $message)
public function __construct(object $subject, string $transitionName, WorkflowInterface $workflow, string $message)
{
parent::__construct($message);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class UndefinedTransitionException extends TransitionException
{
public function __construct($subject, string $transitionName, WorkflowInterface $workflow)
public function __construct(object $subject, string $transitionName, WorkflowInterface $workflow)
{
parent::__construct($subject, $transitionName, $workflow, sprintf('Transition "%s" is not defined for workflow "%s".', $transitionName, $workflow->getName()));
}
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Workflow/Marking.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ public function __construct(array $representation = [])
}
}

public function mark($place)
public function mark(string $place)
{
$this->places[$place] = 1;
}

public function unmark($place)
public function unmark(string $place)
{
unset($this->places[$place]);
}

public function has($place)
public function has(string $place)
{
return isset($this->places[$place]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(bool $singleState = false, string $property = 'marki
/**
* {@inheritdoc}
*/
public function getMarking($subject): Marking
public function getMarking(object $subject): Marking
{
$method = 'get'.ucfirst($this->property);

Expand All @@ -70,7 +70,7 @@ public function getMarking($subject): Marking
/**
* {@inheritdoc}
*/
public function setMarking($subject, Marking $marking, array $context = [])
public function setMarking(object $subject, Marking $marking, array $context = [])
{
$marking = $marking->getPlaces();

Expand Down
9 changes: 2 additions & 7 deletions src/Symfony/Component/Workflow/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ public function addWorkflow(WorkflowInterface $workflow, WorkflowSupportStrategy
}

/**
* @param object $subject
* @param string|null $workflowName
*
* @return Workflow
*/
public function get($subject, $workflowName = null)
public function get(object $subject, string $workflowName = null)
{
$matched = null;

Expand All @@ -54,11 +51,9 @@ public function get($subject, $workflowName = null)
}

/**
* @param object $subject
*
* @return Workflow[]
*/
public function all($subject): array
public function all(object $subject): array
{
$matched = [];
foreach ($this->workflows as list($workflow, $supportStrategy)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(string $className)
/**
* {@inheritdoc}
*/
public function supports(WorkflowInterface $workflow, $subject): bool
public function supports(WorkflowInterface $workflow, object $subject): bool
{
return $subject instanceof $this->className;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
*/
interface WorkflowSupportStrategyInterface
{
public function supports(WorkflowInterface $workflow, $subject): bool;
public function supports(WorkflowInterface $workflow, object $subject): bool;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
interface DefinitionValidatorInterface
{
/**
* @param Definition $definition
* @param string $name
*
* @throws InvalidDefinitionException on invalid definition
*/
public function validate(Definition $definition, $name);
public function validate(Definition $definition, string $name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
class StateMachineValidator implements DefinitionValidatorInterface
{
public function validate(Definition $definition, $name)
public function validate(Definition $definition, string $name)
{
$transitionFromNames = [];
foreach ($definition->getTransitions() as $transition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(bool $singlePlace = false)
$this->singlePlace = $singlePlace;
}

public function validate(Definition $definition, $name)
public function validate(Definition $definition, string $name)
{
// Make sure all transitions for one place has unique name.
$places = array_fill_keys($definition->getPlaces(), []);
Expand Down
26 changes: 13 additions & 13 deletions src/Symfony/Component/Workflow/Workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(Definition $definition, MarkingStoreInterface $marki
/**
* {@inheritdoc}
*/
public function getMarking($subject)
public function getMarking(object $subject)
{
$marking = $this->markingStore->getMarking($subject);

Expand Down Expand Up @@ -91,7 +91,7 @@ public function getMarking($subject)
/**
* {@inheritdoc}
*/
public function can($subject, $transitionName)
public function can(object $subject, string $transitionName)
{
$transitions = $this->definition->getTransitions();
$marking = $this->getMarking($subject);
Expand All @@ -114,7 +114,7 @@ public function can($subject, $transitionName)
/**
* {@inheritdoc}
*/
public function buildTransitionBlockerList($subject, string $transitionName): TransitionBlockerList
public function buildTransitionBlockerList(object $subject, string $transitionName): TransitionBlockerList
{
$transitions = $this->definition->getTransitions();
$marking = $this->getMarking($subject);
Expand Down Expand Up @@ -150,7 +150,7 @@ public function buildTransitionBlockerList($subject, string $transitionName): Tr
/**
* {@inheritdoc}
*/
public function apply($subject, $transitionName, array $context = [])
public function apply(object $subject, string $transitionName, array $context = [])
{
$marking = $this->getMarking($subject);

Expand Down Expand Up @@ -202,7 +202,7 @@ public function apply($subject, $transitionName, array $context = [])
/**
* {@inheritdoc}
*/
public function getEnabledTransitions($subject)
public function getEnabledTransitions(object $subject)
{
$enabledTransitions = [];
$marking = $this->getMarking($subject);
Expand Down Expand Up @@ -249,7 +249,7 @@ public function getMetadataStore(): MetadataStoreInterface
return $this->definition->getMetadataStore();
}

private function buildTransitionBlockerListForTransition($subject, Marking $marking, Transition $transition)
private function buildTransitionBlockerListForTransition(object $subject, Marking $marking, Transition $transition)
{
foreach ($transition->getFroms() as $place) {
if (!$marking->has($place)) {
Expand All @@ -272,7 +272,7 @@ private function buildTransitionBlockerListForTransition($subject, Marking $mark
return new TransitionBlockerList();
}

private function guardTransition($subject, Marking $marking, Transition $transition): ?GuardEvent
private function guardTransition(object $subject, Marking $marking, Transition $transition): ?GuardEvent
{
if (null === $this->dispatcher) {
return null;
Expand All @@ -287,7 +287,7 @@ private function guardTransition($subject, Marking $marking, Transition $transit
return $event;
}

private function leave($subject, Transition $transition, Marking $marking): void
private function leave(object $subject, Transition $transition, Marking $marking): void
{
$places = $transition->getFroms();

Expand All @@ -307,7 +307,7 @@ private function leave($subject, Transition $transition, Marking $marking): void
}
}

private function transition($subject, Transition $transition, Marking $marking, array $context): array
private function transition(object $subject, Transition $transition, Marking $marking, array $context): array
{
if (null === $this->dispatcher) {
return $context;
Expand All @@ -323,7 +323,7 @@ private function transition($subject, Transition $transition, Marking $marking,
return $event->getContext();
}

private function enter($subject, Transition $transition, Marking $marking): void
private function enter(object $subject, Transition $transition, Marking $marking): void
{
$places = $transition->getTos();

Expand All @@ -343,7 +343,7 @@ private function enter($subject, Transition $transition, Marking $marking): void
}
}

private function entered($subject, Transition $transition = null, Marking $marking): void
private function entered(object $subject, ?Transition $transition, Marking $marking): void
{
if (null === $this->dispatcher) {
return;
Expand All @@ -361,7 +361,7 @@ private function entered($subject, Transition $transition = null, Marking $marki
}
}

private function completed($subject, Transition $transition, Marking $marking): void
private function completed(object $subject, Transition $transition, Marking $marking): void
{
if (null === $this->dispatcher) {
return;
Expand All @@ -374,7 +374,7 @@ private function completed($subject, Transition $transition, Marking $marking):
$this->dispatcher->dispatch($event, sprintf('workflow.%s.completed.%s', $this->name, $transition->getName()));
}

private function announce($subject, Transition $initialTransition, Marking $marking): void
private function announce(object $subject, Transition $initialTransition, Marking $marking): void
{
if (null === $this->dispatcher) {
return;
Expand Down
Loading