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

api-platform / core / 18343625207

08 Oct 2025 11:48AM UTC coverage: 24.542% (-0.02%) from 24.561%
18343625207

push

github

web-flow
fix(state): object mapper on delete operation (#7447)

fixes #7434

1 of 49 new or added lines in 2 files covered. (2.04%)

7084 existing lines in 207 files now uncovered.

14004 of 57061 relevant lines covered (24.54%)

26.01 hits per line

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

47.52
/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\Doctrine\Odm\State\Options as OdmOptions;
17
use ApiPlatform\Doctrine\Orm\State\Options as OrmOptions;
18
use ApiPlatform\Elasticsearch\State\Options as ElasticsearchOptions;
19
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
20
use ApiPlatform\Metadata\GetCollection;
21
use ApiPlatform\Metadata\HeaderParameter;
22
use ApiPlatform\Metadata\Post;
23
use ApiPlatform\Metadata\QueryParameter;
24
use ApiPlatform\OpenApi\Model\ExternalDocumentation;
25
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
26
use ApiPlatform\OpenApi\Model\Parameter as OpenApiParameter;
27
use ApiPlatform\OpenApi\Model\RequestBody;
28
use ApiPlatform\OpenApi\Model\Response;
29
use ApiPlatform\State\OptionsInterface;
30
use Symfony\Component\Config\Util\XmlUtils;
31
use Symfony\Component\WebLink\Link;
32

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

42
    public const SCHEMA = __DIR__.'/schema/resources.xsd';
43

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

60
            // It's a property: ignore error
UNCOV
61
            return;
112✔
62
        }
63

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

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

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

153
    private function buildFormats(\SimpleXMLElement $resource, string $key): ?array
154
    {
UNCOV
155
        if (!isset($resource->{$key}->format)) {
112✔
UNCOV
156
            return null;
112✔
157
        }
158

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

166
            $data[] = (string) $format;
×
167
        }
168

169
        return $data;
×
170
    }
171

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

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

182
        $openapi = $resource->openapi;
×
183
        $data = [];
×
184
        $attributes = $openapi->attributes();
×
185

186
        /*
187
         * \SimpleXMLElement should not be read in an iteration because of a known bug in SimpleXML lib that resets the iterator
188
         * and leads to infinite loop
189
         * https://bugs.php.net/bug.php?id=55098
190
         * https://github.com/php/php-src/issues/12208
191
         * https://github.com/php/php-src/issues/12192
192
         *
193
         * attribute names are stored in an iteration and values are fetched in another one
194
         */
195
        $attributeNames = [];
×
196
        foreach ($attributes as $name => $attribute) {
×
197
            $attributeNames[] = $name;
×
198
        }
199

200
        foreach ($attributeNames as $attributeName) {
×
201
            $data[$attributeName] = $this->phpize($attributes, $attributeName, 'deprecated' === $attributeName ? 'bool' : 'string');
×
202
        }
203

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

206
        if (isset($openapi->responses->response)) {
×
207
            foreach ($openapi->responses->response as $response) {
×
208
                $data['responses'][(string) $response->attributes()->status] = new Response(
×
209
                    description: $this->phpize($response, 'description', 'string'),
×
210
                    content: isset($response->content->values) ? new \ArrayObject($this->buildValues($response->content->values)) : null,
×
211
                    headers: isset($response->headers->values) ? new \ArrayObject($this->buildValues($response->headers->values)) : null,
×
212
                    links: isset($response->links->values) ? new \ArrayObject($this->buildValues($response->links->values)) : null,
×
213
                );
×
214
            }
215
        }
216

217
        $data['externalDocs'] = isset($openapi->externalDocs) ? new ExternalDocumentation(
×
218
            description: $this->phpize($resource, 'description', 'string'),
×
219
            url: $this->phpize($resource, 'url', 'string'),
×
220
        ) : null;
×
221

