• 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

93.33
/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 = null)
28
    {
UNCOV
29
        if ($distinctFormats) {
743✔
30
            trigger_deprecation('api-platform/json-schema', '4.2', 'The distinctFormats argument is deprecated and will be removed in 5.0.');
×
31
        }
32
    }
33

34
    public function create(string $className, string $format = 'json', ?string $inputOrOutputClass = null, ?Operation $operation = null, array $serializerContext = []): string
35
    {
UNCOV
36
        if ($operation) {
154✔
UNCOV
37
            $prefix = $operation->getShortName();
138✔
38
        }
39

UNCOV
40
        if (!isset($prefix)) {
154✔
UNCOV
41
            $prefix = $this->createPrefixFromClass($className);
92✔
42
        }
43

UNCOV
44
        if (null !== $inputOrOutputClass && $className !== $inputOrOutputClass) {
154✔
UNCOV
45
            $parts = explode('\\', $inputOrOutputClass);
36✔
UNCOV
46
            $shortName = end($parts);
36✔
UNCOV
47
            $prefix .= self::GLUE.$shortName;
36✔
48
        }
49

50
        // TODO: remove in 5.0
UNCOV
51
        $v = $this->distinctFormats ? ($this->distinctFormats[$format] ?? false) : true;
154✔
52

UNCOV
53
        if ('json' !== $format && $v) {
154✔
54
            // JSON is the default, and so isn't included in the definition name
UNCOV
55
            $prefix .= self::GLUE.$format;
140✔
56
        }
57

UNCOV
58
        $definitionName = $serializerContext[SchemaFactory::OPENAPI_DEFINITION_NAME] ?? null;
154✔
UNCOV
59
        if (null !== $definitionName) {
154✔
UNCOV
60
            $name = \sprintf('%s%s', $prefix, $definitionName ? '-'.$definitionName : $definitionName);
46✔
61
        } else {
UNCOV
62
            $groups = (array) ($serializerContext[AbstractNormalizer::GROUPS] ?? []);
154✔
UNCOV
63
            $name = $groups ? \sprintf('%s-%s', $prefix, implode('_', $groups)) : $prefix;
154✔
64
        }
65

UNCOV
66
        if (false === ($serializerContext['gen_id'] ?? true)) {
154✔
UNCOV
67
            $name .= '_noid';
4✔
68
        }
69

UNCOV
70
        return $this->encodeDefinitionName($name);
154✔
71
    }
72

73
    private function encodeDefinitionName(string $name): string
74
    {
UNCOV
75
        return preg_replace('/[^a-zA-Z0-9.\-_]/', '.', $name);
154✔
76
    }
77

78
    private function createPrefixFromClass(string $fullyQualifiedClassName, int $namespaceParts = 1): string
79
    {
UNCOV
80
        $parts = explode('\\', $fullyQualifiedClassName);
92✔
UNCOV
81
        $name = implode(self::GLUE, \array_slice($parts, -$namespaceParts));
92✔
82

UNCOV
83
        if (!isset($this->prefixCache[$name])) {
92✔
UNCOV
84
            $this->prefixCache[$name] = $fullyQualifiedClassName;
92✔
85

UNCOV
86
            return $name;
92✔
87
        }
88

UNCOV
89
        if ($this->prefixCache[$name] !== $fullyQualifiedClassName) {
44✔
90
            $name = $this->createPrefixFromClass($fullyQualifiedClassName, ++$namespaceParts);
×
91
        }
92

UNCOV
93
        return $name;
44✔
94
    }
95
}
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

© 2026 Coveralls, Inc