Conditions | 10 |
Paths | 16 |
Total Lines | 38 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
42 | public function loadXML(string $strXMLFile) : int |
||
43 | { |
||
44 | if (!file_exists($strXMLFile)) { |
||
45 | // if file not exist, there is nothing more to do... |
||
46 | $this->strErrorMsg = 'Missing form file: ' . $strXMLFile; |
||
47 | return self::E_FILE_NOT_EXIST; |
||
48 | } |
||
49 | // to get more detailed information about XML errors and XML schema validation |
||
50 | libxml_use_internal_errors(true); |
||
51 | $iResult = self::E_XML_ERROR; |
||
52 | $oXMLForm = new \DOMDocument(); |
||
53 | if ($oXMLForm->load($strXMLFile)) { |
||
54 | $iResult = self::E_OK; |
||
|
|||
55 | // the XML schema is allways expected in the same directory as the XML file itself |
||
56 | $strXSDFile = pathinfo($strXMLFile, PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR . self::XML_SCHEMA; |
||
57 | $oRoot = $oXMLForm->documentElement; |
||
58 | if ($this->bSchemaValidate && !$oXMLForm->schemaValidate($strXSDFile)) { |
||
59 | $iResult = self::E_XSD_ERROR; |
||
60 | } elseif ($oRoot->nodeName != 'FormGenerator') { |
||
61 | $this->strErrorMsg = 'Missing document root <FormGenerator> in form file: ' . $strXMLFile; |
||
62 | $iResult = self::E_MISSING_ROOT; |
||
63 | } elseif (($oForm = $this->getXMLChild($oRoot, 'Form')) === null) { |
||
64 | $this->strErrorMsg = 'Missing form elemnt <Form> as first child of the root: ' . $strXMLFile; |
||
65 | $iResult = self::E_MISSING_FORM; |
||
66 | } else { |
||
67 | // First we read some general infos for the form |
||
68 | $this->readAdditionalXML($oForm); |
||
69 | |||
70 | // and iterate recursive through the child elements |
||
71 | $iResult = $this->createChildElements($oForm, $this); |
||
72 | } |
||
73 | } |
||
74 | if ($iResult != self::E_OK && strlen($this->strErrorMsg) == 0) { |
||
75 | $this->strErrorMsg = ($iResult != self::E_XSD_ERROR ? 'XML error: ' : 'XSD Schema validation error: '); |
||
76 | $this->strErrorMsg .= $this->getFormatedXMLError($this->bPlainError); |
||
77 | } |
||
78 | libxml_clear_errors(); |
||
79 | return $iResult; |
||
80 | } |
||
145 |