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

api-platform / core / 6148660584

11 Sep 2023 03:40PM UTC coverage: 37.077% (-0.1%) from 37.185%
6148660584

push

github

soyuka
chore(symfony): security after validate when validator installed

10090 of 27214 relevant lines covered (37.08%)

19.39 hits per line

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

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

16
use ApiPlatform\Metadata\Tests\Extractor\PropertyMetadataCompatibilityTest;
17

18
/**
19
 * XML adapter for PropertyMetadataCompatibilityTest.
20
 *
21
 * @author Vincent Chalamon <vincentchalamon@gmail.com>
22
 */
23
final class XmlPropertyAdapter implements PropertyAdapterInterface
24
{
25
    private const ATTRIBUTES = [
26
        'resource',
27
        'name',
28
        'description',
29
        'readable',
30
        'writable',
31
        'readableLink',
32
        'writableLink',
33
        'required',
34
        'identifier',
35
        'default',
36
        'example',
37
        'deprecationReason',
38
        'fetchable',
39
        'fetchEager',
40
        'push',
41
        'security',
42
        'securityPostDenormalize',
43
        'initializable',
44
        'iris',
45
        'genId',
46
        'uriTemplate',
47
    ];
48

49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function __invoke(string $resourceClass, string $propertyName, array $parameters, array $fixtures): array
53
    {
54
        $xml = new \SimpleXMLElement(<<<XML_WRAP
×
55
<?xml version="1.0" encoding="UTF-8" ?>
56
<properties xmlns="https://api-platform.com/schema/metadata/properties-3.0"
57
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
58
           xsi:schemaLocation="https://api-platform.com/schema/metadata/properties-3.0
59
           https://api-platform.com/schema/metadata/properties-3.0.xsd">
60
</properties>
61
XML_WRAP
×
62
        );
×
63

64
        $property = $xml->addChild('property');
×
65
        $property->addAttribute('name', $propertyName);
×
66
        $property->addAttribute('resource', $resourceClass);
×
67

68
        foreach ($parameters as $parameter) {
×
69
            $parameterName = $parameter->getName();
×
70
            $value = \array_key_exists($parameterName, $fixtures) ? $fixtures[$parameterName] : null;
×
71

72
            if (method_exists($this, 'build'.ucfirst($parameterName))) {
×
73
                $this->{'build'.ucfirst($parameterName)}($property, $value);
×
74
                continue;
×
75
            }
76

77
            if (\in_array($parameterName, self::ATTRIBUTES, true) && \is_scalar($value)) {
×
78
                $property->addAttribute($parameterName, $this->parse($value));
×
79
                continue;
×
80
            }
81

82
            throw new \LogicException(sprintf('Cannot adapt attribute or child "%s". Please add fixtures in '.PropertyMetadataCompatibilityTest::class.' and create a "%s" method in %s.', $parameterName, 'build'.ucfirst($parameterName), self::class));
×
83
        }
84

85
        $filename = __DIR__.'/properties.xml';
×
86
        $xml->asXML($filename);
×
87

88
        return [$filename];
×
89
    }
90

91
    private function buildBuiltinTypes(\SimpleXMLElement $resource, array $values): void
92
    {
93
        $node = $resource->addChild('builtinTypes');
×
94
        foreach ($values as $value) {
×
95
            $node->addChild('builtinType', $value);
×
96
        }
97
    }
98

99
    private function buildSchema(\SimpleXMLElement $resource, array $values): void
100
    {
101
        $this->buildValues($resource->addChild('schema'), $values);
×
102
    }
103

104
    private function buildTypes(\SimpleXMLElement $resource, array $values): void
105
    {
106
        $node = $resource->addChild('types');
×
107
        foreach ($values as $value) {
×
108
            $node->addChild('type', $value);
×
109
        }
110
    }
111

112
    private function buildIris(\SimpleXMLElement $resource, array $values): void
113
    {
114
        $node = $resource->addChild('iris');
×
115
        foreach ($values as $value) {
×
116
            $node->addChild('iri', $value);
×
117
        }
118
    }
119

120
    private function buildJsonldContext(\SimpleXMLElement $resource, array $values): void
121
    {
122
        $this->buildValues($resource->addChild('jsonldContext'), $values);
×
123
    }
124

125
    private function buildOpenapiContext(\SimpleXMLElement $resource, array $values): void
126
    {
127
        $this->buildValues($resource->addChild('openapiContext'), $values);
×
128
    }
129

130
    private function buildJsonSchemaContext(\SimpleXMLElement $resource, array $values): void
131
    {
132
        $this->buildValues($resource->addChild('jsonSchemaContext'), $values);
×
133
    }
134

135
    private function buildExtraProperties(\SimpleXMLElement $resource, array $values): void
136
    {
137
        $this->buildValues($resource->addChild('extraProperties'), $values);
×
138
    }
139

140
    private function buildValues(\SimpleXMLElement $resource, array $values): void
141
    {
142
        $node = $resource->addChild('values');
×
143
        foreach ($values as $key => $value) {
×
144
            if (\is_array($value)) {
×
145
                $child = $node->addChild('value');
×
146
                $this->buildValues($child, $value);
×
147
            } else {
148
                $child = $node->addChild('value', $value);
×
149
            }
150
            if (\is_string($key)) {
×
151
                $child->addAttribute('name', $key);
×
152
            }
153
        }
154
    }
155

156
    private function parse(string|int|float|bool|null $value): ?string
157
    {
158
        if (null === $value) {
×
159
            return null;
×
160
        }
161

162
        return \is_bool($value) ? (true === $value ? 'true' : 'false') : (string) $value;
×
163
    }
164
}
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