| Conditions | 7 |
| Paths | 6 |
| Total Lines | 74 |
| Code Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 7 | ||
| Bugs | 0 | Features | 5 |
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 |
||
| 68 | public function createXsd(EveApiEventInterface $event, $eventName, MediatorInterface $yem) |
||
| 69 | { |
||
| 70 | $this->setYem($yem); |
||
| 71 | $data = $event->getData(); |
||
| 72 | $this->getYem() |
||
| 73 | ->triggerLogEvent( |
||
| 74 | 'Yapeal.Log.log', |
||
| 75 | Logger::DEBUG, |
||
| 76 | $this->getReceivedEventMessage($data, $eventName, __CLASS__) |
||
| 77 | ); |
||
| 78 | // Only work with raw unaltered XML data. |
||
| 79 | if (false !== strpos($data->getEveApiXml(), '<?yapeal.parameters.json')) { |
||
| 80 | return $event->setHandledSufficiently(); |
||
| 81 | } |
||
| 82 | $outputFile = sprintf( |
||
| 83 | '%1$s%2$s/%3$s.xsd', |
||
| 84 | $this->getDir(), |
||
| 85 | $data->getEveApiSectionName(), |
||
| 86 | $data->getEveApiName() |
||
| 87 | ); |
||
| 88 | // Nothing to do if NOT overwriting and file exists. |
||
| 89 | if (false === $this->isOverwrite() && is_file($outputFile)) { |
||
| 90 | return $event; |
||
| 91 | } |
||
| 92 | $this->sectionName = $data->getEveApiSectionName(); |
||
| 93 | $xml = $data->getEveApiXml(); |
||
| 94 | if (false === $xml) { |
||
| 95 | return $event->setHandledSufficiently(); |
||
| 96 | } |
||
| 97 | $sxi = new SimpleXMLIterator($xml); |
||
| 98 | $this->tables = []; |
||
| 99 | $this->processValueOnly($sxi, lcfirst($data->getEveApiName())); |
||
| 100 | $this->processRowset($sxi); |
||
| 101 | list($mSec, $sec) = explode(' ', microtime()); |
||
| 102 | $vars = [ |
||
| 103 | 'className' => lcfirst($data->getEveApiName()), |
||
| 104 | 'tables' => $this->tables, |
||
| 105 | 'sectionName' => lcfirst($this->sectionName), |
||
| 106 | 'version' => gmdate('YmdHis', $sec) . sprintf('.%0-3s', floor($mSec * 1000)) |
||
| 107 | ]; |
||
| 108 | try { |
||
| 109 | $contents = $this->getTwig() |
||
| 110 | ->render('xsd.twig', $vars); |
||
| 111 | } catch (\Twig_Error $exc) { |
||
| 112 | $this->getYem() |
||
| 113 | ->triggerLogEvent('Yapeal.Log.log', Logger::ERROR, 'Twig error', ['exception' => $exc]); |
||
| 114 | $this->getYem() |
||
| 115 | ->triggerLogEvent( |
||
| 116 | 'Yapeal.Log.log', |
||
| 117 | Logger::WARNING, |
||
| 118 | $this->getFailedToWriteFile($data, $eventName, $outputFile) |
||
| 119 | ); |
||
| 120 | return $event; |
||
| 121 | } |
||
| 122 | $tidyConfig = [ |
||
| 123 | 'indent' => true, |
||
| 124 | 'indent-spaces' => 4, |
||
| 125 | 'input-xml' => true, |
||
| 126 | 'newline' => 'LF', |
||
| 127 | 'output-xml' => true, |
||
| 128 | 'wrap' => '120' |
||
| 129 | ]; |
||
| 130 | $contents = (new tidy())->repairString($contents, $tidyConfig, 'utf8'); |
||
| 131 | if (false === $this->saveToFile($outputFile, $contents)) { |
||
| 132 | $this->getYem() |
||
| 133 | ->triggerLogEvent( |
||
| 134 | $eventName, |
||
| 135 | Logger::WARNING, |
||
| 136 | $this->getFailedToWriteFile($data, $eventName, $outputFile) |
||
| 137 | ); |
||
| 138 | return $event; |
||
| 139 | } |
||
| 140 | return $event->setHandledSufficiently(); |
||
| 141 | } |
||
| 142 | /** |
||
| 273 |
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.