| Conditions | 11 |
| Paths | 48 |
| Total Lines | 55 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 73 | public function register(array $config) |
||
| 74 | { |
||
| 75 | $config = array_replace_recursive( |
||
| 76 | [ |
||
| 77 | 'name' => get_class($this), |
||
| 78 | 'places' => [], |
||
| 79 | 'supports' => [], |
||
| 80 | 'transitions' => [], |
||
| 81 | 'type' => 'workflow', |
||
| 82 | 'marking_store' => [ |
||
| 83 | 'type' => 'single_state', |
||
| 84 | 'arguments' => ['state'], |
||
| 85 | ], |
||
| 86 | ], |
||
| 87 | $config |
||
| 88 | ); |
||
| 89 | |||
| 90 | if ($this->isDevMode && empty($config['supports'])) { |
||
| 91 | throw new \InvalidArgumentException("The `supports` can't be empty, Please provide entity classes."); |
||
| 92 | } |
||
| 93 | |||
| 94 | $transitions = []; |
||
| 95 | $definitionBuilder = new DefinitionBuilder(); |
||
| 96 | $definitionBuilder->addPlaces((array)$config['places']); |
||
| 97 | |||
| 98 | foreach ((array)$config['transitions'] as $name => $transition) { |
||
| 99 | if ('workflow' === $config['type']) { |
||
| 100 | $transitions[] = new Transition($name, $transition['from'], $transition['to']); |
||
| 101 | } elseif ('state_machine' === $config['type']) { |
||
| 102 | foreach ((array)$transition['from'] as $from) { |
||
| 103 | foreach ((array)$transition['to'] as $to) { |
||
| 104 | $transitions[] = new Transition($name, $from, $to); |
||
| 105 | } |
||
| 106 | } |
||
| 107 | } |
||
| 108 | } |
||
| 109 | |||
| 110 | $definitionBuilder->addTransitions($transitions); |
||
| 111 | $definition = $definitionBuilder->build(); |
||
| 112 | $markingStoreArguments = $config['marking_store']['arguments']; |
||
| 113 | |||
| 114 | if ('multiple_state' === $config['marking_store']['type']) { |
||
| 115 | $marking = new MultipleStateMarkingStore(...$markingStoreArguments); |
||
|
|
|||
| 116 | } else { |
||
| 117 | $marking = new SingleStateMarkingStore(...$markingStoreArguments); |
||
| 118 | } |
||
| 119 | |||
| 120 | if ($this->isDevMode) { |
||
| 121 | $this->getDefinitionValidator($config)->validate($definition, $config['name']); |
||
| 122 | } |
||
| 123 | |||
| 124 | $workflow = new Workflow($definition, $marking, $this->dispatcher, $config['name']); |
||
| 125 | |||
| 126 | foreach ($config['supports'] as $class) { |
||
| 127 | $this->registry->add($workflow, $class); |
||
| 128 | } |
||
| 139 |