Version 5.1 - All the GraphQL #32

Closed
timw4mail wants to merge 1160 commits from develop into master
2 changed files with 30 additions and 27 deletions
Showing only changes of commit 103f95c07b - Show all commits

View File

@ -3,16 +3,14 @@ parameters:
checkMissingIterableValueType: false checkMissingIterableValueType: false
inferPrivatePropertyTypeFromConstructor: true inferPrivatePropertyTypeFromConstructor: true
level: 7 level: 7
autoload_files:
- %rootDir%/../../../tests/mocks.php
paths: paths:
- src - src
- ./console - ./console
- index.php - index.php
ignoreErrors: ignoreErrors:
- '#Access to an undefined property Aviat\\\Ion\\\Friend::\$[a-zA-Z0-9_]+#' - "#Offset 'fields' does not exist on array#"
- '#Call to an undefined method Aviat\\\Ion\\\Friend::[a-zA-Z0-9_]+\(\)#'
- '#Call to an undefined method Aura\\\Html\\\HelperLocator::[a-zA-Z0-9_]+\(\)#' - '#Call to an undefined method Aura\\\Html\\\HelperLocator::[a-zA-Z0-9_]+\(\)#'
- '#Property Amp\\Artax\\Internal\\RequestCycle::\$[a-zA-Z0-9_]+#' - '#Call to an undefined method Query\\QueryBuilderInterface::[a-zA-Z0-9_]+\(\)#'
excludes_analyse: excludes_analyse:
- tests/mocks.php - tests/mocks.php
- vendor

View File

@ -43,8 +43,7 @@ abstract class AbstractType implements ArrayAccess, Countable {
if (get_parent_class($currentClass) !== FALSE) if (get_parent_class($currentClass) !== FALSE)
{ {
$output = static::class::from($data)->toArray(); return static::class::from($data)->toArray();
return (is_array($output)) ? $output : [];
} }
return NULL; return NULL;
@ -210,27 +209,12 @@ abstract class AbstractType implements ArrayAccess, Countable {
* Returns early on primitive values to work recursively. * Returns early on primitive values to work recursively.
* *
* @param mixed $parent * @param mixed $parent
* @return float|bool|null|int|array|string * @return array
*/ */
final public function toArray(mixed $parent = null): float|null|bool|int|array|string final public function toArray(mixed $parent = null): array
{ {
$object = $parent ?? $this; $fromObject = $this->fromObject($parent);
return (is_array($fromObject)) ? $fromObject : [];
if (is_scalar($object) || $object === NULL)
{
return $object;
}
$output = [];
foreach ($object as $key => $value)
{
$output[$key] = (is_scalar($value) || empty($value))
? $value
: $this->toArray((array) $value);
}
return $output;
} }
/** /**
@ -251,4 +235,25 @@ abstract class AbstractType implements ArrayAccess, Countable {
return TRUE; return TRUE;
} }
final protected function fromObject(mixed $parent = null): float|null|bool|int|array|string
{
$object = $parent ?? $this;
if (is_scalar($object) || $object === NULL)
{
return $object;
}
$output = [];
foreach ($object as $key => $value)
{
$output[$key] = (is_scalar($value) || empty($value))
? $value
: $this->fromObject((array) $value);
}
return $output;
}
} }