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

api-platform / core / 15955912273

29 Jun 2025 01:51PM UTC coverage: 22.057% (-0.03%) from 22.082%
15955912273

Pull #7249

github

web-flow
Merge d9904d788 into a42034dc3
Pull Request #7249: chore: solve some phpstan issues

0 of 9 new or added lines in 8 files covered. (0.0%)

11540 existing lines in 372 files now uncovered.

11522 of 52237 relevant lines covered (22.06%)

11.08 hits per line

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

58.89
/src/Metadata/Extractor/YamlResourceExtractor.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;
25
use ApiPlatform\OpenApi\Model\RequestBody;
26
use ApiPlatform\State\OptionsInterface;
27
use Symfony\Component\WebLink\Link;
28
use Symfony\Component\Yaml\Exception\ParseException;
29
use Symfony\Component\Yaml\Yaml;
30

31
/**
32
 * Extracts an array of metadata from a list of YAML files.
33
 *
34
 * @author Antoine Bluchet <soyuka@gmail.com>
35
 * @author Baptiste Meyer <baptiste.meyer@gmail.com>
36
 * @author Kévin Dunglas <dunglas@gmail.com>
37
 * @author Vincent Chalamon <vincentchalamon@gmail.com>
38
 */
39
final class YamlResourceExtractor extends AbstractResourceExtractor
40
{
41
    use ResourceExtractorTrait;
42

43
    /**
44
     * {@inheritdoc}
45
     */
46
    protected function extractPath(string $path): void
47
    {
48
        try {
UNCOV
49
            $resourcesYaml = Yaml::parse((string) file_get_contents($path), Yaml::PARSE_CONSTANT);
50✔
50
        } catch (ParseException $e) {
×
51
            $e->setParsedFile($path);
×
52

53
            throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
×
54
        }
55

UNCOV
56
        if (null === $resourcesYaml = $resourcesYaml['resources'] ?? $resourcesYaml) {
50✔
57
            return;
×
58
        }
59

UNCOV
60
        if (!\is_array($resourcesYaml)) {
50✔
61
            throw new InvalidArgumentException(\sprintf('"resources" setting is expected to be null or an array, %s given in "%s".', \gettype($resourcesYaml), $path));
×
62
        }
63

UNCOV
64
        $this->buildResources($resourcesYaml, $path);
50✔
65
    }
66

67
    private function buildResources(array $resourcesYaml, string $path): void
68
    {
UNCOV
69
        foreach ($resourcesYaml as $resourceName => $resourceYaml) {
50✔
UNCOV
70
            $resourceName = $this->resolve($resourceName);
50✔
71

UNCOV
72
            if (null === $resourceYaml) {
50✔
UNCOV
73
                $resourceYaml = [[]];
50✔
74
            }
75

UNCOV
76
            if (!\array_key_exists(0, $resourceYaml)) {
50✔
UNCOV
77
                $resourceYaml = [$resourceYaml];
50✔
78
            }
79

UNCOV
80
            foreach ($resourceYaml as $key => $resourceYamlDatum) {
50✔
UNCOV
81
                if (null === $resourceYamlDatum) {
50✔
UNCOV
82
                    $resourceYamlDatum = [];
50✔
83
                }
84

85
                try {
UNCOV
86
                    $base = $this->buildExtendedBase($resourceYamlDatum);
50✔
UNCOV
87
                    $this->resources[$resourceName][$key] = array_merge($base, [
50✔
UNCOV
88
                        'operations' => $this->buildOperations($resourceYamlDatum, $base),
50✔
UNCOV
89
                        'graphQlOperations' => $this->buildGraphQlOperations($resourceYamlDatum, $base),
50✔
UNCOV
90
                    ]);
50✔
91
                } catch (InvalidArgumentException $exception) {
×
92
                    throw new InvalidArgumentException(\sprintf('%s in "%s" (%s).', $exception->getMessage(), $resourceName, $path));
×
93
                }
94
            }
95
        }
96
    }
97

98
    private function buildExtendedBase(array $resource): array
99
    {
UNCOV
100
        return array_merge($this->buildBase($resource), [
50✔
UNCOV
101
            'uriTemplate' => $this->phpize($resource, 'uriTemplate', 'string'),
50✔
UNCOV
102
            'routePrefix' => $this->phpize($resource, 'routePrefix', 'string'),
50✔
UNCOV
103
            'stateless' => $this->phpize($resource, 'stateless', 'bool'),
50✔
UNCOV
104
            'sunset' => $this->phpize($resource, 'sunset', 'string'),
50✔
UNCOV
105
            'acceptPatch' => $this->phpize($resource, 'acceptPatch', 'string'),
50✔
UNCOV
106
            'host' => $this->phpize($resource, 'host', 'string'),
50✔
UNCOV
107
            'condition' => $this->phpize($resource, 'condition', 'string'),
50✔
UNCOV
108
            'controller' => $this->phpize($resource, 'controller', 'string'),
50✔
UNCOV
109
            'queryParameterValidationEnabled' => $this->phpize($resource, 'queryParameterValidationEnabled', 'bool'),
50✔
UNCOV
110
            'types' => $this->buildArrayValue($resource, 'types'),
50✔
UNCOV
111
            'cacheHeaders' => $this->buildArrayValue($resource, 'cacheHeaders'),
50✔
UNCOV
112
            'hydraContext' => $this->buildArrayValue($resource, 'hydraContext'),
50✔
UNCOV
113
            'openapi' => $this->buildOpenapi($resource),
50✔
UNCOV
114
            'paginationViaCursor' => $this->buildArrayValue($resource, 'paginationViaCursor'),
50✔
UNCOV
115
            'exceptionToStatus' => $this->buildArrayValue($resource, 'exceptionToStatus'),
50✔
UNCOV
116
            'defaults' => $this->buildArrayValue($resource, 'defaults'),
50✔
UNCOV
117
            'requirements' => $this->buildArrayValue($resource, 'requirements'),
50✔
UNCOV
118
            'options' => $this->buildArrayValue($resource, 'options'),
50✔
UNCOV
119
            'status' => $this->phpize($resource, 'status', 'integer'),
50✔
UNCOV
120
            'schemes' => $this->buildArrayValue($resource, 'schemes'),
50✔
UNCOV
121
            'formats' => $this->buildArrayValue($resource, 'formats'),
50✔
UNCOV
122
            'uriVariables' => $this->buildUriVariables($resource),
50✔
UNCOV
123
            'inputFormats' => $this->buildArrayValue($resource, 'inputFormats'),
50✔
UNCOV
124
            'outputFormats' => $this->buildArrayValue($resource, 'outputFormats'),
50✔
UNCOV
125
            'stateOptions' => $this->buildStateOptions($resource),
50✔
UNCOV
126
            'links' => $this->buildLinks($resource),
50✔
UNCOV
127
            'headers' => $this->buildHeaders($resource),
50✔
UNCOV
128
            'parameters' => $this->buildParameters($resource),
50✔
UNCOV
129
        ]);
50✔
130
    }
131

132
    private function buildBase(array $resource): array
133
    {
UNCOV
134
        return [
50✔
UNCOV
135
            'shortName' => $this->phpize($resource, 'shortName', 'string'),
50✔
UNCOV
136
            'description' => $this->phpize($resource, 'description', 'string'),
50✔
UNCOV
137
            'urlGenerationStrategy' => $this->phpize($resource, 'urlGenerationStrategy', 'integer'),
50✔
UNCOV
138
            'deprecationReason' => $this->phpize($resource, 'deprecationReason', 'string'),
50✔
UNCOV
139
            'fetchPartial' => $this->phpize($resource, 'fetchPartial', 'bool'),
50✔
UNCOV
140
            'forceEager' => $this->phpize($resource, 'forceEager', 'bool'),
50✔
UNCOV
141
            'paginationClientEnabled' => $this->phpize($resource, 'paginationClientEnabled', 'bool'),
50✔
UNCOV
142
            'paginationClientItemsPerPage' => $this->phpize($resource, 'paginationClientItemsPerPage', 'bool'),
50✔
UNCOV
143
            'paginationClientPartial' => $this->phpize($resource, 'paginationClientPartial', 'bool'),
50✔
UNCOV
144
            'paginationEnabled' => $this->phpize($resource, 'paginationEnabled', 'bool'),
50✔
UNCOV
145
            'paginationFetchJoinCollection' => $this->phpize($resource, 'paginationFetchJoinCollection', 'bool'),
50✔
UNCOV
146
            'paginationUseOutputWalkers' => $this->phpize($resource, 'paginationUseOutputWalkers', 'bool'),
50✔
UNCOV
147
            'paginationItemsPerPage' => $this->phpize($resource, 'paginationItemsPerPage', 'integer'),
50✔
UNCOV
148
            'paginationMaximumItemsPerPage' => $this->phpize($resource, 'paginationMaximumItemsPerPage', 'integer'),
50✔
UNCOV
149
            'paginationPartial' => $this->phpize($resource, 'paginationPartial', 'bool'),
50✔
UNCOV
150
            'paginationType' => $this->phpize($resource, 'paginationType', 'string'),
50✔
UNCOV
151
            'processor' => $this->phpize($resource, 'processor', 'string'),
50✔
UNCOV
152
            'provider' => $this->phpize($resource, 'provider', 'string'),
50✔
UNCOV
153
            'security' => $this->phpize($resource, 'security', 'string'),
50✔
UNCOV
154
            'securityMessage' => $this->phpize($resource, 'securityMessage', 'string'),
50✔
UNCOV
155
            'securityPostDenormalize' => $this->phpize($resource, 'securityPostDenormalize', 'string'),
50✔
UNCOV
156
            'securityPostDenormalizeMessage' => $this->phpize($resource, 'securityPostDenormalizeMessage', 'string'),
50✔
UNCOV
157
            'securityPostValidation' => $this->phpize($resource, 'securityPostValidation', 'string'),
50✔
UNCOV
158
            'securityPostValidationMessage' => $this->phpize($resource, 'securityPostValidationMessage', 'string'),
50✔
UNCOV
159
            'input' => $this->phpize($resource, 'input', 'bool|string'),
50✔
UNCOV
160
            'output' => $this->phpize($resource, 'output', 'bool|string'),
50✔
UNCOV
161
            'normalizationContext' => $this->buildArrayValue($resource, 'normalizationContext'),
50✔
UNCOV
162
            'denormalizationContext' => $this->buildArrayValue($resource, 'denormalizationContext'),
50✔
UNCOV
163
            'collectDenormalizationErrors' => $this->phpize($resource, 'collectDenormalizationErrors', 'bool'),
50✔
UNCOV
164
            'validationContext' => $this->buildArrayValue($resource, 'validationContext'),
50✔
UNCOV
165
            'filters' => $this->buildArrayValue($resource, 'filters'),
50✔
UNCOV
166
            'order' => $this->buildArrayValue($resource, 'order'),
50✔
UNCOV
167
            'extraProperties' => $this->buildArrayValue($resource, 'extraProperties'),
50✔
UNCOV
168
            'mercure' => $this->buildMercure($resource),
50✔
UNCOV
169
            'messenger' => $this->buildMessenger($resource),
50✔
UNCOV
170
            'read' => $this->phpize($resource, 'read', 'bool'),
50✔
UNCOV
171
            'write' => $this->phpize($resource, 'write', 'bool'),
50✔
UNCOV
172
        ];
50✔
173
    }
174

175
    private function buildUriVariables(array $resource): ?array
176
    {
UNCOV
177
        if (!\array_key_exists('uriVariables', $resource)) {
50✔
UNCOV
178
            return null;
50✔
179
        }
180

UNCOV
181
        $uriVariables = [];
50✔
UNCOV
182
        foreach ($resource['uriVariables'] as $parameterName => $data) {
50✔
UNCOV
183
            if (\is_string($data)) {
50✔
184
                $uriVariables[$data] = $data;
×
185
                continue;
×
186
            }
187

UNCOV
188
            if (2 === (is_countable($data) ? \count($data) : 0) && isset($data[0]) && isset($data[1])) {
50✔
UNCOV
189
                $data['fromClass'] = $data[0];
50✔
UNCOV
190
                $data['fromProperty'] = $data[1];
50✔
UNCOV
191
                unset($data[0], $data[1]);
50✔
192
            }
UNCOV
193
            if (isset($data['fromClass'])) {
50✔
UNCOV
194
                $uriVariables[$parameterName]['from_class'] = $this->resolve($data['fromClass']);
50✔
195
            }
UNCOV
196
            if (isset($data['fromProperty'])) {
50✔
UNCOV
197
                $uriVariables[$parameterName]['from_property'] = $data['fromProperty'];
50✔
198
            }
UNCOV
199
            if (isset($data['toClass'])) {
50✔
200
                $uriVariables[$parameterName]['to_class'] = $this->resolve($data['toClass']);
×
201
            }
UNCOV
202
            if (isset($data['toProperty'])) {
50✔
UNCOV
203
                $uriVariables[$parameterName]['to_property'] = $data['toProperty'];
50✔
204
            }
UNCOV
205
            if (isset($data['identifiers'])) {
50✔
206
                $uriVariables[$parameterName]['identifiers'] = $data['identifiers'];
×
207
            }
UNCOV
208
            if (isset($data['compositeIdentifier'])) {
50✔
209
                $uriVariables[$parameterName]['composite_identifier'] = $data['compositeIdentifier'];
×
210
            }
UNCOV
211
            if (isset($data['security'])) {
50✔
212
                $uriVariables[$parameterName]['security'] = $data['security'];
×
213
            }
214
        }
215

UNCOV
216
        return $uriVariables;
50✔
217
    }
218

219
    private function buildOpenapi(array $resource): bool|OpenApiOperation|null
220
    {
UNCOV
221
        if (!\array_key_exists('openapi', $resource)) {
50✔
UNCOV
222
            return null;
50✔
223
        }
224

UNCOV
225
        if (!\is_array($resource['openapi'])) {
50✔
226
            return $this->phpize($resource, 'openapi', 'bool');
×
227
        }
228

UNCOV
229
        $allowedProperties = array_map(fn (\ReflectionProperty $reflProperty): string => $reflProperty->getName(), (new \ReflectionClass(OpenApiOperation::class))->getProperties());
50✔
UNCOV
230
        foreach ($resource['openapi'] as $key => $value) {
50✔
UNCOV
231
            $resource['openapi'][$key] = match ($key) {
50✔
232
                'externalDocs' => new ExternalDocumentation(description: $value['description'] ?? '', url: $value['url'] ?? ''),
×
233
                'requestBody' => new RequestBody(description: $value['description'] ?? '', content: isset($value['content']) ? new \ArrayObject($value['content'] ?? []) : null, required: $value['required'] ?? false),
×
234
                'callbacks' => new \ArrayObject($value ?? []),
×
UNCOV
235
                default => $value,
50✔
UNCOV
236
            };
50✔
237

UNCOV
238
            if (\in_array($key, $allowedProperties, true)) {
50✔
239
                continue;
×
240
            }
241

UNCOV
242
            $resource['openapi']['extensionProperties'][$key] = $value;
50✔
UNCOV
243
            unset($resource['openapi'][$key]);
50✔
244
        }
245

UNCOV
246
        if (\array_key_exists('parameters', $resource['openapi']) && \is_array($openapiParameters = $resource['openapi']['parameters'] ?? [])) {
50✔
247
            $parameters = [];
×
248
            foreach ($openapiParameters as $parameter) {
×
249
                $parameters[] = new Parameter(
×
250
                    name: $parameter['name'],
×
251
                    in: $parameter['in'],
×
252
                    description: $parameter['description'] ?? '',
×
253
                    required: $parameter['required'] ?? false,
×
254
                    deprecated: $parameter['deprecated'] ?? false,
×
255
                    allowEmptyValue: $parameter['allowEmptyValue'] ?? false,
×
256
                    schema: $parameter['schema'] ?? [],
×
257
                    style: $parameter['style'] ?? null,
×
258
                    explode: $parameter['explode'] ?? false,
×
259
                    allowReserved: $parameter['allowReserved '] ?? false,
×
260
                    example: $parameter['example'] ?? null,
×
261
                    examples: isset($parameter['examples']) ? new \ArrayObject($parameter['examples']) : null,
×
262
                    content: isset($parameter['content']) ? new \ArrayObject($parameter['content']) : null
×
263
                );
×
264
            }
265
            $resource['openapi']['parameters'] = $parameters;
×
266
        }
267

UNCOV
268
        return new OpenApiOperation(...$resource['openapi']);
50✔
269
    }
270

271
    /**
272
     * @return bool|string|string[]|null
273
     */
274
    private function buildMercure(array $resource): array|bool|string|null
275
    {
UNCOV
276
        if (!\array_key_exists('mercure', $resource)) {
50✔
UNCOV
277
            return null;
50✔
278
        }
279

280
        if (\is_string($resource['mercure'])) {
×
281
            return $this->phpize($resource, 'mercure', 'bool|string');
×
282
        }
283

284
        return $resource['mercure'];
×
285
    }
286

287
    private function buildMessenger(array $resource): bool|array|string|null
288
    {
UNCOV
289
        if (!\array_key_exists('messenger', $resource)) {
50✔
UNCOV
290
            return null;
50✔
291
        }
292

293
        return $this->phpize($resource, 'messenger', 'bool|string');
×
294
    }
295

296
    private function buildOperations(array $resource, array $root): ?array
297
    {
UNCOV
298
        if (!\array_key_exists('operations', $resource)) {
50✔
UNCOV
299
            return null;
50✔
300
        }
301

UNCOV
302
        $data = [];
50✔
UNCOV
303
        foreach ($resource['operations'] as $class => $operation) {
50✔
UNCOV
304
            if (null === $operation) {
50✔
UNCOV
305
                $operation = [];
50✔
306
            }
307

UNCOV
308
            if (\array_key_exists('class', $operation)) {
50✔
309
                if (!\array_key_exists('name', $operation) && \is_string($class)) {
×
310
                    $operation['name'] = $class;
×
311
                }
312
                $class = $operation['class'];
×
313
            }
314

UNCOV
315
            if (empty($class)) {
50✔
316
                throw new InvalidArgumentException('Missing "class" attribute');
×
317
            }
318

UNCOV
319
            if (!class_exists($class)) {
50✔
320
                throw new InvalidArgumentException(\sprintf('Operation class "%s" does not exist', $class));
×
321
            }
322

UNCOV
323
            $datum = $this->buildExtendedBase($operation);
50✔
UNCOV
324
            foreach ($datum as $key => $value) {
50✔
UNCOV
325
                if (null === $value) {
50✔
UNCOV
326
                    $datum[$key] = $root[$key];
50✔
327
                }
328
            }
329

UNCOV
330
            if (\in_array((string) $class, [GetCollection::class, Post::class], true)) {
50✔
UNCOV
331
                $datum['itemUriTemplate'] = $this->phpize($operation, 'itemUriTemplate', 'string');
50✔
UNCOV
332
            } elseif (isset($operation['itemUriTemplate'])) {
50✔
333
                throw new InvalidArgumentException(\sprintf('"itemUriTemplate" option is not allowed on a %s operation.', $class));
×
334
            }
335

UNCOV
336
            $data[] = array_merge($datum, [
50✔
UNCOV
337
                'read' => $this->phpize($operation, 'read', 'bool'),
50✔
UNCOV
338
                'deserialize' => $this->phpize($operation, 'deserialize', 'bool'),
50✔
UNCOV
339
                'validate' => $this->phpize($operation, 'validate', 'bool'),
50✔
UNCOV
340
                'write' => $this->phpize($operation, 'write', 'bool'),
50✔
UNCOV
341
                'serialize' => $this->phpize($operation, 'serialize', 'bool'),
50✔
UNCOV
342
                'queryParameterValidate' => $this->phpize($operation, 'queryParameterValidate', 'bool'),
50✔
UNCOV
343
                'strictQueryParameterValidation' => $this->phpize($operation, 'strictQueryParameterValidation', 'bool'),
50✔
UNCOV
344
                'hideHydraOperation' => $this->phpize($resource, 'hideHydraOperation', 'bool'),
50✔
UNCOV
345
                'priority' => $this->phpize($operation, 'priority', 'integer'),
50✔
UNCOV
346
                'name' => $this->phpize($operation, 'name', 'string'),
50✔
UNCOV
347
                'class' => (string) $class,
50✔
UNCOV
348
            ]);
50✔
349
        }
350

UNCOV
351
        return $data;
50✔
352
    }
353

354
    private function buildGraphQlOperations(array $resource, array $root): ?array
355
    {
UNCOV
356
        if (!\array_key_exists('graphQlOperations', $resource) || !\is_array($resource['graphQlOperations'])) {
50✔
UNCOV
357
            return null;
50✔
358
        }
359

UNCOV
360
        $data = [];
50✔
UNCOV
361
        foreach ($resource['graphQlOperations'] as $class => $operation) {
50✔
362
            if (null === $operation) {
×
363
                $operation = [];
×
364
            }
365

366
            if (\array_key_exists('class', $operation)) {
×
367
                if (!\array_key_exists('name', $operation) && \is_string($class)) {
×
368
                    $operation['name'] = $class;
×
369
                }
370
                $class = $operation['class'];
×
371
            }
372

373
            if (empty($class)) {
×
374
                throw new InvalidArgumentException('Missing "class" attribute');
×
375
            }
376

377
            if (!class_exists($class)) {
×
378
                throw new InvalidArgumentException(\sprintf('Operation class "%s" does not exist', $class));
×
379
            }
380

381
            $datum = $this->buildBase($operation);
×
382
            foreach ($datum as $key => $value) {
×
383
                if (null === $value) {
×
384
                    $datum[$key] = $root[$key];
×
385
                }
386
            }
387

388
            $data[] = array_merge($datum, [
×
389
                'resolver' => $this->phpize($operation, 'resolver', 'string'),
×
390
                'args' => $operation['args'] ?? null,
×
391
                'extraArgs' => $operation['extraArgs'] ?? null,
×
392
                'class' => (string) $class,
×
393
                'read' => $this->phpize($operation, 'read', 'bool'),
×
394
                'deserialize' => $this->phpize($operation, 'deserialize', 'bool'),
×
395
                'validate' => $this->phpize($operation, 'validate', 'bool'),
×
396
                'write' => $this->phpize($operation, 'write', 'bool'),
×
397
                'serialize' => $this->phpize($operation, 'serialize', 'bool'),
×
398
                'priority' => $this->phpize($operation, 'priority', 'integer'),
×
399
                'name' => $this->phpize($operation, 'name', 'string'),
×
400
            ]);
×
401
        }
402

UNCOV
403
        return $data ?: null;
50✔
404
    }
405

406
    private function buildStateOptions(array $resource): ?OptionsInterface
407
    {
UNCOV
408
        $stateOptions = $resource['stateOptions'] ?? [];
50✔
UNCOV
409
        if (!\is_array($stateOptions)) {
50✔
410
            return null;
×
411
        }
412

UNCOV
413
        if (!$stateOptions) {
50✔
UNCOV
414
            return null;
50✔
415
        }
416

417
        $configuration = reset($stateOptions);
×
418
        switch (key($stateOptions)) {
×
419
            case 'elasticsearchOptions':
×
420
                if (class_exists(Options::class)) {
×
421
                    return new Options($configuration['index'] ?? null);
×
422
                }
423
        }
424

425
        return null;
×
426
    }
427

428
    /**
429
     * @return Link[]
430
     */
431
    private function buildLinks(array $resource): ?array
432
    {
UNCOV
433
        if (!isset($resource['links']) || !\is_array($resource['links'])) {
50✔
UNCOV
434
            return null;
50✔
435
        }
436

437
        $links = [];
×
438
        foreach ($resource['links'] as $link) {
×
439
            $links[] = new Link(rel: $link['rel'], href: $link['href']);
×
440
        }
441

442
        return $links;
×
443
    }
444

445
    /**
446
     * @return array<string, string>
447
     */
448
    private function buildHeaders(array $resource): ?array
449
    {
UNCOV
450
        if (!isset($resource['headers']) || !\is_array($resource['headers'])) {
50✔
UNCOV
451
            return null;
50✔
452
        }
453

454
        $headers = [];
×
455
        foreach ($resource['headers'] as $key => $value) {
×
456
            $headers[$key] = $value;
×
457
        }
458

459
        return $headers;
×
460
    }
461

462
    /**
463
     * @return array<string, \ApiPlatform\Metadata\Parameter>
464
     */
465
    private function buildParameters(array $resource): ?array
466
    {
UNCOV
467
        if (!isset($resource['parameters']) || !\is_array($resource['parameters'])) {
50✔
UNCOV
468
            return null;
50✔
469
        }
470

471
        $parameters = [];
×
472
        foreach ($resource['parameters'] as $key => $parameter) {
×
473
            $cl = ($parameter['in'] ?? 'query') === 'header' ? HeaderParameter::class : QueryParameter::class;
×
474
            $parameters[$key] = new $cl(
×
475
                key: $key,
×
476
                required: $this->phpize($parameter, 'required', 'bool'),
×
477
                schema: $parameter['schema'] ?? null,
×
478
                openApi: ($parameter['openapi'] ?? null) ? new Parameter(
×
479
                    name: $parameter['openapi']['name'],
×
480
                    in: $parameter['in'] ?? 'query',
×
481
                    description: $parameter['openapi']['description'] ?? '',
×
482
                    required: $parameter['openapi']['required'] ?? $parameter['required'] ?? false,
×
483
                    deprecated: $parameter['openapi']['deprecated'] ?? false,
×
484
                    allowEmptyValue: $parameter['openapi']['allowEmptyValue'] ?? false,
×
485
                    schema: $parameter['openapi']['schema'] ?? $parameter['schema'] ?? [],
×
486
                    style: $parameter['openapi']['style'] ?? null,
×
487
                    explode: $parameter['openapi']['explode'] ?? false,
×
488
                    allowReserved: $parameter['openapi']['allowReserved '] ?? false,
×
489
                    example: $parameter['openapi']['example'] ?? null,
×
490
                    examples: isset($parameter['openapi']['examples']) ? new \ArrayObject($parameter['openapi']['examples']) : null,
×
491
                    content: isset($parameter['openapi']['content']) ? new \ArrayObject($parameter['openapi']['content']) : null
×
492
                ) : null,
×
493
                provider: $this->phpize($parameter, 'provider', 'string'),
×
494
                filter: $this->phpize($parameter, 'filter', 'string'),
×
495
                property: $this->phpize($parameter, 'property', 'string'),
×
496
                description: $this->phpize($parameter, 'description', 'string'),
×
497
                priority: $this->phpize($parameter, 'priority', 'integer'),
×
498
                extraProperties: $this->buildArrayValue($parameter, 'extraProperties') ?? [],
×
499
            );
×
500
        }
501

502
        return $parameters;
×
503
    }
504
}
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