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

api-platform / core / 15133993414

20 May 2025 09:30AM UTC coverage: 26.313% (-1.2%) from 27.493%
15133993414

Pull #7161

github

web-flow
Merge e2c03d45f into 5459ba375
Pull Request #7161: fix(metadata): infer parameter string type from schema

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

11019 existing lines in 363 files now uncovered.

12898 of 49018 relevant lines covered (26.31%)

34.33 hits per line

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

28.57
/src/Metadata/Util/CompositeIdentifierParser.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
namespace ApiPlatform\Metadata\Util;
15

16
/**
17
 * Normalizes a composite identifier.
18
 *
19
 * @internal
20
 *
21
 * @author Antoine Bluchet <soyuka@gmail.com>
22
 */
23
final class CompositeIdentifierParser
24
{
25
    public const COMPOSITE_IDENTIFIER_REGEXP = '/(\w+)=(?<=\w=)(.*?)(?=;\w+=)|(\w+)=([^;]*);?$/';
26

27
    private function __construct()
28
    {
29
    }
×
30

31
    /*
32
     * Normalize takes a string and gives back an array of identifiers.
33
     *
34
     * For example: foo=0;bar=2 returns ['foo' => 0, 'bar' => 2].
35
     */
36
    public static function parse(string $identifier): array
37
    {
38
        $matches = [];
×
39
        $identifiers = [];
×
40
        $num = preg_match_all(self::COMPOSITE_IDENTIFIER_REGEXP, $identifier, $matches, \PREG_SET_ORDER);
×
41

42
        foreach ($matches as $i => $match) {
×
43
            if ($i === $num - 1) {
×
44
                $identifiers[$match[3]] = $match[4];
×
45
                continue;
×
46
            }
47
            $identifiers[$match[1]] = $match[2];
×
48
        }
49

50
        return $identifiers;
×
51
    }
52

53
    /**
54
     * Renders composite identifiers to string using: key=value;key2=value2.
55
     */
56
    public static function stringify(array $identifiers): string
57
    {
UNCOV
58
        $composite = [];
4✔
UNCOV
59
        foreach ($identifiers as $name => $value) {
4✔
UNCOV
60
            $composite[] = \sprintf('%s=%s', $name, $value);
4✔
61
        }
62

UNCOV
63
        return implode(';', $composite);
4✔
64
    }
65
}
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