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

api-platform / core / 15063570239

16 May 2025 07:56AM UTC coverage: 27.494% (-0.001%) from 27.495%
15063570239

push

github

web-flow
fix: error formats (#7148)

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

11139 existing lines in 371 files now uncovered.

13476 of 49015 relevant lines covered (27.49%)

74.77 hits per line

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

92.86
/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 = [];
9✔
39
        $identifiers = [];
9✔
40
        $num = preg_match_all(self::COMPOSITE_IDENTIFIER_REGEXP, $identifier, $matches, \PREG_SET_ORDER);
9✔
41

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

50
        return $identifiers;
9✔
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 = [];
25✔
UNCOV
59
        foreach ($identifiers as $name => $value) {
25✔
UNCOV
60
            $composite[] = \sprintf('%s=%s', $name, $value);
25✔
61
        }
62

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