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

api-platform / core / 14954769666

11 May 2025 10:14AM UTC coverage: 0.0% (-8.5%) from 8.457%
14954769666

Pull #7135

github

web-flow
Merge bf21e0bc7 into 4dd0cdfc4
Pull Request #7135: fix(symfony,laravel): InvalidUriVariableException status code (e400)

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

11040 existing lines in 370 files now uncovered.

0 of 48303 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/JsonSchema/DefinitionNameFactory.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\JsonSchema;
15

16
use ApiPlatform\Metadata\Operation;
17
use ApiPlatform\Metadata\Util\ResourceClassInfoTrait;
18
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
19

20
final class DefinitionNameFactory implements DefinitionNameFactoryInterface
21
{
22
    use ResourceClassInfoTrait;
23

24
    private const GLUE = '.';
25
    private array $prefixCache = [];
26

27
    public function __construct(private ?array $distinctFormats)
28
    {
UNCOV
29
    }
×
30

31
    public function create(string $className, string $format = 'json', ?string $inputOrOutputClass = null, ?Operation $operation = null, array $serializerContext = []): string
32
    {
UNCOV
33
        if ($operation) {
×
UNCOV
34
            $prefix = $operation->getShortName();
×
35
        }
36

UNCOV
37
        if (!isset($prefix)) {
×
UNCOV
38
            $prefix = $this->createPrefixFromClass($className);
×
39
        }
40

UNCOV
41
        if (null !== $inputOrOutputClass && $className !== $inputOrOutputClass) {
×
UNCOV
42
            $parts = explode('\\', $inputOrOutputClass);
×
UNCOV
43
            $shortName = end($parts);
×
UNCOV
44
            $prefix .= self::GLUE.$shortName;
×
45
        }
46

UNCOV
47
        if ('json' !== $format && ($this->distinctFormats[$format] ?? false)) {
×
48
            // JSON is the default, and so isn't included in the definition name
UNCOV
49
            $prefix .= self::GLUE.$format;
×
50
        }
51

UNCOV
52
        $definitionName = $serializerContext[SchemaFactory::OPENAPI_DEFINITION_NAME] ?? null;
×
UNCOV
53
        if (null !== $definitionName) {
×
UNCOV
54
            $name = \sprintf('%s%s', $prefix, $definitionName ? '-'.$definitionName : $definitionName);
×
55
        } else {
UNCOV
56
            $groups = (array) ($serializerContext[AbstractNormalizer::GROUPS] ?? []);
×
UNCOV
57
            $name = $groups ? \sprintf('%s-%s', $prefix, implode('_', $groups)) : $prefix;
×
58
        }
59

UNCOV
60
        return $this->encodeDefinitionName($name);
×
61
    }
62

63
    private function encodeDefinitionName(string $name): string
64
    {
UNCOV
65
        return preg_replace('/[^a-zA-Z0-9.\-_]/', '.', $name);
×
66
    }
67

68
    private function createPrefixFromClass(string $fullyQualifiedClassName, int $namespaceParts = 1): string
69
    {
UNCOV
70
        $parts = explode('\\', $fullyQualifiedClassName);
×
UNCOV
71
        $name = implode(self::GLUE, \array_slice($parts, -$namespaceParts));
×
72

UNCOV
73
        if (!isset($this->prefixCache[$name])) {
×
UNCOV
74
            $this->prefixCache[$name] = $fullyQualifiedClassName;
×
75

UNCOV
76
            return $name;
×
77
        }
78

UNCOV
79
        if ($this->prefixCache[$name] !== $fullyQualifiedClassName) {
×
UNCOV
80
            $name = $this->createPrefixFromClass($fullyQualifiedClassName, ++$namespaceParts);
×
81
        }
82

UNCOV
83
        return $name;
×
84
    }
85
}
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