222
        if (isset($openapi->parameters->parameter)) {
×
223
            foreach ($openapi->parameters->parameter as $parameter) {
×
224
                $data['parameters'][(string) $parameter->attributes()->name] = new OpenApiParameter(
×
225
                    name: $this->phpize($parameter, 'name', 'string'),
×
226
                    in: $this->phpize($parameter, 'in', 'string'),
×
227
                    description: $this->phpize($parameter, 'description', 'string'),
×
228
                    required: $this->phpize($parameter, 'required', 'bool'),
×
229
                    deprecated: $this->phpize($parameter, 'deprecated', 'bool', false),
×
230
                    allowEmptyValue: $this->phpize($parameter, 'allowEmptyValue', 'bool', null),
×
231
                    schema: isset($parameter->schema->values) ? $this->buildValues($parameter->schema->values) : [],
×
232
                    style: $this->phpize($parameter, 'style', 'string'),
×
233
                    explode: $this->phpize($parameter, 'explode', 'bool', false),
×
234
                    allowReserved: $this->phpize($parameter, 'allowReserved', 'bool', null),
×
235
                    example: $this->phpize($parameter, 'example', 'string'),
×
236
                    examples: isset($parameter->examples->values) ? new \ArrayObject($this->buildValues($parameter->examples->values)) : null,
×
237
                    content: isset($parameter->content->values) ? new \ArrayObject($this->buildValues($parameter->content->values)) : null,
×
238
                );
×
239
            }
240
        }
241
        $data['requestBody'] = isset($openapi->requestBody) ? new RequestBody(
×
242
            description: $this->phpize($openapi->requestBody, 'description', 'string'),
×
243
            content: isset($openapi->requestBody->content->values) ? new \ArrayObject($this->buildValues($openapi->requestBody->content->values)) : null,
×
244
            required: $this->phpize($openapi->requestBody, 'required', 'bool'),
×
245
        ) : null;
×
246

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

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

251
        if (isset($openapi->servers->server)) {
×
252
            foreach ($openapi->servers->server as $server) {
×
253
                $data['servers'][] = [
×
254
                    'description' => $this->phpize($server, 'description', 'string'),
×
255
                    'url' => $this->phpize($server, 'url', 'string'),
×
256
                    'variables' => isset($server->variables->values) ? $this->buildValues($server->variables->values) : null,
×
257
                ];
×
258
            }
259
        }
260

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

263
        foreach ($data as $key => $value) {
×
264
            if (null === $value) {
×
265
                unset($data[$key]);
×
266
            }
267
        }
268

269
        return new OpenApiOperation(...$data);
×
270
    }
271

272
    private function buildUriVariables(\SimpleXMLElement $resource): ?array
273
    {
UNCOV
274
        if (!isset($resource->uriVariables->uriVariable)) {
112✔
UNCOV
275
            return null;
112✔
276
        }
277

UNCOV
278
        $uriVariables = [];
112✔
UNCOV
279
        foreach ($resource->uriVariables->uriVariable as $data) {
112✔
UNCOV
280
            $parameterName = (string) $data['parameterName'];
112✔
UNCOV
281
            if (1 === (null === $data->attributes() ? 0 : \count($data->attributes()))) {
112✔
UNCOV
282
                $uriVariables[$parameterName] = $parameterName;
112✔
UNCOV
283
                continue;
112✔
284
            }
285

UNCOV
286
            if ($fromProperty = $this->phpize($data, 'fromProperty', 'string')) {
112✔
287
                $uriVariables[$parameterName]['from_property'] = $fromProperty;
×
288
            }
UNCOV
289
            if ($toProperty = $this->phpize($data, 'toProperty', 'string')) {
112✔
UNCOV
290
                $uriVariables[$parameterName]['to_property'] = $toProperty;
112✔
291
            }
UNCOV
292
            if ($fromClass = $this->resolve($this->phpize($data, 'fromClass', 'string'))) {
112✔
UNCOV
293
                $uriVariables[$parameterName]['from_class'] = $fromClass;
112✔
294
            }
UNCOV
295
            if ($toClass = $this->resolve($this->phpize($data, 'toClass', 'string'))) {
112✔
296
                $uriVariables[$parameterName]['to_class'] = $toClass;
×
297
            }
UNCOV
298
            if (isset($data->identifiers->values)) {
112✔
299
                $uriVariables[$parameterName]['identifiers'] = $this->buildValues($data->identifiers->values);
×
300
            }
UNCOV
301
            if (null !== ($compositeIdentifier = $this->phpize($data, 'compositeIdentifier', 'bool'))) {
112✔
302
                $uriVariables[$parameterName]['composite_identifier'] = $compositeIdentifier;
×
303
            }
304
        }
305

UNCOV
306
        return $uriVariables;
112✔
307
    }
