Skip to content

Commit

Permalink
refactor: fix TypeError in BaseUtils
Browse files Browse the repository at this point in the history
1) CodeIgniter\Database\Live\DbUtilsTest::testUtilsCSVFromResult
TypeError: str_replace(): Argument #3 ($subject) must be of type array|string, int given

/home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/BaseUtils.php:217
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Database/Live/DbUtilsTest.php:186

2) CodeIgniter\Database\Live\DbUtilsTest::testUtilsXMLFromResult
TypeError: xml_convert(): Argument #1 ($str) must be of type string, int given, called in /home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/BaseUtils.php on line 249

/home/runner/work/CodeIgniter4/CodeIgniter4/system/Helpers/xml_helper.php:20
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/BaseUtils.php:249
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Database/Live/DbUtilsTest.php:199
  • Loading branch information
kenjis committed Nov 29, 2023
1 parent 0772251 commit 5d52f33
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions system/Database/BaseUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function getCSVFromResult(ResultInterface $query, string $delim = ',', st
$line = [];

foreach ($row as $item) {
$line[] = $enclosure . str_replace($enclosure, $enclosure . $enclosure, $item ?? '') . $enclosure;
$line[] = $enclosure . str_replace($enclosure, $enclosure . $enclosure, (string) $item ?? '') . $enclosure;
}

$out .= implode($delim, $line) . $newline;
Expand Down Expand Up @@ -246,7 +246,7 @@ public function getXMLFromResult(ResultInterface $query, array $params = []): st
$xml .= $tab . '<' . $element . '>' . $newline;

foreach ($row as $key => $val) {
$val = (! empty($val)) ? xml_convert($val) : '';
$val = (! empty($val)) ? xml_convert((string) $val) : '';

$xml .= $tab . $tab . '<' . $key . '>' . $val . '</' . $key . '>' . $newline;
}
Expand Down

0 comments on commit 5d52f33

Please sign in to comment.