Skip to content

Commit daa9092

Browse files
Merge pull request #4 from dkarvounaris/fix-3
Fix for #3
2 parents 911a18d + 71c0ce0 commit daa9092

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/Data/XMLElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class XMLElement extends SimpleXMLElement
1616
*/
1717
public function attribute(string $name, mixed $default = null): mixed
1818
{
19-
return $this->attributes()->{$name} ?? $default;
19+
return !is_null($this->attributes()->{$name}) ? (string)$this->attributes()->{$name} : $default;
2020
}
2121

2222
/**

tests/Unit/XMLImportTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function test_can_get_element_attributes()
3030
$path = __DIR__.'/../Features/Import/stubs/notes.xml';
3131
$xml = XML::import($path)->get()->note;
3232

33+
$this->assertIsString($xml->attribute('completed'));
3334
$this->assertEquals('true', $xml->attribute('completed'));
3435
$this->assertEquals('0', $xml->attribute('stars', '2'));
3536
$this->assertEquals('1', $xml->attribute('shares', '2'));

0 commit comments

Comments
 (0)