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

api-platform / core / 3904303394

pending completion
3904303394

Pull #5332

github

GitHub
Merge 2e0a3ceae into 965332bc8
Pull Request #5332: Revert "chore(deprecation): Only use ValueResolverInterface if it exists"

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

7939 of 12085 relevant lines covered (65.69%)

81.77 hits per line

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

92.86
/src/Api/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\Api;
15

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

25
    private function __construct()
26
    {
27
    }
×
28

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

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

48
        return $identifiers;
8✔
49
    }
50

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

61
        return implode(';', $composite);
15✔
62
    }
63
}
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