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

api-platform / core / 15133993414

20 May 2025 09:30AM UTC coverage: 26.313% (-1.2%) from 27.493%
15133993414

Pull #7161

github

web-flow
Merge e2c03d45f into 5459ba375
Pull Request #7161: fix(metadata): infer parameter string type from schema

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

11019 existing lines in 363 files now uncovered.

12898 of 49018 relevant lines covered (26.31%)

34.33 hits per line

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

71.43
/src/Metadata/Util/CamelCaseToSnakeCaseNameConverter.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
/*
15
 * This file is part of the Symfony package.
16
 *
17
 * (c) Fabien Potencier <fabien@symfony.com>
18
 *
19
 * For the full copyright and license information, please view the LICENSE
20
 * file that was distributed with this source code.
21
 */
22

23
namespace ApiPlatform\Metadata\Util;
24

25
/**
26
 * CamelCase to Underscore name converter.
27
 *
28
 * @internal
29
 *
30
 * @author Kévin Dunglas <dunglas@gmail.com>
31
 */
32
class CamelCaseToSnakeCaseNameConverter
33
{
34
    /**
35
     * @param array|null $attributes     The list of attributes to rename or null for all attributes
36
     * @param bool       $lowerCamelCase Use lowerCamelCase style
37
     */
38
    public function __construct(
39
        private readonly ?array $attributes = null,
40
        private readonly bool $lowerCamelCase = true,
41
    ) {
UNCOV
42
    }
982✔
43

44
    public function normalize(string $propertyName): string
45
    {
46
        if (null === $this->attributes || \in_array($propertyName, $this->attributes, true)) {
×
47
            return strtolower(preg_replace('/[A-Z]/', '_\\0', lcfirst($propertyName)));
×
48
        }
49

50
        return $propertyName;
×
51
    }
52

53
    public function denormalize(string $propertyName): string
54
    {
UNCOV
55
        $camelCasedName = preg_replace_callback(
63✔
UNCOV
56
            '/(^|_|\.)+(.)/',
63✔
UNCOV
57
            fn ($match) => ('.' === $match[1] ? '_' : '').strtoupper($match[2]),
63✔
UNCOV
58
            $propertyName
63✔
UNCOV
59
        );
63✔
60

UNCOV
61
        if ($this->lowerCamelCase) {
63✔
UNCOV
62
            $camelCasedName = lcfirst($camelCasedName);
63✔
63
        }
64

UNCOV
65
        if (null === $this->attributes || \in_array($camelCasedName, $this->attributes, true)) {
63✔
UNCOV
66
            return $camelCasedName;
63✔
67
        }
68

69
        return $propertyName;
×
70
    }
71
}
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