308

309
    private function buildCacheHeaders(\SimpleXMLElement $resource): ?array
310
    {
UNCOV
311
        if (!isset($resource->cacheHeaders->cacheHeader)) {
112✔
UNCOV
312
            return null;
112✔
313
        }
314

315
        $data = [];
×
316
        foreach ($resource->cacheHeaders->cacheHeader as $cacheHeader) {
×
317
            if (isset($cacheHeader->values->value)) {
×
318
                $data[(string) $cacheHeader['name']] = $this->buildValues($cacheHeader->values);
×
319
                continue;
×
320
            }
321

322
            $data[(string) $cacheHeader['name']] = XmlUtils::phpize((string) $cacheHeader);
×
323
        }
324

325
        return $data;
×
326
    }
327

328
    private function buildRequirements(\SimpleXMLElement $resource): ?array
329
    {
UNCOV
330
        if (!isset($resource->requirements->requirement)) {
112✔
UNCOV
331
            return null;
112✔
332
        }
333

334
        $data = [];
×
335
        foreach ($resource->requirements->requirement as $requirement) {
×
336
            $data[(string) $requirement->attributes()->property] = (string) $requirement;
×
337
        }
338

339
        return $data;
×
340
    }
341

342
    private function buildMercure(\SimpleXMLElement $resource): array|bool|null
343
    {
UNCOV
344
        if (!isset($resource->mercure)) {
112✔
UNCOV
345
            return null;
112✔
346
        }
347

348
        if (null !== $resource->mercure->attributes()->private) {
×
349
            return ['private' => $this->phpize($resource->mercure->attributes(), 'private', 'bool')];
×
350
        }
351

352
        return true;
×
353
    }
354

355
    private function buildPaginationViaCursor(\SimpleXMLElement $resource): ?array
356
    {
UNCOV
357
        if (!isset($resource->paginationViaCursor->paginationField)) {
112✔
UNCOV
358
            return null;
112✔
359
        }
360

361
        $data = [];
×
362
        foreach ($resource->paginationViaCursor->paginationField as $paginationField) {
×
363
            $data[(string) $paginationField['field']] = (string) $paginationField['direction'];
×
364
        }
365

366
        return $data;
×
367
    }
368

369
    private function buildExceptionToStatus(\SimpleXMLElement $resource): ?array
370
    {
UNCOV
371
        if (!isset($resource->exceptionToStatus->exception)) {
112✔
UNCOV
372
            return null;
112✔
373
        }
374

375
        $data = [];
×
376
        foreach ($resource->exceptionToStatus->exception as $exception) {
×
377
            $data[(string) $exception['class']] = (int) $exception['statusCode'];
×
378
        }
379

380
        return $data;
×
381
    }
382

383
    private function buildExtraProperties(\SimpleXMLElement $resource, ?string $key = null): ?array
384
    {
UNCOV
385
        if (null !== $key) {
112✔
UNCOV
386
            if (!isset($resource->{$key})) {
112✔
UNCOV
387
                return null;
112✔
388
            }
389

390
            $resource = $resource->{$key};
×
391
        }
392

393
        return $this->buildValues($resource->values);
×
394
    }
395

396
    private function buildOperations(\SimpleXMLElement $resource, array $root): ?array
