Skip to content

Commit

Permalink
feature #27092 [Workflow] "clear()" instead of "reset()" (nicolas-gre…
Browse files Browse the repository at this point in the history
…kas)

This PR was merged into the 4.1-dev branch.

Discussion
----------

[Workflow] "clear()" instead of "reset()"

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

While working on another PR (to come), I noticed that the workflow component is using the word "reset" for something that is consistently called "clear" in the rest of the code base (emptying the state of an object) - and also that "reset" is consistently used for setting an object back to its initial state (which might not be the empty state, contrary to what clear does).

Here is a PR fixing this inconsistency. Should be on 4.1 so that we won't have to deal with another BC layer in 4.2.

Commits
-------

858fabb [Workflow] "clear()" instead of "reset()"
  • Loading branch information
fabpot committed Apr 30, 2018
2 parents 697791c + 858fabb commit 5a5b925
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions UPGRADE-4.1.md
Expand Up @@ -154,6 +154,7 @@ Validator
Workflow
--------

* Deprecated the `DefinitionBuilder::reset()` method, use the `clear()` one instead.
* Deprecated the `add` method in favor of the `addWorkflow` method in `Workflow\Registry`.
* Deprecated `SupportStrategyInterface` in favor of `WorkflowSupportStrategyInterface`.
* Deprecated the class `ClassInstanceSupportStrategy` in favor of the class `InstanceOfSupportStrategy`.
Expand Down
1 change: 1 addition & 0 deletions UPGRADE-5.0.md
Expand Up @@ -107,6 +107,7 @@ Validator
Workflow
--------

* The `DefinitionBuilder::reset()` method has been removed, use the `clear()` one instead.
* `add` method has been removed use `addWorkflow` method in `Workflow\Registry` instead.
* `SupportStrategyInterface` has been removed, use `WorkflowSupportStrategyInterface` instead.
* `ClassInstanceSupportStrategy` has been removed, use `InstanceOfSupportStrategy` instead.
5 changes: 3 additions & 2 deletions src/Symfony/Component/Workflow/CHANGELOG.md
Expand Up @@ -4,8 +4,9 @@ CHANGELOG
4.1.0
-----

* Deprecate the usage of `add(Workflow $workflow, $supportStrategy)` in `Workflow/Registry`, use `addWorkflow(WorkflowInterface, $supportStrategy)` instead.
* Deprecate the usage of `SupportStrategyInterface`, use `WorkflowSupportStrategyInterface` instead.
* Deprecated the `DefinitionBuilder::reset()` method, use the `clear()` one instead.
* Deprecated the usage of `add(Workflow $workflow, $supportStrategy)` in `Workflow/Registry`, use `addWorkflow(WorkflowInterface, $supportStrategy)` instead.
* Deprecated the usage of `SupportStrategyInterface`, use `WorkflowSupportStrategyInterface` instead.
* The `Workflow` class now implements `WorkflowInterface`.
* Deprecated the class `ClassInstanceSupportStrategy` in favor of the class `InstanceOfSupportStrategy`.
* Added TransitionBlockers as a way to pass around reasons why exactly
Expand Down
14 changes: 13 additions & 1 deletion src/Symfony/Component/Workflow/DefinitionBuilder.php
Expand Up @@ -47,7 +47,7 @@ public function build()
*
* @return $this
*/
public function reset()
public function clear()
{
$this->places = array();
$this->transitions = array();
Expand Down Expand Up @@ -121,4 +121,16 @@ public function addTransition(Transition $transition)

return $this;
}

/**
* @deprecated since Symfony 4.1, use the clear() method instead.
*
* @return $this
*/
public function reset()
{
@trigger_error(sprintf('The "%s" method is deprecated since Symfony 4.1, use the "clear()" method instead.', __METHOD__), E_USER_DEPRECATED);

return $this->clear();
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Workflow/Event/GuardEvent.php
Expand Up @@ -42,7 +42,7 @@ public function isBlocked()
public function setBlocked($blocked)
{
if (!$blocked) {
$this->transitionBlockerList->reset();
$this->transitionBlockerList->clear();

return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Workflow/TransitionBlockerList.php
Expand Up @@ -37,7 +37,7 @@ public function add(TransitionBlocker $blocker): void
$this->blockers[] = $blocker;
}

public function reset(): void
public function clear(): void
{
$this->blockers = array();
}
Expand Down

0 comments on commit 5a5b925

Please sign in to comment.