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

api-platform / core / 10943429050

19 Sep 2024 02:48PM UTC coverage: 7.647% (-0.03%) from 7.675%
10943429050

push

github

web-flow
feat: api-platform/json-hal component (#6621)

* feat: add hal support for laravel

* feat: quick review

* fix: typo & cs-fixer

* fix: typo in composer.json

* fix: cs-fixer & phpstan

* fix: forgot about hal item normalizer, therefore there's no more createbook nor updatebook test as Hal is a readonly format

0 of 94 new or added lines in 2 files covered. (0.0%)

9082 existing lines in 291 files now uncovered.

12629 of 165144 relevant lines covered (7.65%)

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

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

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