Skip to content

Commit 5a704be

Browse files
committed
Can't array_sum string values, use array_is_list (since 8.1) and count() instead
also adds @throws annotation
1 parent d9c7904 commit 5a704be

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/DataStreams/TabularInlineDataStream.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,27 @@
77

88
class TabularInlineDataStream extends TabularDataStream
99
{
10+
11+
/**
12+
* @throws \frictionlessdata\datapackage\Exceptions\DataStreamOpenException
13+
*/
1014
protected function getDataSourceObject()
1115
{
1216
$data = json_decode(json_encode($this->dataSource), true);
1317
if (is_array($data)) {
1418
$numFields = count($this->schema->fields());
1519
$objRows = [];
16-
if (array_sum(array_keys($data[0])) == array_sum(range(0, $numFields - 1))) {
20+
if (!function_exists('array_is_list')) {
21+
function array_is_list(array $arr):bool
22+
{
23+
if ($arr === []) {
24+
return true;
25+
}
26+
return array_keys($arr) === range(0, count($arr) - 1);
27+
}
28+
}
29+
30+
if (array_is_list($data[0]) && (count($data[0])) == $numFields) {
1731
// Row Arrays - convert to Row Objects
1832
$header = array_shift($data);
1933
foreach ($data as $row) {

0 commit comments

Comments
 (0)