Skip to content

Commit 0f28326

Browse files
committed
refactor(Impact\Embodied\AbstractAsset): use Type object to traverse supported impact types
1 parent 1c5dc7d commit 0f28326

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/Impact/Embodied/Boavizta/AbstractAsset.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,25 @@ protected function query($description): array
123123
protected function parseResponse(array $response): array
124124
{
125125
$impacts = [];
126+
$types = Type::getImpactTypes();
126127
foreach ($response['impacts'] as $type => $impact) {
127-
if (!in_array($type, Type::getImpactTypes())) {
128+
if (!in_array($type, $types)) {
128129
trigger_error(sprintf('Unsupported impact type %s in class %s', $type, __CLASS__));
129130
continue;
130131
}
131-
132+
$impact_id = Type::getImpactId($type);
133+
if ($impact_id === false) {
134+
continue;
135+
}
132136
switch ($type) {
133137
case 'gwp':
134-
$impacts[Type::IMPACT_GWP] = $this->parseGwp($response['impacts']['gwp']);
138+
$impacts[$impact_id] = $this->parseGwp($response['impacts'][$type]);
135139
break;
136140
case 'adp':
137-
$impacts[Type::IMPACT_ADP] = $this->parseAdp($response['impacts']['adp']);
141+
$impacts[$impact_id] = $this->parseAdp($response['impacts'][$type]);
138142
break;
139143
case 'pe':
140-
$impacts[Type::IMPACT_PE] = $this->parsePe($response['impacts']['pe']);
144+
$impacts[$impact_id] = $this->parsePe($response['impacts'][$type]);
141145
break;
142146
}
143147
}

0 commit comments

Comments
 (0)