1 | <?php |
||
29 | class XMLConverter |
||
30 | { |
||
31 | /** |
||
32 | * XML Root name. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $root_name = 'csv'; |
||
37 | |||
38 | /** |
||
39 | * XML Node name. |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $record_name = 'row'; |
||
44 | |||
45 | /** |
||
46 | * XML Item name. |
||
47 | * |
||
48 | * @var string |
||
49 | */ |
||
50 | protected $field_name = 'cell'; |
||
51 | |||
52 | /** |
||
53 | * XML column attribute name. |
||
54 | * |
||
55 | * @var string |
||
56 | */ |
||
57 | protected $column_attr = ''; |
||
58 | |||
59 | /** |
||
60 | * XML offset attribute name. |
||
61 | * |
||
62 | * @var string |
||
63 | */ |
||
64 | protected $offset_attr = ''; |
||
65 | |||
66 | /** |
||
67 | * Conversion method list. |
||
68 | * |
||
69 | * @var array |
||
70 | */ |
||
71 | protected $encoder = [ |
||
72 | 'field' => [ |
||
73 | true => 'fieldToElementWithAttribute', |
||
74 | false => 'fieldToElement', |
||
75 | ], |
||
76 | 'record' => [ |
||
77 | true => 'recordToElementWithAttribute', |
||
78 | false => 'recordToElement', |
||
79 | ], |
||
80 | ]; |
||
81 | |||
82 | /** |
||
83 | * Convert a Record collection into a DOMDocument. |
||
84 | * |
||
85 | * @param array|Traversable $records the CSV records collection |
||
86 | * |
||
87 | 6 | * @return DOMDocument |
|
88 | */ |
||
89 | 6 | public function convert($records): DOMDocument |
|
100 | |||
101 | 3 | /** |
|
102 | * Create a new DOMElement related to the given DOMDocument. |
||
103 | 3 | * |
|
104 | * **DOES NOT** attach to the DOMDocument |
||
105 | * |
||
106 | * @param iterable $records |
||
107 | * |
||
108 | * @return DOMElement |
||
109 | */ |
||
110 | 3 | public function import($records, DOMDocument $doc): DOMElement |
|
126 | |||
127 | 3 | /** |
|
128 | 3 | * Convert a CSV record into a DOMElement and |
|
129 | 3 | * adds its offset as DOMElement attribute. |
|
130 | 3 | */ |
|
131 | protected function recordToElementWithAttribute( |
||
142 | |||
143 | /** |
||
144 | 3 | * Convert a CSV record into a DOMElement. |
|
145 | */ |
||
146 | 3 | protected function recordToElement(DOMDocument $doc, array $record, string $field_encoder): DOMElement |
|
156 | |||
157 | 3 | /** |
|
158 | * Convert Cell to Item. |
||
159 | 3 | * |
|
160 | 3 | * Convert the CSV item into a DOMElement and adds the item offset |
|
161 | * as attribute to the returned DOMElement |
||
162 | 3 | * |
|
163 | * @param int|string $node_name |
||
164 | */ |
||
165 | protected function fieldToElementWithAttribute(DOMDocument $doc, string $value, $node_name): DOMElement |
||
172 | |||
173 | 3 | /** |
|
174 | * Convert Cell to Item. |
||
175 | * |
||
176 | * @param string $value Record item value |
||
177 | */ |
||
178 | protected function fieldToElement(DOMDocument $doc, string $value): DOMElement |
||
185 | |||
186 | /** |
||
187 | * XML root element setter. |
||
188 | */ |
||
189 | 3 | public function rootElement(string $node_name): self |
|
196 | |||
197 | /** |
||
198 | * Filter XML element name. |
||
199 | * |
||
200 | * @throws DOMException If the Element name is invalid |
||
201 | */ |
||
202 | protected function filterElementName(string $value): string |
||
206 | |||
207 | 6 | /** |
|
208 | 3 | * XML Record element setter. |
|
209 | */ |
||
210 | public function recordElement(string $node_name, string $record_offset_attribute_name = ''): self |
||
218 | |||
219 | 3 | /** |
|
220 | 3 | * Filter XML attribute name. |
|
221 | 3 | * |
|
222 | * @param string $value Element name |
||
223 | 3 | * |
|
224 | * @throws DOMException If the Element attribute name is invalid |
||
225 | */ |
||
226 | protected function filterAttributeName(string $value): string |
||
234 | |||
235 | /** |
||
236 | * XML Field element setter. |
||
237 | */ |
||
238 | public function fieldElement(string $node_name, string $fieldname_attribute_name = ''): self |
||
246 | } |
||
247 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: