Version 5.1 - All the GraphQL #32
@ -3,16 +3,14 @@ parameters:
|
||||
checkMissingIterableValueType: false
|
||||
inferPrivatePropertyTypeFromConstructor: true
|
||||
level: 7
|
||||
autoload_files:
|
||||
- %rootDir%/../../../tests/mocks.php
|
||||
paths:
|
||||
- src
|
||||
- ./console
|
||||
- index.php
|
||||
ignoreErrors:
|
||||
- '#Access to an undefined property Aviat\\\Ion\\\Friend::\$[a-zA-Z0-9_]+#'
|
||||
- '#Call to an undefined method Aviat\\\Ion\\\Friend::[a-zA-Z0-9_]+\(\)#'
|
||||
- "#Offset 'fields' does not exist on array#"
|
||||
- '#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:
|
||||
- tests/mocks.php
|
||||
- vendor
|
@ -43,8 +43,7 @@ abstract class AbstractType implements ArrayAccess, Countable {
|
||||
|
||||
if (get_parent_class($currentClass) !== FALSE)
|
||||
{
|
||||
$output = static::class::from($data)->toArray();
|
||||
return (is_array($output)) ? $output : [];
|
||||
return static::class::from($data)->toArray();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -210,27 +209,12 @@ abstract class AbstractType implements ArrayAccess, Countable {
|
||||
* Returns early on primitive values to work recursively.
|
||||
*
|
||||
* @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;
|
||||
|
||||
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;
|
||||
$fromObject = $this->fromObject($parent);
|
||||
return (is_array($fromObject)) ? $fromObject : [];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -251,4 +235,25 @@ abstract class AbstractType implements ArrayAccess, Countable {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user