1 | <?php |
||
23 | class Json extends AbstractFile |
||
24 | { |
||
25 | /** |
||
26 | * Kind. |
||
27 | */ |
||
28 | public const KIND = 'JsonEndpoint'; |
||
29 | |||
30 | /** |
||
31 | * Init endpoint. |
||
32 | */ |
||
33 | public function __construct(string $name, string $type, string $file, StorageInterface $storage, CollectionInterface $collection, WorkflowFactory $workflow, LoggerInterface $logger, array $resource = []) |
||
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | public function setup(bool $simulate = false): EndpointInterface |
||
46 | { |
||
47 | if ($this->type === EndpointInterface::TYPE_DESTINATION) { |
||
48 | $streams = [$this->file => $this->storage->openWriteStream($this->file)]; |
||
49 | } else { |
||
50 | $streams = $this->storage->openReadStreams($this->file); |
||
51 | } |
||
52 | |||
53 | foreach ($streams as $path => $stream) { |
||
54 | $content = []; |
||
|
|||
55 | // if ($this->type === EndpointInterface::TYPE_SOURCE) { |
||
56 | $content = json_decode(stream_get_contents($stream), true); |
||
57 | |||
58 | if ($err = json_last_error() !== JSON_ERROR_NONE) { |
||
59 | throw new JsonException\InvalidJson('failed decode json '.$this->file.', json error '.$err); |
||
60 | } |
||
61 | |||
62 | if (!is_array($content)) { |
||
63 | throw new JsonException\ArrayExpected('json file contents must be an array'); |
||
64 | } |
||
65 | // } |
||
66 | |||
67 | $this->files[] = [ |
||
68 | 'stream' => $stream, |
||
69 | 'content' => $content, |
||
70 | 'path' => $path, |
||
71 | ]; |
||
72 | } |
||
73 | |||
74 | return $this; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | public function shutdown(bool $simulate = false): EndpointInterface |
||
100 | |||
101 | /** |
||
102 | * {@inheritdoc} |
||
103 | */ |
||
104 | public function transformQuery(?array $query = null) |
||
121 | |||
122 | /** |
||
123 | * {@inheritdoc} |
||
124 | */ |
||
125 | public function getAll(?array $query = null): Generator |
||
152 | |||
153 | /** |
||
154 | * {@inheritdoc} |
||
155 | */ |
||
156 | public function create(AttributeMapInterface $map, array $object, bool $simulate = false): ?string |
||
169 | |||
170 | /** |
||
171 | * {@inheritdoc} |
||
172 | */ |
||
173 | public function getDiff(AttributeMapInterface $map, array $diff): array |
||
177 | |||
178 | /** |
||
179 | * {@inheritdoc} |
||
180 | */ |
||
181 | public function change(AttributeMapInterface $map, array $diff, array $object, array $endpoint_object, bool $simulate = false): ?string |
||
185 | |||
186 | /** |
||
187 | * {@inheritdoc} |
||
188 | */ |
||
189 | public function delete(AttributeMapInterface $map, array $object, array $endpoint_object, bool $simulate = false): bool |
||
193 | |||
194 | /** |
||
195 | * {@inheritdoc} |
||
196 | */ |
||
197 | public function getOne(array $object, array $attributes = []): EndpointObjectInterface |
||
226 | } |
||
227 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.