• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 15133993414

20 May 2025 09:30AM UTC coverage: 26.313% (-1.2%) from 27.493%
15133993414

Pull #7161

github

web-flow
Merge e2c03d45f into 5459ba375
Pull Request #7161: fix(metadata): infer parameter string type from schema

0 of 2 new or added lines in 1 file covered. (0.0%)

11019 existing lines in 363 files now uncovered.

12898 of 49018 relevant lines covered (26.31%)

34.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

48.73
/src/Metadata/Extractor/XmlResourceExtractor.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\Metadata\Extractor;
15

16
use ApiPlatform\Elasticsearch\State\Options;
17
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
18
use ApiPlatform\Metadata\GetCollection;
19
use ApiPlatform\Metadata\HeaderParameter;
20
use ApiPlatform\Metadata\Post;
21
use ApiPlatform\Metadata\QueryParameter;
22
use ApiPlatform\OpenApi\Model\ExternalDocumentation;
23
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
24
use ApiPlatform\OpenApi\Model\Parameter as OpenApiParameter;
25
use ApiPlatform\OpenApi\Model\RequestBody;
26
use ApiPlatform\State\OptionsInterface;
27
use Symfony\Component\Config\Util\XmlUtils;
28
use Symfony\Component\WebLink\Link;
29

30
/**
31
 * Extracts an array of metadata from a list of XML files.
32
 *
33
 * @author Vincent Chalamon <vincentchalamon@gmail.com>
34
 */
