Skip to content
Permalink
Browse files

minor #32223 [Workflow] Added parameter typhint where possible (lyrixx)

This PR was merged into the 5.0-dev branch.

Discussion
----------

[Workflow] Added parameter typhint where possible

| Q             | A
| ------------- | ---
| Branch?       | mas
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | ye
| Fixed tickets | partially #32179
| License       | MIT
| Doc PR        |

Commits
-------

62e615b [Workflow] Added parameter typhint where possible
  • Loading branch information...
fabpot committed Jul 5, 2019
2 parents e5adbe6 + 62e615b commit 78dc3c30dc02080b14175f13d7bd4dba69959beb
@@ -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;
@@ -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
*
* @return string The representation of the workflow
*/
public function dump(Definition $definition, Marking $marking = null, array $options = []);
@@ -236,7 +236,7 @@ protected function endDot()
/**
* @internal
*/
protected function dotize($id)
protected function dotize(string $id)
{
return hash('sha1', $id);
}
@@ -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;
@@ -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);
}
@@ -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>
@@ -27,9 +28,9 @@ class GuardEvent extends Event
/**
* {@inheritdoc}
*/
public function __construct($subject, Marking $marking, Transition $transition, $workflowName = null)
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();
}
@@ -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;
@@ -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;
@@ -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()));
@@ -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);
@@ -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()));
}
@@ -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]);
}
@@ -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);
@@ -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();
@@ -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;
@@ -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)) {
@@ -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;
}
@@ -18,5 +18,5 @@
*/
interface WorkflowSupportStrategyInterface
{
public function supports(WorkflowInterface $workflow, $subject): bool;
public function supports(WorkflowInterface $workflow, object $subject): bool;
}
@@ -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);
}
@@ -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) {
@@ -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(), []);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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)) {
@@ -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;
@@ -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();
@@ -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;
@@ -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();
@@ -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;
@@ -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;
@@ -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;

0 comments on commit 78dc3c3

Please sign in to comment.
You can’t perform that action at this time.