Skip to content

Commit 0343129

Browse files
committed
fix: replace custom string conversion with direct casting for XML attributes.
1 parent 7868c49 commit 0343129

File tree

1 file changed

+6
-36
lines changed

1 file changed

+6
-36
lines changed

tests/TestCase.php

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,16 @@ protected function buildFlatXMLDataSet(array $dataSet): string
129129

130130
foreach ($dataSet as $item) {
131131
$treeElement = $xml->addChild($item['type']);
132-
$treeElement?->addAttribute('id', $this->convertToString($item['id']));
132+
$treeElement?->addAttribute('id', (string) $item['id']);
133133

134134
if ($item['type'] === 'multiple_tree') {
135-
$treeElement?->addAttribute('tree', $this->convertToString($item['tree']));
135+
$treeElement?->addAttribute('tree', (string) $item['tree']);
136136
}
137137

138-
$treeElement?->addAttribute('lft', $this->convertToString($item['lft']));
139-
$treeElement?->addAttribute('rgt', $this->convertToString($item['rgt']));
140-
$treeElement?->addAttribute('depth', $this->convertToString($item['depth']));
141-
$treeElement?->addAttribute('name', $this->convertToString($item['name']));
138+
$treeElement?->addAttribute('lft', (string) $item['lft']);
139+
$treeElement?->addAttribute('rgt', (string) $item['rgt']);
140+
$treeElement?->addAttribute('depth', (string) $item['depth']);
141+
$treeElement?->addAttribute('name', $item['name']);
142142
}
143143

144144
$dom = dom_import_simplexml($xml)->ownerDocument;
@@ -166,36 +166,6 @@ protected function buildFlatXMLDataSet(array $dataSet): string
166166
);
167167
}
168168

169-
/**
170-
* Converts a value to string, handling Oracle resource types correctly.
171-
*
172-
* Oracle database may return numeric values as resource types when using `asArray()` with {@see ActiveRecord}.
173-
*
174-
* This method properly converts those resources to strings for use with {@see SimpleXMLElement::addAttribute()}.
175-
*
176-
* @param int|resource|string|null $value The value to convert to string
177-
*
178-
* @return string The converted string value
179-
*/
180-
protected function convertToString($value): string
181-
{
182-
if (is_resource($value)) {
183-
$content = stream_get_contents($value);
184-
185-
if (is_string($content)) {
186-
return trim($content);
187-
}
188-
189-
return '';
190-
}
191-
192-
if ($value === null) {
193-
return '';
194-
}
195-
196-
return (string) $value;
197-
}
198-
199169
protected function createDatabase(): void
200170
{
201171
$command = $this->getDb()->createCommand();

0 commit comments

Comments
 (0)