397
    {
UNCOV
398
        if (!isset($resource->operations->operation)) {
112✔
UNCOV
399
            return null;
112✔
400
        }
401

UNCOV
402
        $data = [];
112✔
UNCOV
403
        foreach ($resource->operations->operation as $operation) {
112✔
UNCOV
404
            $datum = $this->buildExtendedBase($operation);
112✔
UNCOV
405
            foreach ($datum as $key => $value) {
112✔
UNCOV
406
                if (null === $value) {
112✔
UNCOV
407
                    $datum[$key] = $root[$key];
112✔
408
                }
409
            }
410

UNCOV
411
            if (\in_array((string) $operation['class'], [GetCollection::class, Post::class], true)) {
112✔
UNCOV
412
                $datum['itemUriTemplate'] = $this->phpize($operation, 'itemUriTemplate', 'string');
112✔
UNCOV
413
            } elseif (isset($operation['itemUriTemplate'])) {
112✔
414
                throw new InvalidArgumentException(\sprintf('"itemUriTemplate" option is not allowed on a %s operation.', $operation['class']));
×
415
            }
416

UNCOV
417
            $data[] = array_merge($datum, [
112✔
UNCOV
418
                'collection' => $this->phpize($operation, 'collection', 'bool'),
112✔
UNCOV
419
                'class' => (string) $operation['class'],
112✔
UNCOV
420
                'method' => $this->phpize($operation, 'method', 'string'),
112✔
UNCOV
421
                'read' => $this->phpize($operation, 'read', 'bool'),
112✔
UNCOV
422
                'deserialize' => $this->phpize($operation, 'deserialize', 'bool'),
112✔
UNCOV
423
                'validate' => $this->phpize($operation, 'validate', 'bool'),
112✔
UNCOV
424
                'write' => $this->phpize($operation, 'write', 'bool'),
112✔
UNCOV
425
                'serialize' => $this->phpize($operation, 'serialize', 'bool'),
112✔
UNCOV
426
                'queryParameterValidate' => $this->phpize($operation, 'queryParameterValidate', 'bool'),
112✔
UNCOV
427
                'priority' => $this->phpize($operation, 'priority', 'integer'),
112✔
UNCOV
428
                'name' => $this->phpize($operation, 'name', 'string'),
112✔
UNCOV
429
                'routeName' => $this->phpize($operation, 'routeName', 'string'),
112✔
UNCOV
430
            ]);
112✔
431
        }
432

UNCOV
433
        return $data;
112✔
434
    }
435

436
    private function buildGraphQlOperations(\SimpleXMLElement $resource, array $root): ?array
437
    {
UNCOV
438
        if (!isset($resource->graphQlOperations->graphQlOperation)) {
112✔
UNCOV
439
            return null;
112✔
440
        }
441

442
        $data = [];
×
443
        foreach ($resource->graphQlOperations->graphQlOperation as $operation) {
×
444
            $datum = $this->buildBase($operation);
×
445
            foreach ($datum as $key => $value) {
×
446
                if (null === $value) {
×
447
                    $datum[$key] = $root[$key];
×
448
                }
449
            }
450

451
            $data[] = array_merge($datum, [
×
452
                'resolver' => $this->phpize($operation, 'resolver', 'string'),
×
453
                'args' => $this->buildArgs($operation),
×
454
                'extraArgs' => $this->buildExtraArgs($operation),
×
455
                'class' => (string) $operation['class'],
×
456
                'read' => $this->phpize($operation, 'read', 'bool'),
×
457
                'deserialize' => $this->phpize($operation, 'deserialize', 'bool'),
×
458
                'validate' => $this->phpize($operation, 'validate', 'bool'),
×
459
                'write' => $this->phpize($operation, 'write', 'bool'),
×
460
                'serialize' => $this->phpize($operation, 'serialize', 'bool'),
×
461
                'priority' => $this->phpize($operation, 'priority', 'integer'),
×
462
                'name' => $this->phpize($operation, 'name', 'string'),
×
463
            ]);
×
464
        }
465

466
        return $data;
×
467
    }
468

469
    private function buildStateOptions(\SimpleXMLElement $resource): ?OptionsInterface
470
    {
UNCOV
471
        $stateOptions = $resource->stateOptions ?? null;
112✔
UNCOV
472
        if (!$stateOptions) {
112✔
UNCOV
473
            return null;
112✔
474
        }
475

476
        if (isset($stateOptions->elasticsearchOptions) && class_exists(ElasticsearchOptions::class)) {
×
477
            return new ElasticsearchOptions(
×
478
                isset($stateOptions->elasticsearchOptions['index']) ? (string) $stateOptions->elasticsearchOptions['index'] : null,
×
479
            );
×
480
        }
481

482
        if (isset($stateOptions->doctrineOdmOptions) && class_exists(OdmOptions::class)) {
×
483
            return new OdmOptions(
×
484
                isset($stateOptions->doctrineOdmOptions['documentClass']) ? (string) $stateOptions->doctrineOdmOptions['documentClass'] : null,
×
485
            );
×
486
        }
487

488
        if (isset($stateOptions->doctrineOrmOptions) && class_exists(OrmOptions::class)) {
×
489
            return new OrmOptions(
×
490
                isset($stateOptions->doctrineOrmOptions['entityClass']) ? (string) $stateOptions->doctrineOrmOptions['entityClass'] : null,
×
491
            );
×
492
        }
493

494
        return null;
×
495
    }
