| Conditions | 10 |
| Paths | 26 |
| Total Lines | 60 |
| 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 |
||
| 134 | protected function runConfigFile() |
||
| 135 | { |
||
| 136 | $codeception = $this->executable; |
||
| 137 | |||
| 138 | if (!$codeception) { |
||
| 139 | $this->builder->logFailure(sprintf('Could not find "%s" binary', 'codecept')); |
||
| 140 | |||
| 141 | return false; |
||
| 142 | } |
||
| 143 | |||
| 144 | $cmd = 'cd "%s" && ' . $codeception . ' run -c "%s" ' . $this->args . ' --xml'; |
||
| 145 | |||
| 146 | $success = $this->builder->executeCommand($cmd, $this->directory, $this->ymlConfigFile); |
||
| 147 | if (!$success) { |
||
| 148 | return false; |
||
| 149 | } |
||
| 150 | |||
| 151 | $parser = new YamlParser(); |
||
| 152 | $yaml = file_get_contents($this->ymlConfigFile); |
||
| 153 | $config = (array)$parser->parse($yaml); |
||
| 154 | |||
| 155 | $trueReportXmlPath = null; |
||
| 156 | if ($config && isset($config['paths']['log'])) { |
||
|
|
|||
| 157 | $trueReportXmlPath = rtrim($config['paths']['log'], '/\\') . '/'; |
||
| 158 | } |
||
| 159 | |||
| 160 | if (!file_exists($trueReportXmlPath . 'report.xml')) { |
||
| 161 | foreach ($this->outputPath as $outputPath) { |
||
| 162 | $trueReportXmlPath = rtrim($outputPath, '/\\') . '/'; |
||
| 163 | if (file_exists($trueReportXmlPath . 'report.xml')) { |
||
| 164 | break; |
||
| 165 | } |
||
| 166 | } |
||
| 167 | } |
||
| 168 | |||
| 169 | if (!file_exists($trueReportXmlPath . 'report.xml')) { |
||
| 170 | $this->builder->logFailure('"report.xml" file can not be found in configured "output_path!"'); |
||
| 171 | |||
| 172 | return false; |
||
| 173 | } |
||
| 174 | |||
| 175 | $parser = new Parser($this->builder, ($trueReportXmlPath . 'report.xml')); |
||
| 176 | $output = $parser->parse(); |
||
| 177 | |||
| 178 | $meta = [ |
||
| 179 | 'tests' => $parser->getTotalTests(), |
||
| 180 | 'timetaken' => $parser->getTotalTimeTaken(), |
||
| 181 | 'failures' => $parser->getTotalFailures(), |
||
| 182 | ]; |
||
| 183 | |||
| 184 | // NOTE: Codeception does not use stderr, so failure can only be detected |
||
| 185 | // through tests |
||
| 186 | $success = $success && (intval($meta['failures']) < 1); |
||
| 187 | |||
| 188 | $this->build->storeMeta((self::pluginName() . '-meta'), $meta); |
||
| 189 | $this->build->storeMeta((self::pluginName() . '-data'), $output); |
||
| 190 | $this->build->storeMeta((self::pluginName() . '-errors'), $parser->getTotalFailures()); |
||
| 191 | |||
| 192 | return $success; |
||
| 193 | } |
||
| 194 | } |
||
| 195 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.