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

api-platform / core / 10814494863

11 Sep 2024 03:11PM UTC coverage: 7.008% (-0.7%) from 7.679%
10814494863

push

github

web-flow
fix(state): remove resource_class change (#6607)

11516 of 164321 relevant lines covered (7.01%)

22.85 hits per line

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

48.56
/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 */
48
            $xml = simplexml_import_dom(XmlUtils::loadFile($path, self::SCHEMA));
42✔
49
        } catch (\InvalidArgumentException $e) {
42✔
50
            // Ensure it's not a resource
51
            try {
52
                simplexml_import_dom(XmlUtils::loadFile($path, XmlPropertyExtractor::SCHEMA));
42✔
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
58
            return;
42✔
59
        }
60

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

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

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

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

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

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

165
        return $data;
×
166
    }
167

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

287
        return $uriVariables;
42✔
288
    }
289

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

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

303
            $data[(string) $cacheHeader['name']] = (string) $cacheHeader;
×
304
        }
305

306
        return $data;
×
307
    }
308

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

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

320
        return $data;
×
321
    }
322

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

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

333
        return true;
×
334
    }
335

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

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

347
        return $data;
×
348
    }
349

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

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

361
        return $data;
×
362
    }
363

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

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

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

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

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

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

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

414
        return $data;
42✔
415
    }
416

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

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

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

447
        return $data;
×
448
    }
449

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

466
        return null;
×
467
    }
468

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

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

483
        return $links;
×
484
    }
485

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

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

500
        return $headers;
×
501
    }
502

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

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

544
        return $parameters;
×
545
    }
546
}
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