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

api-platform / core / 10014117656

19 Jul 2024 08:44PM UTC coverage: 7.856% (-56.3%) from 64.185%
10014117656

push

github

soyuka
Merge branch 'sf/remove-flag'

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

10505 existing lines in 362 files now uncovered.

12705 of 161727 relevant lines covered (7.86%)

26.85 hits per line

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

69.23
/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
    private $attributes;
35
    private $lowerCamelCase;
36

37
    /**
38
     * @param array|null $attributes     The list of attributes to rename or null for all attributes
39
     * @param bool       $lowerCamelCase Use lowerCamelCase style
40
     */
41
    public function __construct(?array $attributes = null, bool $lowerCamelCase = true)
42
    {
UNCOV
43
        $this->attributes = $attributes;
2,680✔
UNCOV
44
        $this->lowerCamelCase = $lowerCamelCase;
2,680✔
45
    }
46

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

53
        return $propertyName;
×
54
    }
55

56
    public function denormalize(string $propertyName): string
57
    {
UNCOV
58
        $camelCasedName = preg_replace_callback('/(^|_|\.)+(.)/', function ($match) {
99✔
UNCOV
59
            return ('.' === $match[1] ? '_' : '').strtoupper($match[2]);
99✔
UNCOV
60
        }, $propertyName);
99✔
61

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

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

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