Conditions | 7 |
Paths | 11 |
Total Lines | 54 |
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 |
||
22 | protected function executeConfigured(InputInterface $input, OutputInterface $output, Storeman $storeman): int |
||
23 | { |
||
24 | $revision = $input->getArgument('revision'); |
||
25 | $index = null; |
||
26 | |||
27 | if ($revision === 'latest') |
||
28 | { |
||
29 | $revision = $storeman->getLastRevision(); |
||
30 | |||
31 | if ($revision === null) |
||
32 | { |
||
33 | $this->consoleStyle->writeln("Could not find any past synchronizations to show."); |
||
34 | |||
35 | return 0; |
||
36 | } |
||
37 | } |
||
38 | elseif ($revision === 'local') |
||
39 | { |
||
40 | $index = $storeman->getLocalIndex(); |
||
41 | } |
||
42 | elseif (ctype_digit($revision)) |
||
43 | { |
||
44 | $revision = intval($revision); |
||
45 | } |
||
46 | else |
||
47 | { |
||
48 | $this->consoleStyle->error("Argument 'revision' invalid."); |
||
49 | |||
50 | return 1; |
||
51 | } |
||
52 | |||
53 | if ($index === null) |
||
54 | { |
||
55 | assert(is_int($revision)); |
||
56 | |||
57 | $vaults = $storeman->getVaultContainer(); |
||
58 | $vault = $vaults->getPrioritizedVault($vaults->getVaultsHavingRevision($revision)); |
||
59 | |||
60 | if ($vault === null) |
||
61 | { |
||
62 | $this->consoleStyle->error("Could not find requested revision {$revision} in any vault."); |
||
63 | |||
64 | return 1; |
||
65 | } |
||
66 | |||
67 | $index = $vault->loadRemoteIndex($revision); |
||
68 | } |
||
69 | |||
70 | /** @var DisplayIndexHelper $displayIndexHelper */ |
||
71 | $displayIndexHelper = $this->getHelper('displayIndex'); |
||
72 | $displayIndexHelper->displayIndex($index, $output); |
||
|
|||
73 | |||
74 | return 0; |
||
75 | } |
||
76 | } |
||
77 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: