Skip to content

Commit

Permalink
Skip dummy parts and parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbestle committed Mar 17, 2024
1 parent 525d405 commit 21a6e26
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/classes/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ public function parts(): Collection
throw new InvalidArgumentException('Invalid part ' . $num);
}

// skip dummy parts
if (is_string($part['articleNr'] ?? null) !== true) {
continue;
}

$parts[] = new Part($part);
}

Expand Down
5 changes: 5 additions & 0 deletions src/classes/Part.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ public function parameters(): Parameters
throw new InvalidArgumentException('Invalid parameter ' . $num);
}

// skip dummy parameters
if (is_string($parameter['value'] ?? null) !== true) {
continue;
}

$parameter = new Parameter($parameter);

// double-check uninitialized property before access (normally should not happen);
Expand Down
7 changes: 7 additions & 0 deletions tests/Roomle/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,23 @@ public function testParts()
$configuration = new Configuration([
'parts' => [
[
'articleNr' => '12345',
'componentId' => 'some:component1',
'label' => 'Some component 1'
],
[
'articleNr' => '12345',
'componentId' => 'some:component1',
'label' => 'Some component 1 with different properties'
],
[
'articleNr' => '23456',
'componentId' => 'some:component2',
'label' => 'Some component 2'
],
[
'componentId' => 'some:component3',
'label' => 'Some component 3 without article number'
]
]
]);
Expand Down
7 changes: 6 additions & 1 deletion tests/Roomle/PartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public function testParameters()
'type' => 'Decimal',
'unitType' => 'length',
'value' => '456.0'
],
[
'key' => 'internal',
'label' => 'Internal parameter without value'
]
]
]);
Expand Down Expand Up @@ -106,7 +110,8 @@ public function testParameters_Invalid2()
$part = new Part([
'parameters' => [
[
'label' => 'Some parameter without key'
'label' => 'Some parameter without key',
'value' => '123'
]
]
]);
Expand Down

0 comments on commit 21a6e26

Please sign in to comment.