Skip to content

Commit dd4a946

Browse files
authored
Merge pull request #260 from miken32/main
make BaseElement::unless() compatible with Conditionable::unless()
2 parents a9025e9 + 0fb0b09 commit dd4a946

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/BaseElement.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@
7171
*/
7272
abstract class BaseElement implements Htmlable, HtmlElement
7373
{
74-
use Conditionable;
74+
use Conditionable {
75+
unless as trait_unless;
76+
}
7577

7678
use Macroable {
7779
__call as __macro_call;
@@ -388,13 +390,18 @@ public function if(bool $condition, \Closure $callback)
388390
* Conditionally transform the element. Note that since elements are
389391
* immutable, you'll need to return a new instance from the callback.
390392
*
391-
* @param bool $condition
392-
* @param \Closure $callback
393+
* @param mixed $condition
394+
* @param callable $callback
395+
* @param callable|null $default
393396
*
394397
* @return mixed
395398
*/
396-
public function unless(bool $condition, \Closure $callback)
399+
public function unless($condition, callable $callback, callable|null $default = null)
397400
{
401+
if (! is_bool($condition) || ! $callback instanceof \Closure || ! is_null($default)) {
402+
return $this->trait_unless($condition, $callback, $default);
403+
}
404+
398405
return $this->if(! $condition, $callback);
399406
}
400407

0 commit comments

Comments
 (0)