|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Softonic\GraphQL\DataObjects; |
|
4
|
|
|
|
|
5
|
|
|
use Softonic\GraphQL\DataObjects\Interfaces\DataObject; |
|
6
|
|
|
use Softonic\GraphQL\DataObjects\Mutation\FilteredCollection; |
|
7
|
|
|
use Softonic\GraphQL\DataObjects\Traits\ObjectHandler; |
|
8
|
|
|
|
|
9
|
|
|
class AbstractItem implements DataObject, \JsonSerializable |
|
10
|
|
|
{ |
|
11
|
|
|
use ObjectHandler; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @var array |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $arguments; |
|
17
|
|
|
|
|
18
|
124 |
|
public function __construct(array $arguments) |
|
19
|
|
|
{ |
|
20
|
124 |
|
$this->arguments = $arguments; |
|
21
|
124 |
|
} |
|
22
|
|
|
|
|
23
|
4 |
|
public function has(string $key): bool |
|
24
|
|
|
{ |
|
25
|
4 |
|
$keyPath = explode('.', $key); |
|
26
|
4 |
|
$firstKey = array_shift($keyPath); |
|
27
|
|
|
|
|
28
|
4 |
|
if (!array_key_exists($firstKey, $this->arguments)) { |
|
29
|
4 |
|
return false; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
4 |
|
if (empty($keyPath)) { |
|
33
|
4 |
|
return true; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
2 |
|
$nextKey = implode('.', $keyPath); |
|
37
|
|
|
|
|
38
|
2 |
|
return $this->arguments[$firstKey]->has($nextKey); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
84 |
|
public function __get(string $key) |
|
42
|
|
|
{ |
|
43
|
84 |
|
return array_key_exists($key, $this->arguments) ? $this->arguments[$key] : null; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
34 |
|
public function __set(string $key, $value): void |
|
47
|
|
|
{ |
|
48
|
34 |
|
$this->arguments[$key] = $value; |
|
49
|
34 |
|
} |
|
50
|
|
|
|
|
51
|
2 |
|
public function exists(array $data): bool |
|
52
|
|
|
{ |
|
53
|
2 |
|
return $data === $this->arguments; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
52 |
|
public function jsonSerialize() |
|
57
|
|
|
{ |
|
58
|
52 |
|
$item = []; |
|
59
|
52 |
|
foreach ($this->arguments as $key => $value) { |
|
60
|
52 |
|
if ($value instanceof FilteredCollection && !$value->hasChildren()) { |
|
61
|
2 |
|
continue; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
52 |
|
if ($value instanceof \JsonSerializable) { |
|
|
|
|
|
|
65
|
52 |
|
if (!empty($valueSerialized = $value->jsonSerialize())) { |
|
66
|
52 |
|
$item[$key] = $valueSerialized; |
|
67
|
|
|
} |
|
68
|
|
|
} else { |
|
69
|
52 |
|
$item[$key] = $value; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
52 |
|
return $item; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.