Conditions | 23 |
Paths | 634 |
Total Lines | 81 |
Code Lines | 45 |
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 |
||
52 | protected function getTableInfo(array &$tableColumns, array &$tableValues): void { |
||
53 | if ($this->xmlFileContents->getName() != 'mysqldump') { |
||
54 | throw new RuntimeException('The root element of a MySQL XML data set file must be called <mysqldump>'); |
||
55 | } |
||
56 | |||
57 | foreach ($this->xmlFileContents->xpath('./database/table_data') as $tableElement) { |
||
58 | if (empty($tableElement['name'])) { |
||
59 | throw new RuntimeException('<table_data> elements must include a name attribute'); |
||
60 | } |
||
61 | |||
62 | $tableName = (string) $tableElement['name']; |
||
63 | |||
64 | if (!isset($tableColumns[$tableName])) { |
||
65 | $tableColumns[$tableName] = []; |
||
66 | } |
||
67 | |||
68 | if (!isset($tableValues[$tableName])) { |
||
69 | $tableValues[$tableName] = []; |
||
70 | } |
||
71 | |||
72 | foreach ($tableElement->xpath('./row') as $rowElement) { |
||
73 | $rowValues = []; |
||
74 | |||
75 | foreach ($rowElement->xpath('./field') as $columnElement) { |
||
76 | if (empty($columnElement['name'])) { |
||
77 | throw new RuntimeException('<field> element name attributes cannot be empty'); |
||
78 | } |
||
79 | |||
80 | $columnName = (string) $columnElement['name']; |
||
81 | |||
82 | if (!\in_array($columnName, $tableColumns[$tableName])) { |
||
83 | $tableColumns[$tableName][] = $columnName; |
||
84 | } |
||
85 | } |
||
86 | |||
87 | foreach ($tableColumns[$tableName] as $columnName) { |
||
88 | $fields = $rowElement->xpath('./field[@name="' . $columnName . '"]'); |
||
89 | |||
90 | if (!isset($fields[0])) { |
||
91 | throw new RuntimeException( |
||
92 | \sprintf( |
||
93 | '%s column doesn\'t exist in current row for table %s', |
||
94 | $columnName, |
||
95 | $tableName |
||
96 | ) |
||
97 | ); |
||
98 | } |
||
99 | |||
100 | $column = $fields[0]; |
||
101 | $attr = $column->attributes('http://www.w3.org/2001/XMLSchema-instance'); |
||
102 | |||
103 | if (isset($attr['type']) && (string) $attr['type'] === 'xs:hexBinary') { |
||
104 | $columnValue = \pack('H*', (string) $column); |
||
105 | } else { |
||
106 | $null = isset($column['nil']) || isset($attr[0]); |
||
107 | $columnValue = $null ? null : (string) $column; |
||
108 | } |
||
109 | |||
110 | $rowValues[$columnName] = $columnValue; |
||
111 | } |
||
112 | |||
113 | $tableValues[$tableName][] = $rowValues; |
||
114 | } |
||
115 | } |
||
116 | |||
117 | foreach ($this->xmlFileContents->xpath('./database/table_structure') as $tableElement) { |
||
118 | if (empty($tableElement['name'])) { |
||
119 | throw new RuntimeException('<table_structure> elements must include a name attribute'); |
||
120 | } |
||
121 | |||
122 | $tableName = (string) $tableElement['name']; |
||
123 | |||
124 | foreach ($tableElement->xpath('./field') as $fieldElement) { |
||
125 | if (empty($fieldElement['Field']) && empty($fieldElement['field'])) { |
||
126 | throw new RuntimeException('<field> elements must include a Field attribute'); |
||
127 | } |
||
128 | |||
129 | $columnName = (string) (empty($fieldElement['Field']) ? $fieldElement['field'] : $fieldElement['Field']); |
||
130 | |||
131 | if (!\in_array($columnName, $tableColumns[$tableName])) { |
||
132 | $tableColumns[$tableName][] = $columnName; |
||
133 | } |
||
158 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.