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

api-platform / core / 10027319583

21 Jul 2024 09:36AM UTC coverage: 7.847%. Remained the same
10027319583

push

github

web-flow
ci: fix naming of Windows Behat matrix line (#6489)

12688 of 161690 relevant lines covered (7.85%)

26.88 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
    {
43
        $this->attributes = $attributes;
2,683✔
44
        $this->lowerCamelCase = $lowerCamelCase;
2,683✔
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
    {
58
        $camelCasedName = preg_replace_callback('/(^|_|\.)+(.)/', function ($match) {
100✔
59
            return ('.' === $match[1] ? '_' : '').strtoupper($match[2]);
100✔
60
        }, $propertyName);
100✔
61

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

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