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

api-platform / core / 13175753759

06 Feb 2025 09:30AM UTC coverage: 0.0% (-7.7%) from 7.663%
13175753759

Pull #6947

github

web-flow
Merge 432a515ad into de2d298e3
Pull Request #6947: fix(metadata): remove temporary fix for ArrayCollection

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

11655 existing lines in 385 files now uncovered.

0 of 47351 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/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));
×
UNCOV
49
        } catch (\InvalidArgumentException $e) {
×
50
            // Ensure it's not a resource
51
            try {
UNCOV
52
                simplexml_import_dom(XmlUtils::loadFile($path, XmlPropertyExtractor::SCHEMA));
×
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;
×
59
        }
60

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

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

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

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

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

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

164
        return $data;
×
165
    }
166

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

UNCOV
286
        return $uriVariables;
×
287
    }
288

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

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

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

305
        return $data;
×
306
    }
307

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

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

319
        return $data;
×
320
    }
321

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

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

332
        return true;
×
333
    }
334

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

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

346
        return $data;
×
347
    }
348

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

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

360
        return $data;
×
361
    }
362

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

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

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

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

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

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

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

UNCOV
413
        return $data;
×
414
    }
415

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

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

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

446
        return $data;
×
447
    }
448

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

465
        return null;
×
466
    }
467

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

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

482
        return $links;
×
483
    }
484

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

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

499
        return $headers;
×
500
    }
501

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

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

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