Skip to content

Commit 391bdec

Browse files
committed
Split methods
1 parent f173b79 commit 391bdec

File tree

1 file changed

+64
-54
lines changed

1 file changed

+64
-54
lines changed

src/Metadata/YamlExtractor.php

Lines changed: 64 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -68,62 +68,72 @@ public function getResources(): array
6868
throw new InvalidArgumentException(sprintf('"resources" setting is expected to be null or an array, %s given in "%s".', gettype($resourcesYaml), $path));
6969
}
7070

71-
foreach ($resourcesYaml as $resourceName => $resourceYaml) {
72-
if (null === $resourceYaml) {
73-
$this->resources[$resourceName] = null;
74-
75-
continue;
76-
}
77-
78-
if (!is_array($resourceYaml)) {
79-
throw new InvalidArgumentException(sprintf('"%s" setting is expected to be null or an array, %s given in "%s".', $resourceName, gettype($resourceYaml), $path));
80-
}
81-
82-
$this->resources[$resourceName] = [
83-
'shortName' => $resourceYaml['shortName'] ?? null,
84-
'description' => $resourceYaml['description'] ?? null,
85-
'iri' => $resourceYaml['iri'] ?? null,
86-
'itemOperations' => $resourceYaml['itemOperations'] ?? null,
87-
'collectionOperations' => $resourceYaml['collectionOperations'] ?? null,
88-
'attributes' => $resourceYaml['attributes'] ?? null,
89-
];
90-
91-
if (!isset($resourceYaml['properties'])) {
92-
$this->resources[$resourceName]['properties'] = null;
93-
94-
continue;
95-
}
96-
97-
if (!is_array($resourceYaml['properties'])) {
98-
throw new InvalidArgumentException(sprintf('"properties" setting is expected to be null or an array, %s given in "%s".', gettype($resourceYaml['properties']), $path));
99-
}
100-
101-
foreach ($resourceYaml['properties'] as $propertyName => $propertyValues) {
102-
if (null === $propertyValues) {
103-
$this->resources[$resourceName]['properties'][$propertyName] = null;
104-
105-
continue;
106-
}
107-
108-
if (!is_array($propertyValues)) {
109-
throw new InvalidArgumentException(sprintf('"%s" setting is expected to be null or an array, %s given in "%s".', $propertyName, gettype($propertyValues), $path));
110-
}
111-
112-
$this->resources[$resourceName]['properties'][$propertyName] = [
113-
'description' => isset($propertyValues['description']) && is_scalar($propertyValues['description']) ? $propertyValues['description'] : null,
114-
'readable' => isset($propertyValues['readable']) && is_bool($propertyValues['readable']) ? $propertyValues['readable'] : null,
115-
'writable' => isset($propertyValues['writable']) && is_bool($propertyValues['writable']) ? $propertyValues['writable'] : null,
116-
'readableLink' => isset($propertyValues['readableLink']) && is_bool($propertyValues['readableLink']) ? $propertyValues['readableLink'] : null,
117-
'writableLink' => isset($propertyValues['writableLink']) && is_bool($propertyValues['writableLink']) ? $propertyValues['writableLink'] : null,
118-
'required' => isset($propertyValues['required']) && is_bool($propertyValues['required']) ? $propertyValues['required'] : null,
119-
'identifier' => isset($propertyValues['identifier']) && is_bool($propertyValues['identifier']) ? $propertyValues['identifier'] : null,
120-
'iri' => isset($propertyValues['iri']) && is_scalar($propertyValues['iri']) ? $propertyValues['iri'] : null,
121-
'attributes' => $propertyValues['attributes'] ?? null,
122-
];
123-
}
124-
}
71+
$this->extractResourcesFromYaml($resourcesYaml, $path);
12572
}
12673

12774
return $this->resources;
12875
}
76+
77+
private function extractResourcesFromYaml(array $resourcesYaml, string $path)
78+
{
79+
foreach ($resourcesYaml as $resourceName => $resourceYaml) {
80+
if (null === $resourceYaml) {
81+
$this->resources[$resourceName] = null;
82+
83+
continue;
84+
}
85+
86+
if (!is_array($resourceYaml)) {
87+
throw new InvalidArgumentException(sprintf('"%s" setting is expected to be null or an array, %s given in "%s".', $resourceName, gettype($resourceYaml), $path));
88+
}
89+
90+
$this->resources[$resourceName] = [
91+
'shortName' => $resourceYaml['shortName'] ?? null,
92+
'description' => $resourceYaml['description'] ?? null,
93+
'iri' => $resourceYaml['iri'] ?? null,
94+
'itemOperations' => $resourceYaml['itemOperations'] ?? null,
95+
'collectionOperations' => $resourceYaml['collectionOperations'] ?? null,
96+
'attributes' => $resourceYaml['attributes'] ?? null,
97+
];
98+
99+
if (!isset($resourceYaml['properties'])) {
100+
$this->resources[$resourceName]['properties'] = null;
101+
102+
continue;
103+
}
104+
105+
if (!is_array($resourceYaml['properties'])) {
106+
throw new InvalidArgumentException(sprintf('"properties" setting is expected to be null or an array, %s given in "%s".', gettype($resourceYaml['properties']), $path));
107+
}
108+
109+
$this->extractPropertiesFromYaml($resourceYaml, $resourceName, $path);
110+
}
111+
}
112+
113+
private function extractPropertiesFromYaml(array $resourceYaml, string $resourceName, $path)
114+
{
115+
foreach ($resourceYaml['properties'] as $propertyName => $propertyValues) {
116+
if (null === $propertyValues) {
117+
$this->resources[$resourceName]['properties'][$propertyName] = null;
118+
119+
continue;
120+
}
121+
122+
if (!is_array($propertyValues)) {
123+
throw new InvalidArgumentException(sprintf('"%s" setting is expected to be null or an array, %s given in "%s".', $propertyName, gettype($propertyValues), $path));
124+
}
125+
126+
$this->resources[$resourceName]['properties'][$propertyName] = [
127+
'description' => isset($propertyValues['description']) && is_scalar($propertyValues['description']) ? $propertyValues['description'] : null,
128+
'readable' => isset($propertyValues['readable']) && is_bool($propertyValues['readable']) ? $propertyValues['readable'] : null,
129+
'writable' => isset($propertyValues['writable']) && is_bool($propertyValues['writable']) ? $propertyValues['writable'] : null,
130+
'readableLink' => isset($propertyValues['readableLink']) && is_bool($propertyValues['readableLink']) ? $propertyValues['readableLink'] : null,
131+
'writableLink' => isset($propertyValues['writableLink']) && is_bool($propertyValues['writableLink']) ? $propertyValues['writableLink'] : null,
132+
'required' => isset($propertyValues['required']) && is_bool($propertyValues['required']) ? $propertyValues['required'] : null,
133+
'identifier' => isset($propertyValues['identifier']) && is_bool($propertyValues['identifier']) ? $propertyValues['identifier'] : null,
134+
'iri' => isset($propertyValues['iri']) && is_scalar($propertyValues['iri']) ? $propertyValues['iri'] : null,
135+
'attributes' => $propertyValues['attributes'] ?? null,
136+
];
137+
}
138+
}
129139
}

0 commit comments

Comments
 (0)