Skip to content

Commit

Permalink
blank and filled now support stringable (#51300)
Browse files Browse the repository at this point in the history
* filled and blank works with `Stringable`

* unnecessary

---------

Co-authored-by: stefan.riedel <[email protected]>
  • Loading branch information
lava83 and stefan.riedel authored May 5, 2024
1 parent 7269425 commit 2dee1de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Support/helpers.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ function blank($value)
return count($value) === 0;
}

if ($value instanceof Stringable) {
return $value->trim()->toString() === '';
}

return empty($value);
}
}
Expand Down
6 changes: 6 additions & 0 deletions tests/Support/SupportHelpersTest.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,14 @@ public function testBlank()
$this->assertTrue(blank(null));
$this->assertTrue(blank(''));
$this->assertTrue(blank(' '));
$this->assertTrue(blank(new Stringable('')));
$this->assertTrue(blank(new Stringable(' ')));
$this->assertFalse(blank(10));
$this->assertFalse(blank(true));
$this->assertFalse(blank(false));
$this->assertFalse(blank(0));
$this->assertFalse(blank(0.0));
$this->assertFalse(blank(new Stringable(' FooBar ')));

$object = new SupportTestCountable();
$this->assertTrue(blank($object));
Expand Down Expand Up @@ -102,11 +105,14 @@ public function testFilled()
$this->assertFalse(filled(null));
$this->assertFalse(filled(''));
$this->assertFalse(filled(' '));
$this->assertFalse(filled(new Stringable('')));
$this->assertFalse(filled(new Stringable(' ')));
$this->assertTrue(filled(10));
$this->assertTrue(filled(true));
$this->assertTrue(filled(false));
$this->assertTrue(filled(0));
$this->assertTrue(filled(0.0));
$this->assertTrue(filled(new Stringable(' FooBar ')));

$object = new SupportTestCountable();
$this->assertFalse(filled($object));
Expand Down

0 comments on commit 2dee1de

Please sign in to comment.