35
final class XmlResourceExtractor extends AbstractResourceExtractor
36
{
37
    use ResourceExtractorTrait;
38

39
    public const SCHEMA = __DIR__.'/schema/resources.xsd';
40

41
    /**
42
     * {@inheritdoc}
43
     */
44
    protected function extractPath(string $path): void
45
    {
46
        try {
47
            /** @var \SimpleXMLElement $xml */
UNCOV
48
            $xml = simplexml_import_dom(XmlUtils::loadFile($path, self::SCHEMA));
69✔
UNCOV
49
        } catch (\InvalidArgumentException $e) {
69✔
50
            // Ensure it's not a resource
51
            try {
UNCOV
52
                simplexml_import_dom(XmlUtils::loadFile($path, XmlPropertyExtractor::SCHEMA));
69✔
53
            } catch (\InvalidArgumentException) {
×
54
                throw new InvalidArgumentException(\sprintf('Error while parsing %s: %s', $path, $e->getMessage()), $e->getCode(), $e);
×
55
            }
56

57
            // It's a property: ignore error
UNCOV
58
            return;
69✔
59
        }
60

UNCOV
61
        foreach ($xml->resource as $resource) {
69✔
UNCOV
62
            $base = $this->buildExtendedBase($resource);
69✔
UNCOV
63
            $this->resources[$this->resolve((string) $resource['class'])][] = array_merge($base, [
69✔
UNCOV
64
                'operations' => $this->buildOperations($resource, $base),
69✔
UNCOV
65
                'graphQlOperations' => $this->buildGraphQlOperations($resource, $base),
69✔
UNCOV
66
            ]);
69✔
67
        }
68
    }
69

70
    private function buildExtendedBase(\SimpleXMLElement $resource): array
71
    {
UNCOV
72
        return array_merge($this->buildBase($resource), [
69✔
UNCOV
73
            'uriTemplate' => $this->phpize($resource, 'uriTemplate', 'string'),
69✔
UNCOV
74
            'routePrefix' => $this->phpize($resource, 'routePrefix', 'string'),
69✔
UNCOV
75
            'stateless' => $this->phpize($resource, 'stateless', 'bool'),
69✔
UNCOV
76
            'sunset' => $this->phpize($resource, 'sunset', 'string'),
69✔
UNCOV
77
            'acceptPatch' => $this->phpize($resource, 'acceptPatch', 'string'),
69✔
UNCOV
78
            'status' => $this->phpize($resource, 'status', 'integer'),
69✔
UNCOV
79
            'host' => $this->phpize($resource, 'host', 'string'),
69✔
UNCOV
80
            'condition' => $this->phpize($resource, 'condition', 'string'),
69✔
UNCOV
81
            'controller' => $this->phpize($resource, 'controller', 'string'),
69✔
UNCOV
82
            'types' => $this->buildArrayValue($resource, 'type'),
69✔
UNCOV
83
            'formats' => $this->buildFormats($resource, 'formats'),
69✔
UNCOV
84
            'inputFormats' => $this->buildFormats($resource, 'inputFormats'),
69✔
UNCOV
85
            'outputFormats' => $this->buildFormats($resource, 'outputFormats'),
69✔
UNCOV
86
            'uriVariables' => $this->buildUriVariables($resource),
69✔
UNCOV
87
            'defaults' => isset($resource->defaults->values) ? $this->buildValues($resource->defaults->values) : null,
69✔
UNCOV
88
            'requirements' => $this->buildRequirements($resource),
69✔
UNCOV
89
            'options' => isset($resource->options->values) ? $this->buildValues($resource->options->values) : null,
69✔
UNCOV
90
            'schemes' => $this->buildArrayValue($resource, 'scheme'),
69✔
UNCOV
91
            'cacheHeaders' => $this->buildCacheHeaders($resource),
69✔
UNCOV
92
            'hydraContext' => isset($resource->hydraContext->values) ? $this->buildValues($resource->hydraContext->values) : null,
69✔
UNCOV
93
            'openapi' => $this->buildOpenapi($resource),
69✔
UNCOV
94
            'paginationViaCursor' => $this->buildPaginationViaCursor($resource),
69✔
UNCOV
95
            'exceptionToStatus' => $this->buildExceptionToStatus($resource),
69✔
UNCOV
96
            'queryParameterValidationEnabled' => $this->phpize($resource, 'queryParameterValidationEnabled', 'bool'),
69✔
UNCOV
97
            'strictQueryParameterValidation' => $this->phpize($resource, 'strictQueryParameterValidation', 'bool'),
69✔
UNCOV
98
            'hideHydraOperation' => $this->phpize($resource, 'hideHydraOperation', 'bool'),
69✔
UNCOV
99
            'stateOptions' => $this->buildStateOptions($resource),
69✔
UNCOV
100
            'links' => $this->buildLinks($resource),
69✔
UNCOV
101
            'headers' => $this->buildHeaders($resource),
69✔
UNCOV
102
            'parameters' => $this->buildParameters($resource),
69✔
UNCOV
103
        ]);
69✔
104
    }
105

106
    private function buildBase(\SimpleXMLElement $resource): array
107
    {
UNCOV
108
        return [
69✔
UNCOV
109
            'shortName' => $this->phpize($resource, 'shortName', 'string'),
69✔
UNCOV
110
            'description' => $this->phpize($resource, 'description', 'string'),
69✔
UNCOV
111
            'urlGenerationStrategy' => $this->phpize($resource, 'urlGenerationStrategy', 'integer'),
69✔
UNCOV
112
            'deprecationReason' => $this->phpize($resource, 'deprecationReason', 'string'),
69✔
UNCOV
113
            'elasticsearch' => $this->phpize($resource, 'elasticsearch', 'bool'),
69✔
UNCOV
114
            'messenger' => $this->phpize($resource, 'messenger', 'bool|string'),
69✔
UNCOV
115
            'mercure' => $this->buildMercure($resource),
69✔
UNCOV
116
            'input' => $this->phpize($resource, 'input', 'bool|string'),
69✔
UNCOV
117
            'output' => $this->phpize($resource, 'output', 'bool|string'),
69✔
UNCOV
118
            'fetchPartial' => $this->phpize($resource, 'fetchPartial', 'bool'),
69✔
UNCOV
119
            'forceEager' => $this->phpize($resource, 'forceEager', 'bool'),
69✔
UNCOV
120
            'paginationClientEnabled' => $this->phpize($resource, 'paginationClientEnabled', 'bool'),
69✔
UNCOV
121
            'paginationClientItemsPerPage' => $this->phpize($resource, 'paginationClientItemsPerPage', 'bool'),
69✔
UNCOV
122
            'paginationClientPartial' => $this->phpize($resource, 'paginationClientPartial', 'bool'),
69✔
UNCOV
123
            'paginationEnabled' => $this->phpize($resource, 'paginationEnabled', 'bool'),
69✔
UNCOV
124
            'paginationFetchJoinCollection' => $this->phpize($resource, 'paginationFetchJoinCollection', 'bool'),
69✔
UNCOV
125
            'paginationUseOutputWalkers' => $this->phpize($resource, 'paginationUseOutputWalkers', 'bool'),
69✔
UNCOV
126
            'paginationItemsPerPage' => $this->phpize($resource, 'paginationItemsPerPage', 'integer'),
69✔
UNCOV
127
            'paginationMaximumItemsPerPage' => $this->phpize($resource, 'paginationMaximumItemsPerPage', 'integer'),
69✔
UNCOV
128
            'paginationPartial' => $this->phpize($resource, 'paginationPartial', 'bool'),
69✔
UNCOV
129
            'paginationType' => $this->phpize($resource, 'paginationType', 'string'),
69✔
UNCOV
130
            'processor' => $this->phpize($resource, 'processor', 'string'),
69✔
UNCOV
131
            'provider' => $this->phpize($resource, 'provider', 'string'),
69✔
UNCOV
132
            'security' => $this->phpize($resource, 'security', 'string'),
69✔
UNCOV
133
            'securityMessage' => $this->phpize($resource, 'securityMessage', 'string'),
69✔
UNCOV
134
            'securityPostDenormalize' => $this->phpize($resource, 'securityPostDenormalize', 'string'),
69✔
UNCOV
135
            'securityPostDenormalizeMessage' => $this->phpize($resource, 'securityPostDenormalizeMessage', 'string'),
69✔
UNCOV
136
            'securityPostValidation' => $this->phpize($resource, 'securityPostValidation', 'string'),
69✔
UNCOV
137
            'securityPostValidationMessage' => $this->phpize($resource, 'securityPostValidationMessage', 'string'),
69✔
UNCOV
138
            'normalizationContext' => isset($resource->normalizationContext->values) ? $this->buildValues($resource->normalizationContext->values) : null,
69✔
UNCOV
139
            'denormalizationContext' => isset($resource->denormalizationContext->values) ? $this->buildValues($resource->denormalizationContext->values) : null,
69✔
UNCOV
140
            'collectDenormalizationErrors' => $this->phpize($resource, 'collectDenormalizationErrors', 'bool'),
69✔
UNCOV
141
            'validationContext' => isset($resource->validationContext->values) ? $this->buildValues($resource->validationContext->values) : null,
69✔
UNCOV
142
            'filters' => $this->buildArrayValue($resource, 'filter'),
69✔
UNCOV
143
            'order' => isset($resource->order->values) ? $this->buildValues($resource->order->values) : null,
69✔
UNCOV
144
            'extraProperties' => $this->buildExtraProperties($resource, 'extraProperties'),
69✔
UNCOV
145
            'read' => $this->phpize($resource, 'read', 'bool'),
69✔
UNCOV
146
            'write' => $this->phpize($resource, 'write', 'bool'),
69✔
UNCOV
147
        ];
69✔
148
    }
149

150
    private function buildFormats(\SimpleXMLElement $resource, string $key): ?array
151
    {
UNCOV
152
        if (!isset($resource->{$key}->format)) {
69✔
UNCOV
153
            return null;
69✔
154
        }
155

156
        $data = [];
×
157
        foreach ($resource->{$key}->format as $format) {
×
158
            if (isset($format['name'])) {
×
159
                $data[(string) $format['name']] = (string) $format;
×
160
                continue;
×
161
            }
162

163
            $data[] = (string) $format;
×
164
        }
165

166
        return $data;
×
167
    }
168

169
    private function buildOpenapi(\SimpleXMLElement $resource): bool|OpenApiOperation|null
170
    {
UNCOV
171
        if (!isset($resource->openapi) && !isset($resource['openapi'])) {
69✔
UNCOV
172
            return null;
69✔
173
        }
174

175
        if (isset($resource['openapi']) && \in_array((string) $resource['openapi'], ['1', '0', 'true', 'false'], true)) {
×
176
            return $this->phpize($resource, 'openapi', 'bool');
×
177
        }
178

179
        $openapi = $resource->openapi;
×
180
        $data = [];
×
181
        $attributes = $openapi->attributes();
×
182
        foreach ($attributes as $attribute) {
×
183
            $data[$attribute->getName()] = $this->phpize($attributes, 'deprecated', 'deprecated' === $attribute->getName() ? 'bool' : 'string');
×
184
        }
185

186
        $data['tags'] = $this->buildArrayValue($resource, 'tag');
×
187

188
        if (isset($openapi->responses->response)) {
×
189
            foreach ($openapi->responses->response as $response) {
×
190
                $data['responses'][(string) $response->attributes()->status] = [
×
191
                    'description' => $this->phpize($response, 'description', 'string'),
×
192
                    'content' => isset($response->content->values) ? $this->buildValues($response->content->values) : null,
×
193
                    'headers' => isset($response->headers->values) ? $this->buildValues($response->headers->values) : null,
×
194
                    'links' => isset($response->links->values) ? $this->buildValues($response->links->values) : null,
×
195
                ];
×
196
            }
197
        }
198

199
        $data['externalDocs'] = isset($openapi->externalDocs) ? new ExternalDocumentation(
×
200
            description: $this->phpize($resource, 'description', 'string'),
×
201
            url: $this->phpize($resource, 'url', 'string'),
×
202
        ) : null;
×
203

204
        if (isset($openapi->parameters->parameter)) {
×
205
            foreach ($openapi->parameters->parameter as $parameter) {
×
206
                $data['parameters'][(string) $parameter->attributes()->name] = new OpenApiParameter(
×
207
                    name: $this->phpize($parameter, 'name', 'string'),
×
208
                    in: $this->phpize($parameter, 'in', 'string'),
×
209
                    description: $this->phpize($parameter, 'description', 'string'),
×
210
                    required: $this->phpize($parameter, 'required', 'bool'),
×
211
                    deprecated: $this->phpize($parameter, 'deprecated', 'bool'),
×
212
                    allowEmptyValue: $this->phpize($parameter, 'allowEmptyValue', 'bool'),
×
213
                    schema: isset($parameter->schema->values) ? $this->buildValues($parameter->schema->values) : null,
×
214
                    style: $this->phpize($parameter, 'style', 'string'),
×
215
                    explode: $this->phpize($parameter, 'explode', 'bool'),
×
216
                    allowReserved: $this->phpize($parameter, 'allowReserved', 'bool'),
×
217
                    example: $this->phpize($parameter, 'example', 'string'),
×
218
                    examples: isset($parameter->examples->values) ? new \ArrayObject($this->buildValues($parameter->examples->values)) : null,
×
219
                    content: isset($parameter->content->values) ? new \ArrayObject($this->buildValues($parameter->content->values)) : null,
×
220
                );
×
221
            }
222
        }
223
        $data['requestBody'] = isset($openapi->requestBody) ? new RequestBody(
×
224
            description: $this->phpize($openapi->requestBody, 'description', 'string'),
×
225
            content: isset($openapi->requestBody->content->values) ? new \ArrayObject($this->buildValues($openapi->requestBody->content->values)) : null,
×
226
            required: $this->phpize($openapi->requestBody, 'required', 'bool'),
×
227
        ) : null;
×
228

229
        $data['callbacks'] = isset($openapi->callbacks->values) ? new \ArrayObject($this->buildValues($openapi->callbacks->values)) : null;
×
230

231
        $data['security'] = isset($openapi->security->values) ? $this->buildValues($openapi->security->values) : null;
×
232

233
        if (isset($openapi->servers->server)) {
×
234
            foreach ($openapi->servers->server as $server) {
×
235
                $data['servers'][] = [
×
236
                    'description' => $this->phpize($server, 'description', 'string'),
×
237
                    'url' => $this->phpize($server, 'url', 'string'),
×
238
                    'variables' => isset($server->variables->values) ? $this->buildValues($server->variables->values) : null,
×
239
                ];
×
240
            }
241
        }
242

243
        $data['extensionProperties'] = isset($openapi->extensionProperties->values) ? $this->buildValues($openapi->extensionProperties->values) : null;
×
244

245
        foreach ($data as $key => $value) {
×
246
            if (null === $value) {
×
247
                unset($data[$key]);
×
248
            }
249
        }
250

251
        return new OpenApiOperation(...$data);
×
252
    }
253

254
    private function buildUriVariables(\SimpleXMLElement $resource): ?array
255
    {
UNCOV
256
        if (!isset($resource->uriVariables->uriVariable)) {
69✔
UNCOV
257
            return null;
69✔
258
        }
259

UNCOV
260
        $uriVariables = [];
69✔
UNCOV
261
        foreach ($resource->uriVariables->uriVariable as $data) {
69✔
UNCOV
262
            $parameterName = (string) $data['parameterName'];
69✔
UNCOV
263
            if (1 === (null === $data->attributes() ? 0 : \count($data->attributes()))) {
69✔
UNCOV
264
                $uriVariables[$parameterName] = $parameterName;
69✔
UNCOV
265
                continue;
69✔
266
            }
267

UNCOV
268
            if ($fromProperty = $this->phpize($data, 'fromProperty', 'string')) {
69✔
269
                $uriVariables[$parameterName]['from_property'] = $fromProperty;
×
270
            }
UNCOV
271
            if ($toProperty = $this->phpize($data, 'toProperty', 'string')) {
69✔
UNCOV
272
                $uriVariables[$parameterName]['to_property'] = $toProperty;
69✔
273
            }
UNCOV
274
            if ($fromClass = $this->resolve($this->phpize($data, 'fromClass', 'string'))) {
69✔
UNCOV
275
                $uriVariables[$parameterName]['from_class'] = $fromClass;
69✔
276
            }
UNCOV
277
            if ($toClass = $this->resolve($this->phpize($data, 'toClass', 'string'))) {
69✔
278
                $uriVariables[$parameterName]['to_class'] = $toClass;
×
279
            }
UNCOV
280
            if (isset($data->identifiers->values)) {
69✔
281
                $uriVariables[$parameterName]['identifiers'] = $this->buildValues($data->identifiers->values);
×
282
            }
UNCOV
283
            if (null !== ($compositeIdentifier = $this->phpize($data, 'compositeIdentifier', 'bool'))) {
69✔
284
                $uriVariables[$parameterName]['composite_identifier'] = $compositeIdentifier;
×
285
            }
286
        }
287

UNCOV
288
        return $uriVariables;
69✔
289
    }
290

291
    private function buildCacheHeaders(\SimpleXMLElement $resource): ?array
292
    {
UNCOV
293
        if (!isset($resource->cacheHeaders->cacheHeader)) {
69✔
UNCOV
294
            return null;
69✔
295
        }
296

297
        $data = [];
×
298
        foreach ($resource->cacheHeaders->cacheHeader as $cacheHeader) {
×
299
            if (isset($cacheHeader->values->value)) {
×
300
                $data[(string) $cacheHeader['name']] = $this->buildValues($cacheHeader->values);
×
301
                continue;
×
302
            }
303

304
            $data[(string) $cacheHeader['name']] = XmlUtils::phpize((string) $cacheHeader);
×
305
        }
306

307
        return $data;
×
308
    }
309

310
    private function buildRequirements(\SimpleXMLElement $resource): ?array
311
    {
UNCOV
312
        if (!isset($resource->requirements->requirement)) {
69✔
UNCOV
313
            return null;
69✔
314
        }
315

316
        $data = [];
×
317
        foreach ($resource->requirements->requirement as $requirement) {
×
318
            $data[(string) $requirement->attributes()->property] = (string) $requirement;
×
319
        }
320

321
        return $data;
×
322
    }
323

324
    private function buildMercure(\SimpleXMLElement $resource): array|bool|null
325
    {
UNCOV
326
        if (!isset($resource->mercure)) {
69✔
UNCOV
327
            return null;
69✔
328
        }
329

330
        if (null !== $resource->mercure->attributes()->private) {
×
331
            return ['private' => $this->phpize($resource->mercure->attributes(), 'private', 'bool')];
×
332
        }
333

334
        return true;
×
335
    }
336

337
    private function buildPaginationViaCursor(\SimpleXMLElement $resource): ?array
338
    {
UNCOV
339
        if (!isset($resource->paginationViaCursor->paginationField)) {
69✔
UNCOV
340
            return null;
69✔
341
        }
342

343
        $data = [];
×
344
        foreach ($resource->paginationViaCursor->paginationField as $paginationField) {
×
345
            $data[(string) $paginationField['field']] = (string) $paginationField['direction'];
×
346
        }
347

348
        return $data;
×
349
    }
350

351
    private function buildExceptionToStatus(\SimpleXMLElement $resource): ?array
352
    {
UNCOV
353
        if (!isset($resource->exceptionToStatus->exception)) {
69✔
UNCOV
354
            return null;
69✔
355
        }
356

357
        $data = [];
×
358
        foreach ($resource->exceptionToStatus->exception as $exception) {
×
359
            $data[(string) $exception['class']] = (int) $exception['statusCode'];
×
360
        }
361

362
        return $data;
×
363
    }
364

365
    private function buildExtraProperties(\SimpleXMLElement $resource, ?string $key = null): ?array
366
    {
UNCOV
367
        if (null !== $key) {
69✔
UNCOV
368
            if (!isset($resource->{$key})) {
69✔
UNCOV
369
                return null;
69✔
370
            }
371

372
            $resource = $resource->{$key};
×
373
        }
374

375
        return $this->buildValues($resource->values);
×
376
    }
377

378
    private function buildOperations(\SimpleXMLElement $resource, array $root): ?array
379
    {
UNCOV
380
        if (!isset($resource->operations->operation)) {
69✔
UNCOV
381
            return null;
69✔
382
        }
383

UNCOV
384
        $data = [];
69✔
UNCOV
385
        foreach ($resource->operations->operation as $operation) {
69✔
UNCOV
386
            $datum = $this->buildExtendedBase($operation);
69✔
UNCOV
387
            foreach ($datum as $key => $value) {
69✔
UNCOV
388
                if (null === $value) {
69✔
UNCOV
389
                    $datum[$key] = $root[$key];
69✔
390
                }
391
            }
392

UNCOV
393
            if (\in_array((string) $operation['class'], [GetCollection::class, Post::class], true)) {
69✔
UNCOV
394
                $datum['itemUriTemplate'] = $this->phpize($operation, 'itemUriTemplate', 'string');
69✔
UNCOV
395
            } elseif (isset($operation['itemUriTemplate'])) {
69✔
396
                throw new InvalidArgumentException(\sprintf('"itemUriTemplate" option is not allowed on a %s operation.', $operation['class']));
×
397
            }
398

UNCOV
399
            $data[] = array_merge($datum, [
69✔
UNCOV
400
                'collection' => $this->phpize($operation, 'collection', 'bool'),
69✔
UNCOV
401
                'class' => (string) $operation['class'],
69✔
UNCOV
402
                'method' => $this->phpize($operation, 'method', 'string'),
69✔
UNCOV
403
                'read' => $this->phpize($operation, 'read', 'bool'),
69✔
UNCOV
404
                'deserialize' => $this->phpize($operation, 'deserialize', 'bool'),
69✔
UNCOV
405
                'validate' => $this->phpize($operation, 'validate', 'bool'),
69✔
UNCOV
406
                'write' => $this->phpize($operation, 'write', 'bool'),
69✔
UNCOV
407
                'serialize' => $this->phpize($operation, 'serialize', 'bool'),
69✔
UNCOV
408
                'queryParameterValidate' => $this->phpize($operation, 'queryParameterValidate', 'bool'),
69✔
UNCOV
409
                'priority' => $this->phpize($operation, 'priority', 'integer'),
69✔
UNCOV
410
                'name' => $this->phpize($operation, 'name', 'string'),
69✔
UNCOV
411
                'routeName' => $this->phpize($operation, 'routeName', 'string'),
69✔
UNCOV
412
            ]);
69✔
413
        }
414

UNCOV
415
        return $data;
69✔
416
    }
417

418
    private function buildGraphQlOperations(\SimpleXMLElement $resource, array $root): ?array
419
    {
UNCOV
420
        if (!isset($resource->graphQlOperations->graphQlOperation)) {
69✔
UNCOV
421
            return null;
69✔
422
        }
423

424
        $data = [];
×
425
        foreach ($resource->graphQlOperations->graphQlOperation as $operation) {
×
426
            $datum = $this->buildBase($operation);
×
427
            foreach ($datum as $key => $value) {
×
428
                if (null === $value) {
×
429
                    $datum[$key] = $root[$key];
×
430
                }
431
            }
432

433
            $data[] = array_merge($datum, [
×
434
                'resolver' => $this->phpize($operation, 'resolver', 'string'),
×
435
                'args' => $this->buildArgs($operation),
×
436
                'extraArgs' => $this->buildExtraArgs($operation),
×
437
                'class' => (string) $operation['class'],
×
438
                'read' => $this->phpize($operation, 'read', 'bool'),
×
439
                'deserialize' => $this->phpize($operation, 'deserialize', 'bool'),
×
440
                'validate' => $this->phpize($operation, 'validate', 'bool'),
×
441
                'write' => $this->phpize($operation, 'write', 'bool'),
×
442
                'serialize' => $this->phpize($operation, 'serialize', 'bool'),
×
443
                'priority' => $this->phpize($operation, 'priority', 'integer'),
×
444
                'name' => $this->phpize($operation, 'name', 'string'),
×
445
            ]);
×
446
        }
447

448
        return $data;
×
449
    }
450

451
    private function buildStateOptions(\SimpleXMLElement $resource): ?OptionsInterface
452
    {
UNCOV
453
        $stateOptions = $resource->stateOptions ?? null;
69✔
UNCOV
454
        if (!$stateOptions) {
69✔
UNCOV
455
            return null;
69✔
456
        }
457
        $elasticsearchOptions = $stateOptions->elasticsearchOptions ?? null;
×
458
        if ($elasticsearchOptions) {
×
459
            if (class_exists(Options::class)) {
×
460
                return new Options(
×
461
                    isset($elasticsearchOptions['index']) ? (string) $elasticsearchOptions['index'] : null,
×
462
                    isset($elasticsearchOptions['type']) ? (string) $elasticsearchOptions['type'] : null,
×
463
                );
×
464
            }
465
        }
466

467
        return null;
×
468
    }
469

470
    /**
471
     * @return Link[]
472
     */
473
    private function buildLinks(\SimpleXMLElement $resource): ?array
474
    {
UNCOV
475
        if (!$resource->links) {
69✔
UNCOV
476
            return null;
69✔
477
        }
478

479
        $links = [];
×
480
        foreach ($resource->links as $link) {
×
481
            $links[] = new Link(rel: (string) $link->link->attributes()->rel, href: (string) $link->link->attributes()->href);
×
482
        }
483

484
        return $links;
×
485
    }
486

487
    /**
488
     * @return array<string, string>
489
     */
490
    private function buildHeaders(\SimpleXMLElement $resource): ?array
491
    {
UNCOV
492
        if (!$resource->headers) {
69✔
UNCOV
493
            return null;
69✔
494
        }
495

496
        $headers = [];
×
497
        foreach ($resource->headers as $header) {
×
498
            $headers[(string) $header->header->attributes()->key] = (string) $header->header->attributes()->value;
×
499
        }
500

501
        return $headers;
×
502
    }
503

504
    /**
505
     * @return array<string, \ApiPlatform\Metadata\Parameter>
506
     */
507
    private function buildParameters(\SimpleXMLElement $resource): ?array
508
    {
UNCOV
509
        if (!$resource->parameters) {
69✔
UNCOV
510
            return null;
69✔
511
        }
512

513
        $parameters = [];
×
514
        foreach ($resource->parameters->parameter as $parameter) {
×
515
            $key = (string) $parameter->attributes()->key;
×
516
            $cl = ('header' === (string) $parameter->attributes()->in) ? HeaderParameter::class : QueryParameter::class;
×
517
            $parameters[$key] = new $cl(
×
518
                key: $key,
×
519
                required: $this->phpize($parameter, 'required', 'bool'),
×
520
                schema: isset($parameter->schema->values) ? $this->buildValues($parameter->schema->values) : null,
×
521
                openApi: isset($parameter->openapi) ? new OpenApiParameter(
×
522
                    name: $this->phpize($parameter->openapi, 'name', 'string'),
×
523
                    in: $this->phpize($parameter->openapi, 'in', 'string'),
×
524
                    description: $this->phpize($parameter->openapi, 'description', 'string'),
×
525
                    required: $this->phpize($parameter->openapi, 'required', 'bool'),
×
526
                    deprecated: $this->phpize($parameter->openapi, 'deprecated', 'bool'),
×
527
                    allowEmptyValue: $this->phpize($parameter->openapi, 'allowEmptyValue', 'bool'),
×
528
                    schema: isset($parameter->openapi->schema->values) ? $this->buildValues($parameter->openapi->schema->values) : null,
×
529
                    style: $this->phpize($parameter->openapi, 'style', 'string'),
×
530
                    explode: $this->phpize($parameter->openapi, 'explode', 'bool'),
×
531
                    allowReserved: $this->phpize($parameter->openapi, 'allowReserved', 'bool'),
×
532
                    example: $this->phpize($parameter->openapi, 'example', 'string'),
×
533
                    examples: isset($parameter->openapi->examples->values) ? new \ArrayObject($this->buildValues($parameter->openapi->examples->values)) : null,
×
534
                    content: isset($parameter->openapi->content->values) ? new \ArrayObject($this->buildValues($parameter->openapi->content->values)) : null,
×
535
                ) : null,
×
536
                provider: $this->phpize($parameter, 'provider', 'string'),
×
537
                filter: $this->phpize($parameter, 'filter', 'string'),
×
538
                property: $this->phpize($parameter, 'property', 'string'),
×
539
                description: $this->phpize($parameter, 'description', 'string'),
×
540
                priority: $this->phpize($parameter, 'priority', 'integer'),
×
541
                extraProperties: $this->buildExtraProperties($parameter, 'extraProperties') ?? [],
×
542
            );
×
543
        }
544

545
        return $parameters;
×
546
    }
547
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc