Conditions | 16 |
Paths | 529 |
Total Lines | 93 |
Code Lines | 59 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 1 | Features | 3 |
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 |
||
37 | protected function execute(InputInterface $input, OutputInterface $output) |
||
38 | { |
||
39 | $this->detectMagento($output, true); |
||
40 | |||
41 | if (!$this->initMagento()) { |
||
42 | return; |
||
43 | } |
||
44 | |||
45 | $time = microtime(true); |
||
46 | $ignoreDataUpdate = $input->getOption('ignore-data'); |
||
47 | |||
48 | $headers = array('Setup', 'Module', 'DB', 'Data', 'Status'); |
||
49 | if ($ignoreDataUpdate) { |
||
50 | unset($headers[array_search('Data', $headers)]); |
||
51 | } |
||
52 | |||
53 | $errorCounter = 0; |
||
54 | $table = array(); |
||
55 | foreach ($this->getMagentoModuleList()->getAll() as $moduleName => $moduleInfo) { |
||
56 | |||
57 | $moduleVersion = $moduleInfo['setup_version']; |
||
58 | $dbVersion = $this->getMagentoModuleResource()->getDbVersion($moduleName); |
||
59 | if (!$ignoreDataUpdate) { |
||
60 | $dataVersion = $this->getMagentoModuleResource()->getDataVersion($moduleName); |
||
61 | } |
||
62 | |||
63 | $ok = $dbVersion == $moduleVersion; |
||
64 | if ($ok && !$ignoreDataUpdate) { |
||
65 | $ok = $dataVersion == $moduleVersion; |
||
|
|||
66 | } |
||
67 | if (!$ok) { |
||
68 | $errorCounter++; |
||
69 | } |
||
70 | |||
71 | $row = array( |
||
72 | 'Module' => $moduleName, |
||
73 | 'DB' => $dbVersion, |
||
74 | 'Data' => $dataVersion, |
||
75 | ); |
||
76 | |||
77 | if (!$ignoreDataUpdate) { |
||
78 | $row['Data-Version'] = $dataVersion; |
||
79 | } |
||
80 | $row['Status'] = $ok ? 'OK' : 'Error'; |
||
81 | $table[] = $row; |
||
82 | } |
||
83 | |||
84 | // If there is no output format highlight the status and show error'd rows at bottom |
||
85 | if (!$input->getOption('format')) { |
||
86 | |||
87 | usort($table, function($a, $b) { |
||
88 | return $a['Status'] !== 'OK'; |
||
89 | }); |
||
90 | |||
91 | array_walk($table, function (&$row) { |
||
92 | $status = $row['Status']; |
||
93 | $availableStatus = array('OK' => 'info', 'Error' => 'error'); |
||
94 | $statusString = sprintf( |
||
95 | '<%s>%s</%s>', |
||
96 | $availableStatus[$status], |
||
97 | $status, |
||
98 | $availableStatus[$status] |
||
99 | ); |
||
100 | $row['Status'] = $statusString; |
||
101 | }); |
||
102 | } |
||
103 | |||
104 | if ($input->getOption('log-junit')) { |
||
105 | $this->logJUnit($table, $input->getOption('log-junit'), microtime($time) - $time); |
||
106 | } else { |
||
107 | $this->getHelper('table') |
||
108 | ->setHeaders($headers) |
||
109 | ->renderByFormat($output, $table, $input->getOption('format')); |
||
110 | |||
111 | //if no output format specified - output summary line |
||
112 | if (!$input->getOption('format')) { |
||
113 | if ($errorCounter > 0) { |
||
114 | $this->writeSection( |
||
115 | $output, |
||
116 | sprintf( |
||
117 | '%s error%s %s found!', |
||
118 | $errorCounter, |
||
119 | $errorCounter === 1 ? '' : 's', |
||
120 | $errorCounter === 1 ? 'was' : 'were' |
||
121 | ), |
||
122 | 'error' |
||
123 | ); |
||
124 | } else { |
||
125 | $this->writeSection($output, 'No setup problems were found.', 'info'); |
||
126 | } |
||
127 | } |
||
128 | } |
||
129 | } |
||
130 | |||
164 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: