Patch passing array to jsonToArroy not working.
This commit is contained in:
parent
7b6e35108f
commit
63a748e4dc
@ -315,15 +315,31 @@ class Utils
|
||||
$json = (array) $json;
|
||||
$typeName = [];
|
||||
|
||||
foreach ($json as $key => $param) {
|
||||
if (is_array($param) && $depth > 1) {
|
||||
foreach ($param as $subKey => $subParam) {
|
||||
$json[$key][$subKey] = self::jsonToArray($subParam, $depth-1);
|
||||
if ($depth > 1) {
|
||||
foreach ($json as $key => $param) {
|
||||
if (is_array($param)) {
|
||||
foreach ($param as $subKey => $subParam) {
|
||||
$json[$key][$subKey] = self::jsonToArray($subParam, $depth-1);
|
||||
}
|
||||
} elseif ($param instanceof stdClass) {
|
||||
$json[$key] = self::jsonToArray($param, $depth-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $json;
|
||||
} elseif (!is_array($json)) {
|
||||
} elseif (is_array($json)) {
|
||||
if ($depth > 1) {
|
||||
foreach ($json as $key => $param) {
|
||||
if (is_array($param)) {
|
||||
foreach ($param as $subKey => $subParam) {
|
||||
$json[$key][$subKey] = self::jsonToArray($subParam, $depth-1);
|
||||
}
|
||||
} elseif ($param instanceof stdClass) {
|
||||
$json[$key] = self::jsonToArray($param, $depth-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new InvalidArgumentException('jsonToArray json must be array or stdClass.');
|
||||
}
|
||||
return $json;
|
||||
|
@ -44,7 +44,10 @@ class UtilsTest extends TestCase
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
"type": "function",
|
||||
"test": {
|
||||
"name": "testObject"
|
||||
}
|
||||
}';
|
||||
|
||||
/**
|
||||
@ -270,13 +273,17 @@ class UtilsTest extends TestCase
|
||||
public function testJsonToArray()
|
||||
{
|
||||
$json = json_decode($this->testJsonMethodString);
|
||||
$jsonArray = Utils::jsonToArray($json);
|
||||
$jsonArrayDepth1 = Utils::jsonToArray($json);
|
||||
|
||||
$this->assertEquals($jsonArray, (array) $json);
|
||||
$this->assertEquals($jsonArrayDepth1, (array) $json);
|
||||
|
||||
$jsonAssoc = json_decode($this->testJsonMethodString, true);
|
||||
$jsonArray = Utils::jsonToArray($json, 2);
|
||||
$jsonArrayDepth2 = Utils::jsonToArray($json, 2);
|
||||
|
||||
$this->assertEquals($jsonArray, $jsonAssoc);
|
||||
$this->assertEquals($jsonArrayDepth2, $jsonAssoc);
|
||||
|
||||
$jsonArrayDepth2 = Utils::jsonToArray($jsonArrayDepth1, 2);
|
||||
|
||||
$this->assertEquals($jsonArrayDepth2, $jsonAssoc);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user