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

api-platform / core / 16705318661

03 Aug 2025 01:05PM UTC coverage: 0.0% (-21.9%) from 21.944%
16705318661

Pull #7317

github

web-flow
Merge 1ca8642ff into d06b1a0a0
Pull Request #7317: Fix/4372 skip null values in hal

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

11680 existing lines in 376 files now uncovered.

0 of 51817 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/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
    }
×
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(
×
UNCOV
56
            '/(^|_|\.)+(.)/',
×
UNCOV
57
            fn ($match) => ('.' === $match[1] ? '_' : '').strtoupper($match[2]),
×
UNCOV
58
            $propertyName
×
UNCOV
59
        );
×
60

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

UNCOV
65
        if (null === $this->attributes || \in_array($camelCasedName, $this->attributes, true)) {
×
UNCOV
66
            return $camelCasedName;
×
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