diff --git a/README.md b/README.md index 39fbbc7..fea1820 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,12 @@ Add the dependency to `phpmentors/workflower` into your `composer.json` file as composer require phpmentors/workflower "1.4.*" ``` +when your PHP version >= 8.0, you can install `1.5.*` + +``` +composer require phpmentors/workflower "1.5.*" +``` + ## Documentation * [Quick Start Guide](https://github.com/phpmentors-jp/workflower/blob/master/docs/GUIDE.md) diff --git a/composer.json b/composer.json index 28cf1ce..7e54569 100644 --- a/composer.json +++ b/composer.json @@ -11,14 +11,15 @@ } ], "require": { - "php": ">=5.3.9", + "php": "^8.0", "phpmentors/domain-kata": "~1.4", "piece/stagehand-fsm": "~2.6", - "symfony/expression-language": "~2.8|~3.0|~4.0" + "symfony/expression-language": "~3.4|~4.0|~5.0", + "ext-dom": "*" }, "require-dev": { - "phake/phake": "~2.0", - "phpunit/phpunit": "~4.0" + "phake/phake": "^4.0", + "phpunit/phpunit": "~8.0" }, "autoload": { "psr-4": { diff --git a/src/Definition/Bpmn2File.php b/src/Definition/Bpmn2File.php index 8bb6c71..7afda60 100644 --- a/src/Definition/Bpmn2File.php +++ b/src/Definition/Bpmn2File.php @@ -23,7 +23,7 @@ class Bpmn2File implements EntityInterface, IdentifiableInterface private $file; /** - * @param string $file + * @param string $file */ public function __construct($file) { @@ -47,8 +47,7 @@ public function getFile() } /** - * @param string $file - * + * @param string $file * @return string */ public static function getWorkflowId($file) diff --git a/src/Definition/Bpmn2Reader.php b/src/Definition/Bpmn2Reader.php index c36d8d4..a4d7769 100644 --- a/src/Definition/Bpmn2Reader.php +++ b/src/Definition/Bpmn2Reader.php @@ -19,8 +19,7 @@ class Bpmn2Reader implements ServiceInterface { /** - * @param string $file - * + * @param string $file * @return Workflow * * @throws IdAttributeNotFoundException @@ -37,8 +36,7 @@ public function read($file) } /** - * @param string $source - * + * @param string $source * @return Workflow * * @throws IdAttributeNotFoundException @@ -57,9 +55,8 @@ public function readSource($source) } /** - * @param DOMDocument $document - * @param int|string $workflowId - * + * @param DOMDocument $document + * @param int|string $workflowId * @return Workflow * * @throws IdAttributeNotFoundException @@ -85,9 +82,9 @@ private function readDocument(\DOMDocument $document, $workflowId = null) } } - $flowObjectRoles = array(); + $flowObjectRoles = []; foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'lane') as $element) { - if (!$element->hasAttribute('id')) { + if (! $element->hasAttribute('id')) { throw $this->createIdAttributeNotFoundException($element, $workflowId); } @@ -105,18 +102,18 @@ private function readDocument(\DOMDocument $document, $workflowId = null) $workflowBuilder->addRole(Workflow::DEFAULT_ROLE_ID); } - $messages = array(); + $messages = []; foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'message') as $element) { - if (!$element->hasAttribute('id')) { + if (! $element->hasAttribute('id')) { throw $this->createIdAttributeNotFoundException($element, $workflowId); } $messages[$element->getAttribute('id')] = $element->getAttribute('name'); } - $operations = array(); + $operations = []; foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'operation') as $element) { - if (!$element->hasAttribute('id')) { + if (! $element->hasAttribute('id')) { throw $this->createIdAttributeNotFoundException($element, $workflowId); } @@ -124,7 +121,7 @@ private function readDocument(\DOMDocument $document, $workflowId = null) } foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'startEvent') as $element) { - if (!$element->hasAttribute('id')) { + if (! $element->hasAttribute('id')) { throw $this->createIdAttributeNotFoundException($element, $workflowId); } @@ -137,7 +134,7 @@ private function readDocument(\DOMDocument $document, $workflowId = null) } foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'task') as $element) { - if (!$element->hasAttribute('id')) { + if (! $element->hasAttribute('id')) { throw $this->createIdAttributeNotFoundException($element, $workflowId); } @@ -150,7 +147,7 @@ private function readDocument(\DOMDocument $document, $workflowId = null) } foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'serviceTask') as $element) { - if (!$element->hasAttribute('id')) { + if (! $element->hasAttribute('id')) { throw $this->createIdAttributeNotFoundException($element, $workflowId); } @@ -164,7 +161,7 @@ private function readDocument(\DOMDocument $document, $workflowId = null) } foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'sendTask') as $element) { - if (!$element->hasAttribute('id')) { + if (! $element->hasAttribute('id')) { throw $this->createIdAttributeNotFoundException($element, $workflowId); } @@ -179,7 +176,7 @@ private function readDocument(\DOMDocument $document, $workflowId = null) } foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'exclusiveGateway') as $element) { - if (!$element->hasAttribute('id')) { + if (! $element->hasAttribute('id')) { throw $this->createIdAttributeNotFoundException($element, $workflowId); } @@ -192,7 +189,7 @@ private function readDocument(\DOMDocument $document, $workflowId = null) } foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'endEvent') as $element) { - if (!$element->hasAttribute('id')) { + if (! $element->hasAttribute('id')) { throw $this->createIdAttributeNotFoundException($element, $workflowId); } @@ -200,7 +197,7 @@ private function readDocument(\DOMDocument $document, $workflowId = null) } foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'sequenceFlow') as $element) { - if (!$element->hasAttribute('id')) { + if (! $element->hasAttribute('id')) { throw $this->createIdAttributeNotFoundException($element, $workflowId); } @@ -223,9 +220,8 @@ private function readDocument(\DOMDocument $document, $workflowId = null) } /** - * @param \DOMElement $element - * @param int|string $workflowId - * + * @param \DOMElement $element + * @param int|string $workflowId * @return IdAttributeNotFoundException */ private function createIdAttributeNotFoundException(\DOMElement $element, $workflowId) @@ -234,9 +230,8 @@ private function createIdAttributeNotFoundException(\DOMElement $element, $workf } /** - * @param array $flowObjectRoles - * @param string $flowObjectId - * + * @param array $flowObjectRoles + * @param string $flowObjectId * @return string * * @since Method available since Release 1.3.0 diff --git a/src/Definition/Bpmn2WorkflowRepository.php b/src/Definition/Bpmn2WorkflowRepository.php index 971be77..5796ad1 100644 --- a/src/Definition/Bpmn2WorkflowRepository.php +++ b/src/Definition/Bpmn2WorkflowRepository.php @@ -20,7 +20,7 @@ class Bpmn2WorkflowRepository implements WorkflowRepositoryInterface /** * @var array */ - private $bpmn2Files = array(); + private $bpmn2Files = []; /** * {@inheritdoc} @@ -51,7 +51,7 @@ public function remove(EntityInterface $entity) */ public function findById($id) { - if (!array_key_exists($id, $this->bpmn2Files)) { + if (! array_key_exists($id, $this->bpmn2Files)) { return null; } diff --git a/src/Definition/ErrorToExceptionContext.php b/src/Definition/ErrorToExceptionContext.php index 3e40a4c..404d9fe 100644 --- a/src/Definition/ErrorToExceptionContext.php +++ b/src/Definition/ErrorToExceptionContext.php @@ -25,8 +25,8 @@ class ErrorToExceptionContext private $target; /** - * @param int $errorReportingLevel - * @param \Closure $target + * @param int $errorReportingLevel + * @param \Closure $target */ public function __construct($errorReportingLevel, \Closure $target) { diff --git a/src/Persistence/WorkflowSerializableInterface.php b/src/Persistence/WorkflowSerializableInterface.php index a832eeb..f827acd 100644 --- a/src/Persistence/WorkflowSerializableInterface.php +++ b/src/Persistence/WorkflowSerializableInterface.php @@ -17,7 +17,7 @@ interface WorkflowSerializableInterface extends OperationInterface, WorkflowAwareInterface { /** - * @param string $serializedWorkflow + * @param string $serializedWorkflow */ public function setSerializedWorkflow($serializedWorkflow); diff --git a/src/Persistence/WorkflowSerializerInterface.php b/src/Persistence/WorkflowSerializerInterface.php index 3e57b88..b697185 100644 --- a/src/Persistence/WorkflowSerializerInterface.php +++ b/src/Persistence/WorkflowSerializerInterface.php @@ -18,15 +18,13 @@ interface WorkflowSerializerInterface extends ServiceInterface { /** - * @param Workflow $workflow - * + * @param Workflow $workflow * @return string */ public function serialize(Workflow $workflow); /** - * @param string $workflow - * + * @param string $workflow * @return Workflow */ public function deserialize($workflow); diff --git a/src/Process/EventContext.php b/src/Process/EventContext.php index 00a55a0..5e95934 100644 --- a/src/Process/EventContext.php +++ b/src/Process/EventContext.php @@ -25,8 +25,8 @@ class EventContext implements EventContextInterface private $processContext; /** - * @param int|string $eventId - * @param ProcessContextInterface $processContext + * @param int|string $eventId + * @param ProcessContextInterface $processContext */ public function __construct($eventId, ProcessContextInterface $processContext) { diff --git a/src/Process/Process.php b/src/Process/Process.php index 21f909e..2aefd01 100644 --- a/src/Process/Process.php +++ b/src/Process/Process.php @@ -47,9 +47,9 @@ class Process implements ServiceInterface private $operationRunner; /** - * @param int|string|WorkflowContextInterface $workflowContext - * @param WorkflowRepositoryInterface $workflowRepository - * @param OperationRunnerInterface $operationRunner + * @param int|string|WorkflowContextInterface $workflowContext + * @param WorkflowRepositoryInterface $workflowRepository + * @param OperationRunnerInterface $operationRunner */ public function __construct($workflowContext, WorkflowRepositoryInterface $workflowRepository, OperationRunnerInterface $operationRunner) { @@ -59,7 +59,7 @@ public function __construct($workflowContext, WorkflowRepositoryInterface $workf } /** - * @param ExpressionLanguage $expressionLanguage + * @param ExpressionLanguage $expressionLanguage * * @since Method available since Release 1.2.0 */ @@ -69,7 +69,7 @@ public function setExpressionLanguage(ExpressionLanguage $expressionLanguage) } /** - * @param EventContextInterface $eventContext + * @param EventContextInterface $eventContext */ public function start(EventContextInterface $eventContext) { @@ -84,7 +84,7 @@ public function start(EventContextInterface $eventContext) } /** - * @param WorkItemContextInterface $workItemContext + * @param WorkItemContextInterface $workItemContext */ public function allocateWorkItem(WorkItemContextInterface $workItemContext) { @@ -97,7 +97,7 @@ public function allocateWorkItem(WorkItemContextInterface $workItemContext) } /** - * @param WorkItemContextInterface $workItemContext + * @param WorkItemContextInterface $workItemContext */ public function startWorkItem(WorkItemContextInterface $workItemContext) { @@ -110,7 +110,7 @@ public function startWorkItem(WorkItemContextInterface $workItemContext) } /** - * @param WorkItemContextInterface $workItemContext + * @param WorkItemContextInterface $workItemContext */ public function completeWorkItem(WorkItemContextInterface $workItemContext) { @@ -124,7 +124,7 @@ public function completeWorkItem(WorkItemContextInterface $workItemContext) } /** - * @param WorkItemContextInterface $workItemContext + * @param WorkItemContextInterface $workItemContext * * @throws UnexpectedActivityStateException */ @@ -184,8 +184,7 @@ private function createWorkflow() } /** - * @param Workflow $workflow - * + * @param Workflow $workflow * @return Workflow * * @since Method available since Release 1.2.0 diff --git a/src/Process/ProcessAwareInterface.php b/src/Process/ProcessAwareInterface.php index f09ca32..edd028e 100644 --- a/src/Process/ProcessAwareInterface.php +++ b/src/Process/ProcessAwareInterface.php @@ -15,7 +15,7 @@ interface ProcessAwareInterface extends OperationInterface { /** - * @param Process $process + * @param Process $process */ public function setProcess(Process $process); } diff --git a/src/Process/WorkItemContext.php b/src/Process/WorkItemContext.php index 92d9cd5..318cb9a 100644 --- a/src/Process/WorkItemContext.php +++ b/src/Process/WorkItemContext.php @@ -32,7 +32,7 @@ class WorkItemContext implements WorkItemContextInterface private $processContext; /** - * @param ParticipantInterface $participant + * @param ParticipantInterface $participant */ public function __construct(ParticipantInterface $participant) { @@ -40,7 +40,7 @@ public function __construct(ParticipantInterface $participant) } /** - * @param int|string $activityId + * @param int|string $activityId */ public function setActivityId($activityId) { @@ -48,7 +48,7 @@ public function setActivityId($activityId) } /** - * @param ProcessContextInterface $processContext + * @param ProcessContextInterface $processContext */ public function setProcessContext(ProcessContextInterface $processContext) { @@ -64,7 +64,7 @@ public function getActivityId() } /** - * @param ParticipantInterface $participant + * @param ParticipantInterface $participant * * @since Method available since Release 1.1.0 */ diff --git a/src/Process/WorkflowAwareInterface.php b/src/Process/WorkflowAwareInterface.php index 8b40086..27b8d1d 100644 --- a/src/Process/WorkflowAwareInterface.php +++ b/src/Process/WorkflowAwareInterface.php @@ -17,7 +17,7 @@ interface WorkflowAwareInterface extends OperationInterface { /** - * @param Workflow $workflow + * @param Workflow $workflow */ public function setWorkflow(Workflow $workflow); } diff --git a/src/Workflow/AccessDeniedException.php b/src/Workflow/AccessDeniedException.php index fd32b2c..244f396 100644 --- a/src/Workflow/AccessDeniedException.php +++ b/src/Workflow/AccessDeniedException.php @@ -15,8 +15,8 @@ class AccessDeniedException extends \RuntimeException { /** - * @param string $message - * @param \Exception $previous + * @param string $message + * @param \Exception $previous */ public function __construct($message = 'Access Denied', \Exception $previous = null) { diff --git a/src/Workflow/Activity/ActivityInterface.php b/src/Workflow/Activity/ActivityInterface.php index b883aae..c1de80d 100644 --- a/src/Workflow/Activity/ActivityInterface.php +++ b/src/Workflow/Activity/ActivityInterface.php @@ -41,8 +41,7 @@ public function isCompletable(); public function isEnded(); /** - * @param int $index - * + * @param int $index * @return WorkItemInterface * * @throws \OutOfBoundsException diff --git a/src/Workflow/Activity/SendTask.php b/src/Workflow/Activity/SendTask.php index cf1d858..5bc81b0 100644 --- a/src/Workflow/Activity/SendTask.php +++ b/src/Workflow/Activity/SendTask.php @@ -32,10 +32,10 @@ class SendTask extends Task implements MessageInterface, OperationalInterface private $operation; /** - * @param int|string $id - * @param Role $role - * @param int|string $operation - * @param string $name + * @param int|string $id + * @param Role $role + * @param int|string $operation + * @param string $name */ public function __construct($id, Role $role, $message, $operation, $name = null) { @@ -48,23 +48,24 @@ public function __construct($id, Role $role, $message, $operation, $name = null) /** * {@inheritdoc} */ - public function serialize() + public function __serialize() { - return serialize(array( + return serialize([ get_parent_class($this) => parent::serialize(), 'message' => $this->message, 'operation' => $this->operation, - )); + ]); } /** * {@inheritdoc} */ - public function unserialize($serialized) + public function __unserialize($serialized) { foreach (unserialize($serialized) as $name => $value) { if ($name == get_parent_class($this)) { parent::unserialize($value); + continue; } diff --git a/src/Workflow/Activity/ServiceTask.php b/src/Workflow/Activity/ServiceTask.php index b317d95..8828518 100644 --- a/src/Workflow/Activity/ServiceTask.php +++ b/src/Workflow/Activity/ServiceTask.php @@ -26,10 +26,10 @@ class ServiceTask extends Task implements OperationalInterface private $operation; /** - * @param int|string $id - * @param Role $role - * @param int|string $operation - * @param string $name + * @param int|string $id + * @param Role $role + * @param int|string $operation + * @param string $name */ public function __construct($id, Role $role, $operation, $name = null) { @@ -41,22 +41,23 @@ public function __construct($id, Role $role, $operation, $name = null) /** * {@inheritdoc} */ - public function serialize() + public function __serialize() { - return serialize(array( + return serialize([ get_parent_class($this) => parent::serialize(), 'operation' => $this->operation, - )); + ]); } /** * {@inheritdoc} */ - public function unserialize($serialized) + public function __unserialize($serialized) { foreach (unserialize($serialized) as $name => $value) { if ($name == get_parent_class($this)) { parent::unserialize($value); + continue; } diff --git a/src/Workflow/Activity/Task.php b/src/Workflow/Activity/Task.php index 137d3d8..34ce81b 100644 --- a/src/Workflow/Activity/Task.php +++ b/src/Workflow/Activity/Task.php @@ -16,7 +16,7 @@ use PHPMentors\Workflower\Workflow\Participant\ParticipantInterface; use PHPMentors\Workflower\Workflow\Participant\Role; -class Task implements ActivityInterface, \Serializable +class Task implements ActivityInterface { /** * @var int|string @@ -36,7 +36,7 @@ class Task implements ActivityInterface, \Serializable /** * @var WorkItemInterface[] */ - private $workItems = array(); + private $workItems = []; /** * @var int|string @@ -44,9 +44,9 @@ class Task implements ActivityInterface, \Serializable private $defaultSequenceFlowId; /** - * @param int|string $id - * @param Role $role - * @param string $name + * @param int|string $id + * @param Role $role + * @param string $name */ public function __construct($id, Role $role, $name = null) { @@ -58,21 +58,21 @@ public function __construct($id, Role $role, $name = null) /** * {@inheritdoc} */ - public function serialize() + public function __serialize() { - return serialize(array( + return serialize([ 'id' => $this->id, 'role' => $this->role, 'name' => $this->name, 'workItems' => $this->workItems, 'defaultSequenceFlowId' => $this->defaultSequenceFlowId, - )); + ]); } /** * {@inheritdoc} */ - public function unserialize($serialized) + public function __unserialize($serialized) { foreach (unserialize($serialized) as $name => $value) { if (property_exists($this, $name)) { @@ -112,7 +112,7 @@ public function getName() */ public function equals(EntityInterface $target) { - if (!($target instanceof self)) { + if (! ($target instanceof self)) { return false; } @@ -236,7 +236,7 @@ public function getEndResult() */ public function createWorkItem() { - if (!(count($this->workItems) == 0 || $this->isEnded())) { + if (! (count($this->workItems) == 0 || $this->isEnded())) { throw new UnexpectedActivityStateException(sprintf('The current work item of the activity "%s" is not ended.', $this->getId())); } @@ -248,7 +248,7 @@ public function createWorkItem() */ public function allocate(ParticipantInterface $participant) { - if (!$this->isAllocatable()) { + if (! $this->isAllocatable()) { throw new UnexpectedActivityStateException(sprintf('The current work item of the activity "%s" is not allocatable.', $this->getId())); } @@ -260,7 +260,7 @@ public function allocate(ParticipantInterface $participant) */ public function start() { - if (!$this->isStartable()) { + if (! $this->isStartable()) { throw new UnexpectedActivityStateException(sprintf('The current work item of the activity "%s" is not startable.', $this->getId())); } @@ -272,7 +272,7 @@ public function start() */ public function complete(ParticipantInterface $participant) { - if (!$this->isCompletable()) { + if (! $this->isCompletable()) { throw new UnexpectedActivityStateException(sprintf('The current work item of the activity "%s" is not completable.', $this->getId())); } @@ -316,7 +316,7 @@ public function isEnded() */ public function getWorkItem($index) { - if (!array_key_exists($index, $this->workItems)) { + if (! array_key_exists($index, $this->workItems)) { throw new \OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, count($this->workItems) - 1)); } diff --git a/src/Workflow/Activity/WorkItem.php b/src/Workflow/Activity/WorkItem.php index cabc586..90a5b16 100644 --- a/src/Workflow/Activity/WorkItem.php +++ b/src/Workflow/Activity/WorkItem.php @@ -5,7 +5,7 @@ use PHPMentors\Workflower\Workflow\Participant\LoggedParticipant; use PHPMentors\Workflower\Workflow\Participant\ParticipantInterface; -class WorkItem implements WorkItemInterface, \Serializable +class WorkItem implements WorkItemInterface { /** * @var string @@ -55,9 +55,9 @@ public function __construct() /** * {@inheritdoc} */ - public function serialize() + public function __serialize() { - return serialize(array( + return serialize([ 'currentState' => $this->currentState, 'participant' => $this->participant === null ? null : ($this->participant instanceof LoggedParticipant ? $this->participant : new LoggedParticipant($this->participant)), 'creationDate' => $this->creationDate, @@ -66,13 +66,13 @@ public function serialize() 'endDate' => $this->endDate, 'endParticipant' => $this->endParticipant === null ? null : ($this->endParticipant instanceof LoggedParticipant ? $this->endParticipant : new LoggedParticipant($this->endParticipant)), 'endResult' => $this->endResult, - )); + ]); } /** * {@inheritdoc} */ - public function unserialize($serialized) + public function __unserialize($serialized) { foreach (unserialize($serialized) as $name => $value) { if (property_exists($this, $name)) { diff --git a/src/Workflow/Activity/WorkItemInterface.php b/src/Workflow/Activity/WorkItemInterface.php index 34a75b7..5b6237a 100644 --- a/src/Workflow/Activity/WorkItemInterface.php +++ b/src/Workflow/Activity/WorkItemInterface.php @@ -18,9 +18,13 @@ interface WorkItemInterface extends EntityInterface { const STATE_CREATED = 'created'; + const STATE_ALLOCATED = 'allocated'; + const STATE_STARTED = 'started'; + const STATE_ENDED = 'ended'; + const END_RESULT_COMPLETION = 'completion'; /** @@ -64,14 +68,14 @@ public function getEndParticipant(); public function getEndResult(); /** - * @param ParticipantInterface $participant + * @param ParticipantInterface $participant */ public function allocate(ParticipantInterface $participant); public function start(); /** - * @param ParticipantInterface $participant + * @param ParticipantInterface $participant */ public function complete(ParticipantInterface $participant); } diff --git a/src/Workflow/ActivityLog.php b/src/Workflow/ActivityLog.php index 16f5696..6022395 100644 --- a/src/Workflow/ActivityLog.php +++ b/src/Workflow/ActivityLog.php @@ -29,7 +29,7 @@ class ActivityLog implements EntityInterface private $workItem; /** - * @param ActivityInterface $activity + * @param ActivityInterface $activity */ public function __construct(ActivityInterface $activity) { @@ -45,7 +45,7 @@ public function getActivity() } /** - * @param WorkItemInterface $workItem + * @param WorkItemInterface $workItem */ public function setWorkItem(WorkItemInterface $workItem) { diff --git a/src/Workflow/ActivityLogCollection.php b/src/Workflow/ActivityLogCollection.php index 4520bba..6f7495a 100644 --- a/src/Workflow/ActivityLogCollection.php +++ b/src/Workflow/ActivityLogCollection.php @@ -15,18 +15,19 @@ use PHPMentors\DomainKata\Entity\EntityCollectionInterface; use PHPMentors\DomainKata\Entity\EntityInterface; use PHPMentors\Workflower\Workflow\Activity\ActivityInterface; +use Traversable; class ActivityLogCollection implements EntityCollectionInterface { /** * @var ActivityLog[] */ - private $activityLogs = array(); + private $activityLogs = []; /** * @var array */ - private $lastWorkItemIndexByActivity = array(); + private $lastWorkItemIndexByActivity = []; /** * {@inheritdoc} @@ -38,7 +39,7 @@ public function add(EntityInterface $entity) $this->activityLogs[] = $entity; if (array_key_exists($entity->getActivity()->getId(), $this->lastWorkItemIndexByActivity)) { - ++$this->lastWorkItemIndexByActivity[$entity->getActivity()->getId()]; + $this->lastWorkItemIndexByActivity[$entity->getActivity()->getId()]++; } else { $this->lastWorkItemIndexByActivity[$entity->getActivity()->getId()] = 0; } @@ -53,7 +54,7 @@ public function add(EntityInterface $entity) */ public function get($key) { - if (!array_key_exists($key, $this->activityLogs)) { + if (! array_key_exists($key, $this->activityLogs)) { return null; } @@ -71,7 +72,7 @@ public function remove(EntityInterface $entity) /** * {@inheritdoc} */ - public function count() + public function count(): int { return count($this->activityLogs); } @@ -79,7 +80,7 @@ public function count() /** * {@inheritdoc} */ - public function getIterator() + public function getIterator(): Traversable { return new \ArrayIterator($this->activityLogs); } diff --git a/src/Workflow/Connection/SequenceFlow.php b/src/Workflow/Connection/SequenceFlow.php index 02dec21..074547a 100644 --- a/src/Workflow/Connection/SequenceFlow.php +++ b/src/Workflow/Connection/SequenceFlow.php @@ -18,7 +18,7 @@ use PHPMentors\Workflower\Workflow\Element\TransitionalInterface; use Symfony\Component\ExpressionLanguage\Expression; -class SequenceFlow implements ConnectingObjectInterface, \Serializable +class SequenceFlow implements ConnectingObjectInterface { /** * @var int|string @@ -47,10 +47,10 @@ class SequenceFlow implements ConnectingObjectInterface, \Serializable /** * @param int|string - * @param TransitionalInterface $source - * @param FlowObjectInterface $destination - * @param string $name - * @param Expression $condition + * @param TransitionalInterface $source + * @param FlowObjectInterface $destination + * @param string $name + * @param Expression $condition */ public function __construct($id, TransitionalInterface $source, FlowObjectInterface $destination, $name = null, Expression $condition = null) { @@ -64,21 +64,21 @@ public function __construct($id, TransitionalInterface $source, FlowObjectInterf /** * {@inheritdoc} */ - public function serialize() + public function __serialize() { - return serialize(array( + return serialize([ 'id' => $this->id, 'name' => $this->name, 'source' => $this->source, 'destination' => $this->destination, 'condition' => $this->condition, - )); + ]); } /** * {@inheritdoc} */ - public function unserialize($serialized) + public function __unserialize($serialized) { foreach (unserialize($serialized) as $name => $value) { if (property_exists($this, $name)) { @@ -134,7 +134,7 @@ public function getCondition() */ public function equals(EntityInterface $target) { - if (!($target instanceof self)) { + if (! ($target instanceof self)) { return false; } diff --git a/src/Workflow/Element/ConditionalInterface.php b/src/Workflow/Element/ConditionalInterface.php index 31e725e..581f595 100644 --- a/src/Workflow/Element/ConditionalInterface.php +++ b/src/Workflow/Element/ConditionalInterface.php @@ -15,7 +15,7 @@ interface ConditionalInterface extends OperationInterface { /** - * @param int|string $sequenceFlowId + * @param int|string $sequenceFlowId */ public function setDefaultSequenceFlowId($sequenceFlowId); diff --git a/src/Workflow/Element/ConnectingObjectCollection.php b/src/Workflow/Element/ConnectingObjectCollection.php index 7d8bf11..7de757d 100644 --- a/src/Workflow/Element/ConnectingObjectCollection.php +++ b/src/Workflow/Element/ConnectingObjectCollection.php @@ -14,28 +14,29 @@ use PHPMentors\DomainKata\Entity\EntityCollectionInterface; use PHPMentors\DomainKata\Entity\EntityInterface; +use Traversable; -class ConnectingObjectCollection implements EntityCollectionInterface, \Serializable +class ConnectingObjectCollection implements EntityCollectionInterface { /** * @var array */ - private $connectingObjects = array(); + private $connectingObjects = []; /** * {@inheritdoc} */ - public function serialize() + public function __serialize() { - return serialize(array( + return serialize([ 'connectingObjects' => $this->connectingObjects, - )); + ]); } /** * {@inheritdoc} */ - public function unserialize($serialized) + public function __unserialize($serialized) { foreach (unserialize($serialized) as $name => $value) { if (property_exists($this, $name)) { @@ -61,7 +62,7 @@ public function add(EntityInterface $entity) */ public function get($key) { - if (!array_key_exists($key, $this->connectingObjects)) { + if (! array_key_exists($key, $this->connectingObjects)) { return null; } @@ -79,7 +80,7 @@ public function remove(EntityInterface $entity) /** * {@inheritdoc} */ - public function count() + public function count(): int { return count($this->connectingObjects); } @@ -87,14 +88,13 @@ public function count() /** * {@inheritdoc} */ - public function getIterator() + public function getIterator(): Traversable { return new \ArrayIterator($this->connectingObjects); } /** - * @param TransitionalInterface $flowObject - * + * @param TransitionalInterface $flowObject * @return ConnectingObjectCollection */ public function filterBySource(TransitionalInterface $flowObject) diff --git a/src/Workflow/Element/FlowObjectCollection.php b/src/Workflow/Element/FlowObjectCollection.php index b022867..755a6ee 100644 --- a/src/Workflow/Element/FlowObjectCollection.php +++ b/src/Workflow/Element/FlowObjectCollection.php @@ -14,28 +14,29 @@ use PHPMentors\DomainKata\Entity\EntityCollectionInterface; use PHPMentors\DomainKata\Entity\EntityInterface; +use Traversable; -class FlowObjectCollection implements EntityCollectionInterface, \Serializable +class FlowObjectCollection implements EntityCollectionInterface { /** * @var array */ - private $flowObjects = array(); + private $flowObjects = []; /** * {@inheritdoc} */ - public function serialize() + public function __serialize() { - return serialize(array( + return serialize([ 'flowObjects' => $this->flowObjects, - )); + ]); } /** * {@inheritdoc} */ - public function unserialize($serialized) + public function __unserialize($serialized) { foreach (unserialize($serialized) as $name => $value) { if (property_exists($this, $name)) { @@ -61,7 +62,7 @@ public function add(EntityInterface $entity) */ public function get($key) { - if (!array_key_exists($key, $this->flowObjects)) { + if (! array_key_exists($key, $this->flowObjects)) { return null; } @@ -79,7 +80,7 @@ public function remove(EntityInterface $entity) /** * {@inheritdoc} */ - public function count() + public function count(): int { return count($this->flowObjects); } @@ -87,7 +88,7 @@ public function count() /** * {@inheritdoc} */ - public function getIterator() + public function getIterator(): Traversable { return new \ArrayIterator($this->flowObjects); } diff --git a/src/Workflow/Event/Event.php b/src/Workflow/Event/Event.php index 63b7fef..5729be4 100644 --- a/src/Workflow/Event/Event.php +++ b/src/Workflow/Event/Event.php @@ -15,7 +15,7 @@ use PHPMentors\DomainKata\Entity\EntityInterface; use PHPMentors\Workflower\Workflow\Participant\Role; -abstract class Event implements \Serializable +abstract class Event { /** * @var int|string @@ -33,9 +33,9 @@ abstract class Event implements \Serializable private $role; /** - * @param int|string $id - * @param Role $role - * @param string $name + * @param int|string $id + * @param Role $role + * @param string $name */ public function __construct($id, Role $role, $name = null) { @@ -44,22 +44,16 @@ public function __construct($id, Role $role, $name = null) $this->name = $name; } - /** - * {@inheritdoc} - */ - public function serialize() + public function __serialize() { - return serialize(array( + return serialize([ 'id' => $this->id, 'name' => $this->name, 'role' => $this->role, - )); + ]); } - /** - * {@inheritdoc} - */ - public function unserialize($serialized) + public function __unserialize($serialized) { foreach (unserialize($serialized) as $name => $value) { if (property_exists($this, $name)) { @@ -69,8 +63,6 @@ public function unserialize($serialized) } /** - * {@inheritdoc} - * * @return string */ public function getId() @@ -86,20 +78,14 @@ public function getName() return $this->name; } - /** - * {@inheritdoc} - */ public function getRole() { return $this->role; } - /** - * {@inheritdoc} - */ public function equals(EntityInterface $target) { - if (!($target instanceof self)) { + if (! ($target instanceof self)) { return false; } diff --git a/src/Workflow/Gateway/ExclusiveGateway.php b/src/Workflow/Gateway/ExclusiveGateway.php index a7be350..d983169 100644 --- a/src/Workflow/Gateway/ExclusiveGateway.php +++ b/src/Workflow/Gateway/ExclusiveGateway.php @@ -15,7 +15,7 @@ use PHPMentors\DomainKata\Entity\EntityInterface; use PHPMentors\Workflower\Workflow\Participant\Role; -class ExclusiveGateway implements GatewayInterface, \Serializable +class ExclusiveGateway implements GatewayInterface { /** * @var int|string @@ -38,9 +38,9 @@ class ExclusiveGateway implements GatewayInterface, \Serializable private $defaultSequenceFlowId; /** - * @param int|string $id - * @param Role $role - * @param string $name + * @param int|string $id + * @param Role $role + * @param string $name */ public function __construct($id, Role $role, $name = null) { @@ -52,20 +52,20 @@ public function __construct($id, Role $role, $name = null) /** * {@inheritdoc} */ - public function serialize() + public function __serialize() { - return serialize(array( + return serialize([ 'id' => $this->id, 'name' => $this->name, 'role' => $this->role, 'defaultSequenceFlowId' => $this->defaultSequenceFlowId, - )); + ]); } /** * {@inheritdoc} */ - public function unserialize($serialized) + public function __unserialize($serialized) { foreach (unserialize($serialized) as $name => $value) { if (property_exists($this, $name)) { @@ -105,7 +105,7 @@ public function getName() */ public function equals(EntityInterface $target) { - if (!($target instanceof self)) { + if (! ($target instanceof self)) { return false; } diff --git a/src/Workflow/Operation/OperationRunnerInterface.php b/src/Workflow/Operation/OperationRunnerInterface.php index 261b2cd..7c46f20 100644 --- a/src/Workflow/Operation/OperationRunnerInterface.php +++ b/src/Workflow/Operation/OperationRunnerInterface.php @@ -23,16 +23,15 @@ interface OperationRunnerInterface extends ServiceInterface { /** - * @param ActivityInterface $activity - * @param Workflow $workflow - * + * @param ActivityInterface $activity + * @param Workflow $workflow * @return ParticipantInterface */ public function provideParticipant(OperationalInterface $operational, Workflow $workflow); /** - * @param OperationalInterface $operational - * @param Workflow $workflow + * @param OperationalInterface $operational + * @param Workflow $workflow */ public function run(OperationalInterface $operational, Workflow $workflow); } diff --git a/src/Workflow/Participant/LoggedParticipant.php b/src/Workflow/Participant/LoggedParticipant.php index 00bd6da..edfb425 100644 --- a/src/Workflow/Participant/LoggedParticipant.php +++ b/src/Workflow/Participant/LoggedParticipant.php @@ -14,7 +14,7 @@ use PHPMentors\Workflower\Workflow\Resource\ResourceInterface; -class LoggedParticipant implements ParticipantInterface, \Serializable +class LoggedParticipant implements ParticipantInterface { /** * @var int|string @@ -27,7 +27,7 @@ class LoggedParticipant implements ParticipantInterface, \Serializable private $name; /** - * @param ParticipantInterface $participant + * @param ParticipantInterface $participant */ public function __construct(ParticipantInterface $participant) { @@ -38,18 +38,18 @@ public function __construct(ParticipantInterface $participant) /** * {@inheritdoc} */ - public function serialize() + public function __serialize() { - return serialize(array( + return serialize([ 'id' => $this->id, 'name' => $this->name, - )); + ]); } /** * {@inheritdoc} */ - public function unserialize($serialized) + public function __unserialize($serialized) { foreach (unserialize($serialized) as $name => $value) { if (property_exists($this, $name)) { @@ -99,7 +99,7 @@ public function getName() } /** - * @param string $method + * @param string $method * * @throws OperationNotSupportedException */ diff --git a/src/Workflow/Participant/ParticipantInterface.php b/src/Workflow/Participant/ParticipantInterface.php index 90f96ae..6f9813c 100644 --- a/src/Workflow/Participant/ParticipantInterface.php +++ b/src/Workflow/Participant/ParticipantInterface.php @@ -18,14 +18,13 @@ interface ParticipantInterface extends OperationInterface, IdentifiableInterface { /** - * @param string $role - * + * @param string $role * @return bool */ public function hasRole($role); /** - * @param ResourceInterface $resource + * @param ResourceInterface $resource */ public function setResource(ResourceInterface $resource); diff --git a/src/Workflow/Participant/Role.php b/src/Workflow/Participant/Role.php index 62714d8..f37cd5c 100644 --- a/src/Workflow/Participant/Role.php +++ b/src/Workflow/Participant/Role.php @@ -15,7 +15,7 @@ use PHPMentors\DomainKata\Entity\EntityInterface; use PHPMentors\DomainKata\Entity\Operation\IdentifiableInterface; -class Role implements EntityInterface, IdentifiableInterface, \Serializable +class Role implements EntityInterface, IdentifiableInterface { /** * @var int|string @@ -28,8 +28,8 @@ class Role implements EntityInterface, IdentifiableInterface, \Serializable private $name; /** - * @param int|string $id - * @param string $name + * @param int|string $id + * @param string $name */ public function __construct($id, $name = null) { @@ -40,18 +40,18 @@ public function __construct($id, $name = null) /** * {@inheritdoc} */ - public function serialize() + public function __serialize() { - return serialize(array( + return serialize([ 'id' => $this->id, 'name' => $this->name, - )); + ]); } /** * {@inheritdoc} */ - public function unserialize($serialized) + public function __unserialize($serialized) { foreach (unserialize($serialized) as $name => $value) { if (property_exists($this, $name)) { diff --git a/src/Workflow/Participant/RoleCollection.php b/src/Workflow/Participant/RoleCollection.php index 0b31c80..039ec29 100644 --- a/src/Workflow/Participant/RoleCollection.php +++ b/src/Workflow/Participant/RoleCollection.php @@ -14,28 +14,29 @@ use PHPMentors\DomainKata\Entity\EntityCollectionInterface; use PHPMentors\DomainKata\Entity\EntityInterface; +use Traversable; -class RoleCollection implements EntityCollectionInterface, \Serializable +class RoleCollection implements EntityCollectionInterface { /** * @var array */ - private $roles = array(); + private $roles = []; /** * {@inheritdoc} */ - public function serialize() + public function __serialize() { - return serialize(array( + return serialize([ 'roles' => $this->roles, - )); + ]); } /** * {@inheritdoc} */ - public function unserialize($serialized) + public function __unserialize($serialized) { foreach (unserialize($serialized) as $name => $value) { if (property_exists($this, $name)) { @@ -79,7 +80,7 @@ public function remove(EntityInterface $entity) /** * {@inheritdoc} */ - public function count() + public function count(): int { return count($this->roles); } @@ -87,7 +88,7 @@ public function count() /** * {@inheritdoc} */ - public function getIterator() + public function getIterator(): Traversable { return new \ArrayIterator($this->roles); } diff --git a/src/Workflow/Workflow.php b/src/Workflow/Workflow.php index 6b43e75..b8c2a56 100644 --- a/src/Workflow/Workflow.php +++ b/src/Workflow/Workflow.php @@ -40,7 +40,7 @@ use Stagehand\FSM\StateMachine\StateMachineInterface; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; -class Workflow implements EntityInterface, IdentifiableInterface, \Serializable +class Workflow implements EntityInterface, IdentifiableInterface { const DEFAULT_ROLE_ID = '__ROLE__'; @@ -104,8 +104,8 @@ class Workflow implements EntityInterface, IdentifiableInterface, \Serializable private $operationRunner; /** - * @param int|string $id - * @param string $name + * @param int|string $id + * @param string $name */ public function __construct($id, $name) { @@ -119,9 +119,9 @@ public function __construct($id, $name) /** * {@inheritdoc} */ - public function serialize() + public function __serialize() { - return serialize(array( + return serialize([ 'name' => $this->name, 'connectingObjectCollection' => $this->connectingObjectCollection, 'flowObjectCollection' => $this->flowObjectCollection, @@ -129,13 +129,13 @@ public function serialize() 'startDate' => $this->startDate, 'endDate' => $this->endDate, 'stateMachine' => $this->stateMachine, - )); + ]); } /** * {@inheritdoc} */ - public function unserialize($serialized) + public function __unserialize($serialized) { foreach (unserialize($serialized) as $name => $value) { if (property_exists($this, $name)) { @@ -163,7 +163,7 @@ public function getName() } /** - * @param ConnectingObjectInterface $connectingObject + * @param ConnectingObjectInterface $connectingObject */ public function addConnectingObject(ConnectingObjectInterface $connectingObject) { @@ -179,7 +179,7 @@ public function addConnectingObject(ConnectingObjectInterface $connectingObject) } /** - * @param FlowObjectInterface $flowObject + * @param FlowObjectInterface $flowObject */ public function addFlowObject(FlowObjectInterface $flowObject) { @@ -206,8 +206,7 @@ public function addFlowObject(FlowObjectInterface $flowObject) } /** - * @param int|string $id - * + * @param int|string $id * @return ConnectingObjectInterface|null */ public function getConnectingObject($id) @@ -216,8 +215,7 @@ public function getConnectingObject($id) } /** - * @param TransitionalInterface $flowObject - * + * @param TransitionalInterface $flowObject * @return ConnectingObjectCollection */ public function getConnectingObjectCollectionBySource(TransitionalInterface $flowObject) @@ -226,8 +224,7 @@ public function getConnectingObjectCollectionBySource(TransitionalInterface $flo } /** - * @param int|string $id - * + * @param int|string $id * @return FlowObjectInterface|null */ public function getFlowObject($id) @@ -236,7 +233,7 @@ public function getFlowObject($id) } /** - * @param Role $role + * @param Role $role */ public function addRole(Role $role) { @@ -244,8 +241,7 @@ public function addRole(Role $role) } /** - * @param int|string $id - * + * @param int|string $id * @return bool */ public function hasRole($id) @@ -254,8 +250,7 @@ public function hasRole($id) } /** - * @param int|string $id - * + * @param int|string $id * @return Role */ public function getRole($id) @@ -329,8 +324,8 @@ public function start(StartEvent $event) } /** - * @param ActivityInterface $activity - * @param ParticipantInterface $participant + * @param ActivityInterface $activity + * @param ParticipantInterface $participant */ public function allocateWorkItem(ActivityInterface $activity, ParticipantInterface $participant) { @@ -341,8 +336,8 @@ public function allocateWorkItem(ActivityInterface $activity, ParticipantInterfa } /** - * @param ActivityInterface $activity - * @param ParticipantInterface $participant + * @param ActivityInterface $activity + * @param ParticipantInterface $participant */ public function startWorkItem(ActivityInterface $activity, ParticipantInterface $participant) { @@ -353,8 +348,8 @@ public function startWorkItem(ActivityInterface $activity, ParticipantInterface } /** - * @param ActivityInterface $activity - * @param ParticipantInterface $participant + * @param ActivityInterface $activity + * @param ParticipantInterface $participant */ public function completeWorkItem(ActivityInterface $activity, ParticipantInterface $participant) { @@ -367,7 +362,7 @@ public function completeWorkItem(ActivityInterface $activity, ParticipantInterfa } /** - * @param array $processData + * @param array $processData */ public function setProcessData(array $processData) { @@ -385,7 +380,7 @@ public function getProcessData() } /** - * @param ExpressionLanguage $expressionLanguage + * @param ExpressionLanguage $expressionLanguage * * @since Method available since Release 1.1.0 */ @@ -395,7 +390,7 @@ public function setExpressionLanguage(ExpressionLanguage $expressionLanguage) } /** - * @param OperationRunnerInterface $operationRunner + * @param OperationRunnerInterface $operationRunner * * @since Method available since Release 1.2.0 */ @@ -405,7 +400,7 @@ public function setOperationRunner(OperationRunnerInterface $operationRunner) } /** - * @param EndEvent $event + * @param EndEvent $event */ private function end(EndEvent $event) { @@ -446,8 +441,7 @@ public function getActivityLog() } /** - * @param string $stateMachineName - * + * @param string $stateMachineName * @return StateMachineInterface */ private function createStateMachine($stateMachineName) @@ -468,7 +462,7 @@ private function createStateMachine($stateMachineName) } /** - * @param TransitionalInterface $currentFlowObject + * @param TransitionalInterface $currentFlowObject * * @throws SequenceFlowNotSelectedException */ @@ -476,7 +470,7 @@ private function selectSequenceFlow(TransitionalInterface $currentFlowObject) { foreach ($this->connectingObjectCollection->filterBySource($currentFlowObject) as $connectingObject) { /* @var $connectingObject ConnectingObjectInterface */ if ($connectingObject instanceof SequenceFlow) { - if (!($currentFlowObject instanceof ConditionalInterface) || $connectingObject->getId() !== $currentFlowObject->getDefaultSequenceFlowId()) { + if (! ($currentFlowObject instanceof ConditionalInterface) || $connectingObject->getId() !== $currentFlowObject->getDefaultSequenceFlowId()) { $condition = $connectingObject->getCondition(); if ($condition === null) { $selectedSequenceFlow = $connectingObject; @@ -492,8 +486,8 @@ private function selectSequenceFlow(TransitionalInterface $currentFlowObject) } } - if (!isset($selectedSequenceFlow)) { - if (!($currentFlowObject instanceof ConditionalInterface) || $currentFlowObject->getDefaultSequenceFlowId() === null) { + if (! isset($selectedSequenceFlow)) { + if (! ($currentFlowObject instanceof ConditionalInterface) || $currentFlowObject->getDefaultSequenceFlowId() === null) { throw new SequenceFlowNotSelectedException(sprintf('No sequence flow can be selected on "%s".', $currentFlowObject->getId())); } @@ -508,26 +502,26 @@ private function selectSequenceFlow(TransitionalInterface $currentFlowObject) } /** - * @param ActivityInterface $activity - * @param ParticipantInterface $participant + * @param ActivityInterface $activity + * @param ParticipantInterface $participant * * @throws AccessDeniedException */ private function assertParticipantHasRole(ActivityInterface $activity, ParticipantInterface $participant) { - if (!$participant->hasRole($activity->getRole()->getId())) { + if (! $participant->hasRole($activity->getRole()->getId())) { throw new AccessDeniedException(sprintf('The participant "%s" does not have the role "%s" that is required to operate the activity "%s".', $participant->getId(), $activity->getRole()->getId(), $activity->getId())); } } /** - * @param ActivityInterface $activity + * @param ActivityInterface $activity * * @throws UnexpectedActivityException */ private function assertCurrentFlowObjectIsExpectedActivity(ActivityInterface $activity) { - if (!$activity->equals($this->getCurrentFlowObject())) { + if (! $activity->equals($this->getCurrentFlowObject())) { throw new UnexpectedActivityException(sprintf('The current flow object is not equal to the expected activity "%s".', $activity->getId())); } } diff --git a/src/Workflow/WorkflowBuilder.php b/src/Workflow/WorkflowBuilder.php index 99f371a..4fa18bc 100644 --- a/src/Workflow/WorkflowBuilder.php +++ b/src/Workflow/WorkflowBuilder.php @@ -27,46 +27,46 @@ class WorkflowBuilder /** * @var array */ - private $endEvents = array(); + private $endEvents = []; /** * @var array */ - private $exclusiveGateways = array(); + private $exclusiveGateways = []; /** * @var array */ - private $roles = array(); + private $roles = []; /** * @var array */ - private $sequenceFlows = array(); + private $sequenceFlows = []; /** * @var array */ - private $startEvents = array(); + private $startEvents = []; /** * @var array */ - private $tasks = array(); + private $tasks = []; /** * @var array * * @since Property available since Release 1.2.0 */ - private $serviceTasks = array(); + private $serviceTasks = []; /** * @var array * * @since Property available since Release 1.3.0 */ - private $sendTasks = array(); + private $sendTasks = []; /** * @var string @@ -81,11 +81,11 @@ class WorkflowBuilder /** * @var array */ - private $defaultableFlowObjects = array(); + private $defaultableFlowObjects = []; /** - * @param int|string $workflowId - * @param int|string $workflowName + * @param int|string $workflowId + * @param int|string $workflowName */ public function __construct($workflowId = null, $workflowName = null) { @@ -94,7 +94,7 @@ public function __construct($workflowId = null, $workflowName = null) } /** - * @param int|string $id + * @param int|string $id */ public function setWorkflowId($id) { @@ -102,7 +102,7 @@ public function setWorkflowId($id) } /** - * @param string $name + * @param string $name */ public function setWorkflowName($name) { @@ -110,24 +110,24 @@ public function setWorkflowName($name) } /** - * @param string $id - * @param string $participant - * @param string $name + * @param string $id + * @param string $participant + * @param string $name */ public function addEndEvent($id, $participant, $name = null) { - $this->endEvents[$id] = array($participant, $name); + $this->endEvents[$id] = [$participant, $name]; } /** - * @param int|string $id - * @param string $participant - * @param string $name - * @param int|string $defaultSequenceFlow + * @param int|string $id + * @param string $participant + * @param string $name + * @param int|string $defaultSequenceFlow */ public function addExclusiveGateway($id, $participant, $name = null, $defaultSequenceFlow = null) { - $this->exclusiveGateways[$id] = array($participant, $name); + $this->exclusiveGateways[$id] = [$participant, $name]; if ($defaultSequenceFlow !== null) { $this->defaultableFlowObjects[$defaultSequenceFlow] = $id; @@ -135,20 +135,20 @@ public function addExclusiveGateway($id, $participant, $name = null, $defaultSeq } /** - * @param int|string $id - * @param string $name + * @param int|string $id + * @param string $name */ public function addRole($id, $name = null) { - $this->roles[$id] = array($name); + $this->roles[$id] = [$name]; } /** - * @param string $source - * @param string $destination - * @param int|string $id - * @param string $name - * @param string $condition + * @param string $source + * @param string $destination + * @param int|string $id + * @param string $name + * @param string $condition */ public function addSequenceFlow($source, $destination, $id = null, $name = null, $condition = null) { @@ -156,21 +156,21 @@ public function addSequenceFlow($source, $destination, $id = null, $name = null, if ($id === null) { $id = $source.'.'.$destination.$i; - ++$i; + $i++; } - $this->sequenceFlows[$id] = array($source, $destination, $name, $condition); + $this->sequenceFlows[$id] = [$source, $destination, $name, $condition]; } /** - * @param int|string $id - * @param string $participant - * @param string $name - * @param int|string $defaultSequenceFlow + * @param int|string $id + * @param string $participant + * @param string $name + * @param int|string $defaultSequenceFlow */ public function addStartEvent($id, $participant, $name = null, $defaultSequenceFlow = null) { - $this->startEvents[$id] = array($participant, $name, $defaultSequenceFlow); + $this->startEvents[$id] = [$participant, $name, $defaultSequenceFlow]; if ($defaultSequenceFlow !== null) { $this->defaultableFlowObjects[$defaultSequenceFlow] = $id; @@ -178,14 +178,14 @@ public function addStartEvent($id, $participant, $name = null, $defaultSequenceF } /** - * @param string $id - * @param string $participant - * @param string $name - * @param int|string $defaultSequenceFlow + * @param string $id + * @param string $participant + * @param string $name + * @param int|string $defaultSequenceFlow */ public function addTask($id, $participant, $name = null, $defaultSequenceFlow = null) { - $this->tasks[$id] = array($participant, $name); + $this->tasks[$id] = [$participant, $name]; if ($defaultSequenceFlow !== null) { $this->defaultableFlowObjects[$defaultSequenceFlow] = $id; @@ -193,17 +193,17 @@ public function addTask($id, $participant, $name = null, $defaultSequenceFlow = } /** - * @param string $id - * @param string $participant - * @param string $operation - * @param string $name - * @param int|string $defaultSequenceFlow + * @param string $id + * @param string $participant + * @param string $operation + * @param string $name + * @param int|string $defaultSequenceFlow * * @since Method available since Release 1.2.0 */ public function addServiceTask($id, $participant, $operation, $name = null, $defaultSequenceFlow = null) { - $this->serviceTasks[$id] = array($participant, $operation, $name); + $this->serviceTasks[$id] = [$participant, $operation, $name]; if ($defaultSequenceFlow !== null) { $this->defaultableFlowObjects[$defaultSequenceFlow] = $id; @@ -211,18 +211,18 @@ public function addServiceTask($id, $participant, $operation, $name = null, $def } /** - * @param string $id - * @param string $participant - * @param string $message - * @param string $operation - * @param string $name - * @param int|string $defaultSequenceFlow + * @param string $id + * @param string $participant + * @param string $message + * @param string $operation + * @param string $name + * @param int|string $defaultSequenceFlow * * @since Method available since Release 1.3.0 */ public function addSendTask($id, $participant, $message, $operation, $name = null, $defaultSequenceFlow = null) { - $this->sendTasks[$id] = array($participant, $message, $operation, $name); + $this->sendTasks[$id] = [$participant, $message, $operation, $name]; if ($defaultSequenceFlow !== null) { $this->defaultableFlowObjects[$defaultSequenceFlow] = $id; @@ -239,54 +239,54 @@ public function build() $workflow = new Workflow($this->workflowId, $this->workflowName); foreach ($this->roles as $id => $role) { - list($name) = $role; + [$name] = $role; $workflow->addRole(new Role($id, $name)); } foreach ($this->startEvents as $id => $event) { - list($roleId, $name) = $event; + [$roleId, $name] = $event; $this->assertWorkflowHasRole($workflow, $roleId); $workflow->addFlowObject(new StartEvent($id, $workflow->getRole($roleId), $name)); } foreach ($this->endEvents as $id => $event) { - list($roleId, $name) = $event; + [$roleId, $name] = $event; $this->assertWorkflowHasRole($workflow, $roleId); $workflow->addFlowObject(new EndEvent($id, $workflow->getRole($roleId), $name)); } foreach ($this->tasks as $id => $task) { - list($roleId, $name) = $task; + [$roleId, $name] = $task; $this->assertWorkflowHasRole($workflow, $roleId); $workflow->addFlowObject(new Task($id, $workflow->getRole($roleId), $name)); } foreach ($this->serviceTasks as $id => $task) { - list($roleId, $operation, $name) = $task; + [$roleId, $operation, $name] = $task; $this->assertWorkflowHasRole($workflow, $roleId); $workflow->addFlowObject(new ServiceTask($id, $workflow->getRole($roleId), $operation, $name)); } foreach ($this->sendTasks as $id => $task) { - list($roleId, $message, $operation, $name) = $task; + [$roleId, $message, $operation, $name] = $task; $this->assertWorkflowHasRole($workflow, $roleId); $workflow->addFlowObject(new SendTask($id, $workflow->getRole($roleId), $message, $operation, $name)); } foreach ($this->exclusiveGateways as $id => $gateway) { - list($roleId, $name) = $gateway; + [$roleId, $name] = $gateway; $this->assertWorkflowHasRole($workflow, $roleId); $workflow->addFlowObject(new ExclusiveGateway($id, $workflow->getRole($roleId), $name)); } foreach ($this->sequenceFlows as $id => $flow) { - list($source, $destination, $name, $condition) = $flow; + [$source, $destination, $name, $condition] = $flow; if (array_key_exists($id, $this->defaultableFlowObjects) && $condition !== null) { throw new \LogicException(sprintf('The sequence flow "%s" has the condition "%s". A condition cannot be set to the default sequence flow.', $id, $condition)); @@ -303,14 +303,14 @@ public function build() } /** - * @param Workflow $workflow - * @param int|string $roleId + * @param Workflow $workflow + * @param int|string $roleId * * @throws \LogicException */ private function assertWorkflowHasRole(Workflow $workflow, $roleId) { - if (!$workflow->hasRole($roleId)) { + if (! $workflow->hasRole($roleId)) { throw new \LogicException(sprintf('The workflow "%s" does not have the role "%s".', $workflow->getId(), $roleId)); } } diff --git a/src/Workflow/WorkflowRepositoryInterface.php b/src/Workflow/WorkflowRepositoryInterface.php index 53f8fed..6c84e58 100644 --- a/src/Workflow/WorkflowRepositoryInterface.php +++ b/src/Workflow/WorkflowRepositoryInterface.php @@ -17,8 +17,7 @@ interface WorkflowRepositoryInterface extends RepositoryInterface { /** - * @param int|string $id - * + * @param int|string $id * @return Workflow */ public function findById($id); diff --git a/tests/Definition/Bpmn2ReaderTest.php b/tests/Definition/Bpmn2ReaderTest.php index bb52231..1448f64 100644 --- a/tests/Definition/Bpmn2ReaderTest.php +++ b/tests/Definition/Bpmn2ReaderTest.php @@ -13,8 +13,9 @@ namespace PHPMentors\Workflower\Definition; use PHPMentors\Workflower\Workflow\WorkflowRepository; +use PHPUnit\Framework\TestCase; -class Bpmn2ReaderTest extends \PHPUnit_Framework_TestCase +class Bpmn2ReaderTest extends TestCase { /** * @test diff --git a/tests/Workflow/WorkflowRepository.php b/tests/Workflow/WorkflowRepository.php index 5c7fdcd..9a65b75 100644 --- a/tests/Workflow/WorkflowRepository.php +++ b/tests/Workflow/WorkflowRepository.php @@ -20,7 +20,7 @@ class WorkflowRepository implements WorkflowRepositoryInterface /** * @var array */ - private $workflows = array(); + private $workflows = []; public function __construct() { @@ -54,7 +54,7 @@ public function remove(EntityInterface $entity) */ public function findById($id) { - if (!array_key_exists($id, $this->workflows)) { + if (! array_key_exists($id, $this->workflows)) { return null; } diff --git a/tests/Workflow/WorkflowTest.php b/tests/Workflow/WorkflowTest.php index 03b9a19..fac3d9f 100644 --- a/tests/Workflow/WorkflowTest.php +++ b/tests/Workflow/WorkflowTest.php @@ -16,8 +16,9 @@ use PHPMentors\Workflower\Workflow\Activity\WorkItem; use PHPMentors\Workflower\Workflow\Activity\WorkItemInterface; use PHPMentors\Workflower\Workflow\Operation\OperationalInterface; +use PHPUnit\Framework\TestCase; -class WorkflowTest extends \PHPUnit_Framework_TestCase +class WorkflowTest extends TestCase { /** * @var WorkflowRepositoryInterface @@ -27,7 +28,7 @@ class WorkflowTest extends \PHPUnit_Framework_TestCase /** * {@inheritdoc} */ - protected function setUp() + protected function setUp(): void { $this->workflowRepository = new WorkflowRepository(); } @@ -149,15 +150,15 @@ public function completeWorkItem() */ public function completeActivityOnConditionalSequenceFlowsData() { - return array( - array(true, 'End'), - array(false, 'LoanStudy'), - ); + return [ + [true, 'End'], + [false, 'LoanStudy'], + ]; } /** - * @param bool $rejected - * @param string $nextFlowObjectId + * @param bool $rejected + * @param string $nextFlowObjectId * * @test * @dataProvider completeActivityOnConditionalSequenceFlowsData @@ -168,7 +169,7 @@ public function completeActivityOnConditionalSequenceFlow($rejected, $nextFlowOb \Phake::when($participant)->hasRole($this->anything())->thenReturn(true); $workflow = $this->workflowRepository->findById('LoanRequestProcess'); - $workflow->setProcessData(array('rejected' => false)); + $workflow->setProcessData(['rejected' => false]); $workflow->start($workflow->getFlowObject('Start')); $workflow->allocateWorkItem($workflow->getCurrentFlowObject(), $participant); @@ -177,7 +178,7 @@ public function completeActivityOnConditionalSequenceFlow($rejected, $nextFlowOb $workflow->allocateWorkItem($workflow->getCurrentFlowObject(), $participant); $workflow->startWorkItem($workflow->getCurrentFlowObject(), $participant); - $workflow->setProcessData(array('rejected' => $rejected)); + $workflow->setProcessData(['rejected' => $rejected]); $workflow->completeWorkItem($workflow->getCurrentFlowObject(), $participant); $currentFlowObject = $workflow->getCurrentFlowObject(); @@ -190,15 +191,15 @@ public function completeActivityOnConditionalSequenceFlow($rejected, $nextFlowOb */ public function selectSequenceFlowOnExclusiveGatewayData() { - return array( - array(true, 'InformRejection'), - array(false, 'Disbursement'), - ); + return [ + [true, 'InformRejection'], + [false, 'Disbursement'], + ]; } /** - * @param bool $rejected - * @param string $nextFlowObjectId + * @param bool $rejected + * @param string $nextFlowObjectId * * @test * @dataProvider selectSequenceFlowOnExclusiveGatewayData @@ -209,7 +210,7 @@ public function selectSequenceFlowOnExclusiveGateway($rejected, $nextFlowObjectI \Phake::when($participant)->hasRole($this->anything())->thenReturn(true); $workflow = $this->workflowRepository->findById('LoanRequestProcess'); - $workflow->setProcessData(array('rejected' => false)); + $workflow->setProcessData(['rejected' => false]); $workflow->start($workflow->getFlowObject('Start')); $workflow->allocateWorkItem($workflow->getCurrentFlowObject(), $participant); @@ -222,7 +223,7 @@ public function selectSequenceFlowOnExclusiveGateway($rejected, $nextFlowObjectI $workflow->allocateWorkItem($workflow->getCurrentFlowObject(), $participant); $workflow->startWorkItem($workflow->getCurrentFlowObject(), $participant); - $workflow->setProcessData(array('rejected' => $rejected)); + $workflow->setProcessData(['rejected' => $rejected]); $workflow->completeWorkItem($workflow->getCurrentFlowObject(), $participant); $currentFlowObject = $workflow->getCurrentFlowObject(); @@ -239,7 +240,7 @@ public function end() \Phake::when($participant)->hasRole($this->anything())->thenReturn(true); $workflow = $this->workflowRepository->findById('LoanRequestProcess'); - $workflow->setProcessData(array('rejected' => false)); + $workflow->setProcessData(['rejected' => false]); $workflow->start($workflow->getFlowObject('Start')); $workflow->allocateWorkItem($workflow->getCurrentFlowObject(), $participant); @@ -283,7 +284,7 @@ public function getActivityLog() \Phake::when($participant)->hasRole($this->anything())->thenReturn(true); $workflow = $this->workflowRepository->findById('LoanRequestProcess'); - $workflow->setProcessData(array('rejected' => false)); + $workflow->setProcessData(['rejected' => false]); $workflow->start($workflow->getFlowObject('Start')); $workflow->allocateWorkItem($workflow->getCurrentFlowObject(), $participant); @@ -307,12 +308,12 @@ public function getActivityLog() $this->assertThat($activityLog, $this->isInstanceOf('PHPMentors\Workflower\Workflow\ActivityLogCollection')); $this->assertThat(count($activityLog), $this->equalTo(4)); - $activityIds = array( + $activityIds = [ 'RecordLoanApplicationInformation', 'CheckApplicantInformation', 'LoanStudy', 'Disbursement', - ); + ]; foreach ($activityLog as $i => $activityLogEntry) { /* @var $activityLogEntry ActivityLog */ $this->assertThat($activityLogEntry->getActivity()->getId(), $this->equalTo($activityIds[$i])); @@ -336,7 +337,7 @@ public function getActivityLogWithMultipleExecutionsOfSameActivity() \Phake::when($participant)->hasRole($this->anything())->thenReturn(true); $workflow = $this->workflowRepository->findById('MultipleWorkItemsProcess'); - $workflow->setProcessData(array('satisfied' => false)); + $workflow->setProcessData(['satisfied' => false]); $workflow->start($workflow->getFlowObject('Start')); $workflow->allocateWorkItem($workflow->getCurrentFlowObject(), $participant); @@ -353,7 +354,7 @@ public function getActivityLogWithMultipleExecutionsOfSameActivity() $workflow->allocateWorkItem($workflow->getCurrentFlowObject(), $participant); $workflow->startWorkItem($workflow->getCurrentFlowObject(), $participant); - $workflow->setProcessData(array('satisfied' => true)); + $workflow->setProcessData(['satisfied' => true]); $workflow->completeWorkItem($workflow->getCurrentFlowObject(), $participant); $activityLog = $workflow->getActivityLog(); @@ -384,8 +385,11 @@ public function injectExpressionLanguage() $workflow = $this->workflowRepository->findById('LoanRequestProcess'); $workflow->setExpressionLanguage($expressionLanguage); - $workflow->setProcessData(array('rejected' => false)); + $workflow->setProcessData(['rejected' => false]); $workflow->start($workflow->getFlowObject('Start')); + + // if not will get an error: this test did not perform any assertions + $this->assertTrue(true); } /** @@ -403,7 +407,7 @@ public function executeServiceTasks() \Phake::when($operationRunner)->run($this->anything(), $this->anything())->thenReturnCallback(function (OperationalInterface $operational, Workflow $workflow) use ($self) { static $calls = 0; - ++$calls; + $calls++; $self->assertThat($operational, $self->isInstanceOf('PHPMentors\Workflower\Workflow\Activity\ServiceTask')); $self->assertThat($operational->getOperation(), $self->equalTo('phpmentors_workflower.service'.$calls)); }); @@ -453,7 +457,7 @@ public function executeSendTasks() \Phake::when($operationRunner)->run($this->anything(), $this->anything())->thenReturnCallback(function (OperationalInterface $operational, Workflow $workflow) use ($self) { static $calls = 0; - ++$calls; + $calls++; $self->assertThat($operational, $self->isInstanceOf('PHPMentors\Workflower\Workflow\Activity\SendTask')); $self->assertThat($operational->getOperation(), $self->equalTo('phpmentors_workflower.service'.$calls)); $self->assertThat($operational, $self->isInstanceOf('PHPMentors\Workflower\Workflow\Resource\MessageInterface'));