Skip to content
This repository was archived by the owner on Mar 12, 2024. It is now read-only.

Commit cae6c65

Browse files
committedMar 25, 2022
handle null case
1 parent 0342d93 commit cae6c65

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed
 

‎src/Traits/LoopFunctions.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ trait LoopFunctions
2020
*/
2121
public function propertiesFrom(Model|array|null $data = null, mixed $rescue = null): void
2222
{
23-
match (true) {
24-
is_array($data) => $this->arrayToProperties($data, $rescue),
25-
$data instanceof Model => $this->attributesToProperties($data, $rescue),
26-
};
23+
if ($data) {
24+
match (true) {
25+
is_array($data) => $this->arrayToProperties($data, $rescue),
26+
$data instanceof Model => $this->attributesToProperties($data, $rescue),
27+
};
28+
}
2729
}
2830

2931
/**

‎tests/ArrayMappingTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,9 @@ public function testCanMapUsingPropertiesFrom()
115115
$this->propertiesFrom($array);
116116

117117
$this->assertArrayHasKey('next', $this->additional_data);
118+
119+
$this->propertiesFrom(null);
120+
121+
$this->assertArrayHasKey('next', $this->additional_data);
118122
}
119123
}

‎tests/AttributeMappingTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,10 @@ public function testCanMapUsingPropertiesFrom()
137137

138138
$this->assertInstanceOf(Collection::class, $this->collection);
139139
$this->assertIsString($this->intAsString);
140+
141+
$this->propertiesFrom(null);
142+
143+
$this->assertInstanceOf(Collection::class, $this->collection);
144+
$this->assertIsString($this->intAsString);
140145
}
141146
}

0 commit comments

Comments
 (0)
This repository has been archived.