Conditions | 10 |
Paths | 14 |
Total Lines | 35 |
Code Lines | 28 |
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 |
||
53 | public function handle(Command $command): void |
||
54 | { |
||
55 | try { |
||
56 | $board = $this->progressBoardRepository->getBoardByUuid($command->getBoardUuid()); |
||
57 | } catch (BoardNotFoundException $e) { |
||
58 | throw new InvalidCommandDataException($e->getMessage(), $e->getCode(), $e); |
||
59 | } |
||
60 | $profile = $board->getProfile(); |
||
61 | |||
62 | try { |
||
63 | $transformation = $this->boardTransformationFactory->factory($profile); |
||
64 | } catch (BoardTransformationNotFoundException $e) { |
||
65 | throw new InvalidCommandDataException($e->getMessage(), $e->getCode(), $e); |
||
66 | } |
||
67 | |||
68 | if ($transformation->isLastState($board->getStep()->getState())) { |
||
69 | try { |
||
70 | $unitTransformation = $this->unitTransformationFactory->factory($profile); |
||
71 | $this->unitRepository->addUnit(Unit::createFromBoard($board, $unitTransformation)); |
||
72 | } catch (UnitTransformationNotFoundException $e) { |
||
73 | throw new InvalidCommandDataException($e->getMessage(), $e->getCode(), $e); |
||
74 | } catch (UnitUnfinishedStepPassedForTransformationException $e) { |
||
75 | throw new InvalidCommandDataException($e->getMessage(), $e->getCode(), $e); |
||
76 | } catch (UnprocessableUnitException $e) { |
||
77 | throw new InvalidCommandDataException($e->getMessage(), $e->getCode(), $e); |
||
78 | } catch (UnitExistException $e) { |
||
79 | throw new InvalidCommandDataException($e->getMessage(), $e->getCode(), $e); |
||
80 | } |
||
81 | } else { |
||
82 | try { |
||
83 | $board->transformStep($transformation); |
||
84 | } catch (BoardUnfinishedStepPassedForTransformationException $e) { |
||
85 | throw new InvalidCommandDataException($e->getMessage(), $e->getCode(), $e); |
||
86 | } catch (UnprocessableBoardException $e) { |
||
87 | throw new InvalidCommandDataException($e->getMessage(), $e->getCode(), $e); |
||
88 | } |
||
92 |