Skip to content

Commit

Permalink
feat: Struct::isArrayOf() now returns type of array's children
Browse files Browse the repository at this point in the history
  • Loading branch information
Ondrej Vana committed Sep 27, 2015
1 parent 54642e6 commit 3db9e02
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/Keboola/Json/Struct.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function load(array $struct = [])
if (
!is_scalar($type)
|| (!$this->isValidType($type)
&& !($this->isArrayOf($type) && $this->isValidType(substr($type, 7))))
&& !($this->isValidType($this->isArrayOf($type))))
) {
if (!is_scalar($type)) {
$type = json_encode($type);
Expand Down Expand Up @@ -166,7 +166,7 @@ protected function upgradeToArrayCheck($oldType, $newType)
{
return $this->autoUpgradeToArray
&& (
($this->isArrayOf($oldType) && substr($oldType, 7) == $newType)
($this->isArrayOf($oldType) == $newType)
|| $newType == 'arrayOf' . $oldType
);
}
Expand All @@ -189,12 +189,11 @@ protected function upgradeToArray($oldType, $newType)

/**
* @param string $type
* @return bool
* @todo return the type without arrayOf?
* @return string type of array chuldren
*/
public function isArrayOf($type)
{
return substr($type, 0, 7) == 'arrayOf';
return substr($type, 0, 7) == 'arrayOf' ? substr($type, 7) : false;
}

/**
Expand Down

0 comments on commit 3db9e02

Please sign in to comment.