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

api-platform / core / 15023181448

14 May 2025 02:19PM UTC coverage: 0.0% (-8.4%) from 8.418%
15023181448

Pull #7139

github

web-flow
Merge 9f45709da into 1862d03b7
Pull Request #7139: refactor(symfony): remove obsolete option `validator.query-parameter-validation`

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

11266 existing lines in 366 files now uncovered.

0 of 50828 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