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

api-platform / core / 15255731762

26 May 2025 01:55PM UTC coverage: 0.0% (-26.5%) from 26.526%
15255731762

Pull #7176

github

web-flow
Merge 66f6cf4d2 into 79edced67
Pull Request #7176: Merge 4.1

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

11394 existing lines in 372 files now uncovered.

0 of 51334 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/src/Metadata/Extractor/ResourceExtractorTrait.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\Extractor;
15

16
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
17
use Symfony\Component\Config\Util\XmlUtils;
18

19
/**
20
 * Utils for ResourceExtractors.
21
 *
22
 * @author Vincent Chalamon <vincentchalamon@gmail.com>
23
 */
24
trait ResourceExtractorTrait
25
{
26
    private function buildArrayValue(\SimpleXMLElement|array|null $resource, string $key, mixed $default = null): ?array
27
    {
UNCOV
28
        if (\is_object($resource) && $resource instanceof \SimpleXMLElement) {
×
UNCOV
29
            if (!isset($resource->{$key.'s'}->{$key})) {
×
UNCOV
30
                return $default;
×
31
            }
32

33
            return (array) $resource->{$key.'s'}->{$key};
×
34
        }
35

UNCOV
36
        if (empty($resource[$key])) {
×
UNCOV
37
            return $default;
×
38
        }
39

UNCOV
40
        if (!\is_array($resource[$key])) {
×
41
            throw new InvalidArgumentException(\sprintf('"%s" setting is expected to be an array, %s given', $key, \gettype($resource[$key])));
×
42
        }
43

UNCOV
44
        return $resource[$key];
×
45
    }
46

47
    /**
48
     * Transforms an attribute's value in a PHP value.
49
     */
50
    private function phpize(\SimpleXMLElement|array|null $resource, string $key, string $type, mixed $default = null): array|bool|int|string|null
51
    {
UNCOV
52
        if (!isset($resource[$key])) {
×
UNCOV
53
            return $default;
×
54
        }
55

56
        switch ($type) {
UNCOV
57
            case 'bool|string':
×
UNCOV
58
                return \is_bool($resource[$key]) || \in_array((string) $resource[$key], ['1', '0', 'true', 'false'], true) ? $this->phpize($resource, $key, 'bool') : $this->phpize($resource, $key, 'string');
×
UNCOV
59
            case 'string':
×
UNCOV
60
                return (string) $resource[$key];
×
61
            case 'integer':
×
62
                return (int) $resource[$key];
×
63
            case 'bool':
×
64
                if (\is_object($resource) && $resource instanceof \SimpleXMLElement) {
×
65
                    return (bool) XmlUtils::phpize($resource[$key]);
×
66
                }
67

68
                return \in_array($resource[$key], ['1', 'true', 1, true], false);
×
69
        }
70

71
        throw new InvalidArgumentException(\sprintf('The property "%s" must be a "%s", "%s" given.', $key, $type, \gettype($resource[$key])));
×
72
    }
73

74
    private function buildArgs(\SimpleXMLElement $resource): ?array
75
    {
76
        if (!isset($resource->args->arg)) {
×
77
            return null;
×
78
        }
79

80
        $data = [];
×
81
        foreach ($resource->args->arg as $arg) {
×
82
            $data[(string) $arg['id']] = $this->buildValues($arg->values);
×
83
        }
84

85
        return $data;
×
86
    }
87

88
    private function buildExtraArgs(\SimpleXMLElement $resource): ?array
89
    {
90
        if (!isset($resource->extraArgs->arg)) {
×
91
            return null;
×
92
        }
93

94
        $data = [];
×
95
        foreach ($resource->extraArgs->arg as $arg) {
×
96
            $data[(string) $arg['id']] = $this->buildValues($arg->values);
×
97
        }
98

99
        return $data;
×
100
    }
101

102
    private function buildValues(\SimpleXMLElement $resource): array
103
    {
104
        $data = [];
×
105
        foreach ($resource->value as $value) {
×
106
            if (null !== $value->attributes()->name) {
×
107
                $data[(string) $value->attributes()->name] = isset($value->values) ? $this->buildValues($value->values) : XmlUtils::phpize($value->__toString());
×
108
                continue;
×
109
            }
110

111
            $data[] = isset($value->values) ? $this->buildValues($value->values) : XmlUtils::phpize($value->__toString());
×
112
        }
113

114
        return $data;
×
115
    }
116
}
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