Conditions | 11 |
Paths | 51 |
Total Lines | 52 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
91 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
92 | { |
||
93 | $workflowName = $input->getArgument('name'); |
||
94 | |||
95 | $workflow = null; |
||
96 | |||
97 | if (isset($this->workflows['workflow.' . $workflowName])) { |
||
98 | $workflow = $this->workflows['workflow.' . $workflowName]; |
||
99 | $type = 'workflow'; |
||
100 | } elseif (isset($this->workflows['state_machine.' . $workflowName])) { |
||
101 | $workflow = $this->workflows['state_machine.' . $workflowName]; |
||
102 | $type = 'state_machine'; |
||
103 | } |
||
104 | |||
105 | if (null === $workflow) { |
||
106 | throw new InvalidArgumentException(\sprintf('No service found for "workflow.%1$s" nor "state_machine.%1$s".', $workflowName)); |
||
107 | } |
||
108 | |||
109 | switch ($input->getOption('dump-format')) { |
||
110 | case 'puml': |
||
111 | $transitionType = 'workflow' === $type ? PlantUmlDumper::WORKFLOW_TRANSITION : PlantUmlDumper::STATEMACHINE_TRANSITION; |
||
|
|||
112 | $dumper = new PlantUmlDumper($transitionType); |
||
113 | |||
114 | break; |
||
115 | |||
116 | case 'mermaid': |
||
117 | $transitionType = 'workflow' === $type ? MermaidDumper::TRANSITION_TYPE_WORKFLOW : MermaidDumper::TRANSITION_TYPE_STATEMACHINE; |
||
118 | $dumper = new MermaidDumper($transitionType); |
||
119 | |||
120 | break; |
||
121 | |||
122 | case 'dot': |
||
123 | default: |
||
124 | $dumper = ('workflow' === $type) ? new GraphvizDumper() : new StateMachineGraphvizDumper(); |
||
125 | } |
||
126 | |||
127 | $marking = new Marking(); |
||
128 | |||
129 | foreach ($input->getArgument('marking') as $place) { |
||
130 | $marking->mark($place); |
||
131 | } |
||
132 | |||
133 | $options = [ |
||
134 | 'name' => $workflowName, |
||
135 | 'nofooter' => true, |
||
136 | 'graph' => [ |
||
137 | 'label' => $input->getOption('label'), |
||
138 | ], |
||
139 | ]; |
||
140 | $output->writeln($dumper->dump($workflow, $marking, $options)); |
||
141 | |||
142 | return self::SUCCESS; |
||
143 | } |
||
156 |