496

497
    /**
498
     * @return Link[]
499
     */
500
    private function buildLinks(\SimpleXMLElement $resource): ?array
501
    {
UNCOV
502
        if (!$resource->links) {
112✔
UNCOV
503
            return null;
112✔
504
        }
505

506
        $links = [];
×
507
        foreach ($resource->links as $link) {
×
508
            $links[] = new Link(rel: (string) $link->link->attributes()->rel, href: (string) $link->link->attributes()->href);
×
509
        }
510

511
        return $links;
×
512
    }
513

514
    /**
515
     * @return array<string, string>
516
     */
517
    private function buildHeaders(\SimpleXMLElement $resource): ?array
518
    {
UNCOV
519
        if (!$resource->headers) {
112✔
UNCOV
520
            return null;
112✔
521
        }
522

523
        $headers = [];
×
524
        foreach ($resource->headers as $header) {
×
525
            $headers[(string) $header->header->attributes()->key] = (string) $header->header->attributes()->value;
×
526
        }
527

528
        return $headers;
×
529
    }
530

531
    /**
532
     * @return array<string, \ApiPlatform\Metadata\Parameter>
533
     */
534
    private function buildParameters(\SimpleXMLElement $resource): ?array
535
    {
UNCOV
536
        if (!$resource->parameters) {
112✔
UNCOV
537
            return null;
112✔
538
        }
539

540
        $parameters = [];
×
541
        foreach ($resource->parameters->parameter as $parameter) {
×
542
            $key = (string) $parameter->attributes()->key;
×
543
            $cl = ('header' === (string) $parameter->attributes()->in) ? HeaderParameter::class : QueryParameter::class;
×
544
            $parameters[$key] = new $cl(
×
545
                key: $key,
×
546
                required: $this->phpize($parameter, 'required', 'bool'),
×
547
                schema: isset($parameter->schema->values) ? $this->buildValues($parameter->schema->values) : null,
×
548
                openApi: isset($parameter->openapi) ? new OpenApiParameter(
×
549
                    name: $this->phpize($parameter->openapi, 'name', 'string'),
×
550
                    in: $this->phpize($parameter->openapi, 'in', 'string'),
×
551
                    description: $this->phpize($parameter->openapi, 'description', 'string'),
×
552
                    required: $this->phpize($parameter->openapi, 'required', 'bool'),
×
553
                    deprecated: $this->phpize($parameter->openapi, 'deprecated', 'bool'),
×
554
                    allowEmptyValue: $this->phpize($parameter->openapi, 'allowEmptyValue', 'bool'),
×
555
                    schema: isset($parameter->openapi->schema->values) ? $this->buildValues($parameter->openapi->schema->values) : null,
×
556
                    style: $this->phpize($parameter->openapi, 'style', 'string'),
×
557
                    explode: $this->phpize($parameter->openapi, 'explode', 'bool'),
×
558
                    allowReserved: $this->phpize($parameter->openapi, 'allowReserved', 'bool'),
×
559
                    example: $this->phpize($parameter->openapi, 'example', 'string'),
×
560
                    examples: isset($parameter->openapi->examples->values) ? new \ArrayObject($this->buildValues($parameter->openapi->examples->values)) : null,
×
561
                    content: isset($parameter->openapi->content->values) ? new \ArrayObject($this->buildValues($parameter->openapi->content->values)) : null,
×
562
                ) : null,
×
563
                provider: $this->phpize($parameter, 'provider', 'string'),
×
564
                filter: $this->phpize($parameter, 'filter', 'string'),
×
565
                property: $this->phpize($parameter, 'property', 'string'),
×
566
                description: $this->phpize($parameter, 'description', 'string'),
×
567
                priority: $this->phpize($parameter, 'priority', 'integer'),
×
568
                extraProperties: $this->buildExtraProperties($parameter, 'extraProperties') ?? [],
×
569
            );
×
570
        }
571

572
        return $parameters;
×
573
    }
574
}
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