| Conditions | 7 |
| Paths | 8 |
| Total Lines | 70 |
| Code Lines | 56 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 2 |
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 |
||
| 71 | public function createEveApi(EveApiEventInterface $event, $eventName, MediatorInterface $yem) |
||
| 72 | { |
||
| 73 | $this->setYem($yem); |
||
| 74 | $data = $event->getData(); |
||
| 75 | $this->getYem() |
||
| 76 | ->triggerLogEvent( |
||
| 77 | 'Yapeal.Log.log', |
||
| 78 | Logger::DEBUG, |
||
| 79 | $this->getReceivedEventMessage($data, $eventName, __CLASS__) |
||
| 80 | ); |
||
| 81 | // Only work with raw unaltered XML data. |
||
| 82 | if (false !== strpos($data->getEveApiXml(), '<?yapeal.parameters.json')) { |
||
| 83 | return $event->setHandledSufficiently(); |
||
| 84 | } |
||
| 85 | $outputFile = sprintf( |
||
| 86 | '%1$s%2$s/%3$s.php', |
||
| 87 | $this->getDir(), |
||
| 88 | $data->getEveApiSectionName(), |
||
| 89 | $data->getEveApiName() |
||
| 90 | ); |
||
| 91 | // Nothing to do if NOT overwriting and file exists. |
||
| 92 | if (false === $this->isOverwrite() && is_file($outputFile)) { |
||
| 93 | return $event; |
||
| 94 | } |
||
| 95 | $this->sectionName = $data->getEveApiSectionName(); |
||
| 96 | $sxi = new SimpleXMLIterator($data->getEveApiXml()); |
||
| 97 | $this->tables = []; |
||
| 98 | $this->processValueOnly($sxi, $data->getEveApiName()); |
||
| 99 | $this->processRowset($sxi, $data->getEveApiName()); |
||
| 100 | $tCount = count($this->tables); |
||
| 101 | if (0 === $tCount) { |
||
| 102 | $mess = 'No SQL tables to create for'; |
||
| 103 | $this->getYem() |
||
| 104 | ->triggerLogEvent('Yapeal.Log.log', Logger::NOTICE, $this->createEveApiMessage($mess, $data)); |
||
| 105 | } |
||
| 106 | ksort($this->tables); |
||
| 107 | $vars = [ |
||
| 108 | 'className' => ucfirst($data->getEveApiName()), |
||
| 109 | 'tables' => $this->tables, |
||
| 110 | 'hasOwner' => $this->hasOwner(), |
||
| 111 | 'mask' => $data->getEveApiArgument('mask'), |
||
| 112 | 'namespace' => $this->getNamespace(), |
||
| 113 | 'sectionName' => $this->sectionName, |
||
| 114 | 'tableNames' => array_keys($this->tables) |
||
| 115 | ]; |
||
| 116 | try { |
||
| 117 | $contents = $this->getTwig() |
||
| 118 | ->render('php.twig', $vars); |
||
| 119 | } catch (\Twig_Error $exp) { |
||
| 120 | $this->getYem() |
||
| 121 | ->triggerLogEvent('Yapeal.Log.log', Logger::ERROR, 'Twig error', ['exception' => $exp]); |
||
| 122 | $this->getYem() |
||
| 123 | ->triggerLogEvent( |
||
| 124 | 'Yapeal.Log.log', |
||
| 125 | Logger::WARNING, |
||
| 126 | $this->getFailedToWriteFile($data, $eventName, $outputFile) |
||
| 127 | ); |
||
| 128 | return $event; |
||
| 129 | } |
||
| 130 | if (false === $this->saveToFile($outputFile, $contents)) { |
||
| 131 | $this->getYem() |
||
| 132 | ->triggerLogEvent( |
||
| 133 | $eventName, |
||
| 134 | Logger::WARNING, |
||
| 135 | $this->getFailedToWriteFile($data, $eventName, $outputFile) |
||
| 136 | ); |
||
| 137 | return $event; |
||
| 138 | } |
||
| 139 | return $event->setHandledSufficiently(); |
||
| 140 | } |
||
| 141 | /** |
||
| 275 |
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.