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

api-platform / core / 14008635868

22 Mar 2025 12:39PM UTC coverage: 8.52% (+0.005%) from 8.515%
14008635868

Pull #7042

github

web-flow
Merge fdd88ef56 into 47a6dffbb
Pull Request #7042: Purge parent collections in inheritance cases

4 of 9 new or added lines in 1 file covered. (44.44%)

540 existing lines in 57 files now uncovered.

13394 of 157210 relevant lines covered (8.52%)

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

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

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

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