Conditions | 8 |
Paths | 6 |
Total Lines | 58 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 9 | ||
Bugs | 1 | 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 |
||
67 | public function validateEveApi(EveApiEventInterface $event, $eventName, MediatorInterface $yem) |
||
68 | { |
||
69 | $this->setYem($yem); |
||
70 | $data = $event->getData(); |
||
71 | $yem->triggerLogEvent('Yapeal.Log.log', |
||
72 | Logger::DEBUG, |
||
73 | $this->getReceivedEventMessage($data, $eventName, __CLASS__)); |
||
74 | $htmlError = strpos($data->getEveApiXml(), '<!DOCTYPE html'); |
||
75 | if (false !== $htmlError) { |
||
76 | $mess = 'Received HTML result from '; |
||
77 | $yem->triggerLogEvent('Yapeal.Log.log', Logger::NOTICE, $this->createEveApiMessage($mess, $data)); |
||
78 | $apiName = $data->getEveApiName(); |
||
79 | $data->setEveApiName('Invalid_' . $apiName); |
||
80 | // Cache error html. |
||
81 | $this->emitEvents($data, 'preserve', 'Yapeal.Xml.Error'); |
||
82 | $data->setEveApiName($apiName); |
||
83 | return $event->setData($data); |
||
84 | } |
||
85 | $fileName = $this->findEveApiFile($data->getEveApiSectionName(), $data->getEveApiName(), 'xsd'); |
||
86 | if ('' === $fileName) { |
||
87 | return $event; |
||
88 | } |
||
89 | libxml_clear_errors(); |
||
90 | libxml_use_internal_errors(true); |
||
91 | libxml_clear_errors(); |
||
92 | $dom = new \DOMDocument(); |
||
93 | $loaded = $dom->loadXML($data->getEveApiXml()); |
||
94 | if (!$loaded || !$dom->schemaValidate($fileName)) { |
||
95 | /** |
||
96 | * @var array $errors |
||
97 | */ |
||
98 | $errors = libxml_get_errors(); |
||
99 | if (0 !== count($errors)) { |
||
100 | foreach ($errors as $error) { |
||
101 | $this->getYem() |
||
102 | ->triggerLogEvent('Yapeal.Log.log', Logger::NOTICE, $error->message); |
||
103 | } |
||
104 | } |
||
105 | libxml_clear_errors(); |
||
106 | libxml_use_internal_errors(false); |
||
107 | libxml_clear_errors(); |
||
108 | $apiName = $data->getEveApiName(); |
||
109 | $data->setEveApiName('Invalid_' . $apiName); |
||
110 | // Cache error causing XML. |
||
111 | $this->emitEvents($data, 'preserve', 'Yapeal.Xml.Error'); |
||
112 | $data->setEveApiName($apiName); |
||
113 | return $event->setData($data); |
||
114 | } |
||
115 | libxml_clear_errors(); |
||
116 | libxml_use_internal_errors(false); |
||
117 | libxml_clear_errors(); |
||
118 | // Check for XML error element. |
||
119 | if (false !== strpos($data->getEveApiXml(), '<error ')) { |
||
120 | $this->emitEvents($data, 'start', 'Yapeal.Xml.Error'); |
||
121 | return $event->setData($data); |
||
122 | } |
||
123 | return $event->setHandledSufficiently(); |
||
124 | } |
||
125 | /** |
||
140 |