Conditions | 6 |
Paths | 14 |
Total Lines | 53 |
Code Lines | 31 |
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 |
||
67 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
68 | { |
||
69 | if (!$output instanceof ConsoleOutputInterface) { |
||
70 | throw new \InvalidArgumentException('Output must implement ConsoleOutputInterface'); |
||
71 | } |
||
72 | |||
73 | $this->environment->registerListener(new OutputtingListener($output->getErrorOutput())); |
||
74 | |||
75 | $commandBus = $this->environment->getCommandBus(); |
||
76 | |||
77 | try { |
||
78 | $this->dispatcher->dispatch(new ExecutionStarted); |
||
79 | $this->console->execute($input, $output); |
||
80 | $commandBus->handle(new Commit); |
||
81 | $this->dispatcher->dispatch(new ExecutionStopped); |
||
82 | } catch (GiroappException $e) { |
||
83 | $this->dispatcher->dispatch( |
||
84 | new LogEvent( |
||
85 | $e->getMessage(), |
||
86 | [ |
||
87 | 'code' => $e->getCode(), |
||
88 | ], |
||
89 | LogLevel::ERROR |
||
90 | ) |
||
91 | ); |
||
92 | |||
93 | $commandBus->handle(new Rollback); |
||
94 | |||
95 | return $e->getCode(); |
||
96 | } catch (\Exception $e) { |
||
97 | $this->dispatcher->dispatch( |
||
98 | new LogEvent( |
||
99 | $e->getMessage(), |
||
100 | [ |
||
101 | 'class' => get_class($e), |
||
102 | 'file' => $e->getFile(), |
||
103 | 'line' => $e->getLine(), |
||
104 | 'trace' => $e->getTraceAsString(), |
||
105 | ], |
||
106 | LogLevel::ERROR |
||
107 | ) |
||
108 | ); |
||
109 | |||
110 | if ($output->isVerbose()) { |
||
111 | $output->writeln($e->getTraceAsString()); |
||
112 | } |
||
113 | |||
114 | $commandBus->handle(new Rollback); |
||
115 | |||
116 | return $e->getCode() ?: GiroappException::GENERIC_ERROR; |
||
117 | } |
||
118 | |||
119 | return 0; |
||
120 | } |
||
122 |