| Conditions | 23 |
| Paths | 1352 |
| Total Lines | 85 |
| Code Lines | 53 |
| 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 |
||
| 137 | private function processImportNode(ImportNode $node, Context $context, $importParent) |
||
| 138 | { |
||
| 139 | $e = null; |
||
| 140 | try { |
||
| 141 | $compiledNode = $node->compileForImport($context); |
||
| 142 | } catch (Exception $e) { |
||
| 143 | $compiledNode = false; |
||
| 144 | if (!$e->getCurrentFile()) { |
||
| 145 | if ($node->currentFileInfo) { |
||
| 146 | $e->setCurrentFile($node->currentFileInfo, $node->index); |
||
| 147 | } else { |
||
| 148 | $e->setIndex($node->index); |
||
| 149 | } |
||
| 150 | } |
||
| 151 | $node->css = true; |
||
| 152 | $node->error = $e; |
||
| 153 | } |
||
| 154 | |||
| 155 | $inlineCSS = $node->getOption('inline'); |
||
| 156 | $isPlugin = $node->getOption('plugin'); |
||
| 157 | |||
| 158 | if ($compiledNode && (!$compiledNode->css || $inlineCSS)) { |
||
| 159 | if ($node->getOption('multiple')) { |
||
| 160 | $context->importMultiple = true; |
||
| 161 | } |
||
| 162 | |||
| 163 | for ($i = 0; $i < count($importParent->rules); ++$i) { |
||
|
|
|||
| 164 | if ($importParent->rules[$i] === $node) { |
||
| 165 | $importParent->rules[$i] = $compiledNode; |
||
| 166 | break; |
||
| 167 | } |
||
| 168 | } |
||
| 169 | |||
| 170 | $tryAppendLessExtension = !$compiledNode->css; |
||
| 171 | |||
| 172 | try { |
||
| 173 | // import the file |
||
| 174 | list($alreadyImported, $file) = $this->importer->import( |
||
| 175 | $compiledNode->getPath(), |
||
| 176 | $tryAppendLessExtension, |
||
| 177 | $compiledNode->currentFileInfo, |
||
| 178 | $compiledNode->options, |
||
| 179 | $compiledNode->index |
||
| 180 | ); |
||
| 181 | |||
| 182 | /* @var $file ImportedFile */ |
||
| 183 | if (!$context->importMultiple) { |
||
| 184 | if ($alreadyImported) { |
||
| 185 | $compiledNode->skip = true; |
||
| 186 | } |
||
| 187 | } |
||
| 188 | |||
| 189 | if ($root = $file->getRuleset()) { |
||
| 190 | /* @var $root RulesetNode */ |
||
| 191 | $compiledNode->root = $root; |
||
| 192 | $compiledNode->importedFilename = $file->getPath(); |
||
| 193 | if (!$inlineCSS && !$isPlugin && ($context->importMultiple || !$alreadyImported)) { |
||
| 194 | $oldEnv = $this->context; |
||
| 195 | $this->context = $context; |
||
| 196 | try { |
||
| 197 | $this->visit($root); |
||
| 198 | } catch (Exception $e) { |
||
| 199 | $this->error = $e; |
||
| 200 | } |
||
| 201 | |||
| 202 | $this->end = $oldEnv; |
||
| 203 | } |
||
| 204 | } |
||
| 205 | } catch (ImportException $e) { |
||
| 206 | // optional import |
||
| 207 | if (isset($compiledNode->options['optional']) && $compiledNode->options['optional']) { |
||
| 208 | // optional import |
||
| 209 | } else { |
||
| 210 | $this->error = $e; |
||
| 211 | } |
||
| 212 | } catch (Exception $e) { |
||
| 213 | $this->error = $e; |
||
| 214 | } |
||
| 215 | } |
||
| 216 | |||
| 217 | --$this->importCount; |
||
| 218 | if ($this->isFinished) { |
||
| 219 | $this->sequencer->tryRun(); |
||
| 220 | } |
||
| 221 | } |
||
| 222 | |||
| 379 |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: