Skip to content

Commit de04718

Browse files
committed
Applied same re-use of when() to whenContains() and whenContainsAll().
1 parent 5871d64 commit de04718

File tree

1 file changed

+2
-22
lines changed

1 file changed

+2
-22
lines changed

src/Illuminate/Support/Stringable.php

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -775,17 +775,7 @@ public function ucfirst()
775775
*/
776776
public function whenContains($needles, $callback, $default = null)
777777
{
778-
if ($this->contains($needles)) {
779-
$result = $callback($this);
780-
781-
return $result ?? $this;
782-
} elseif ($default) {
783-
$result = $default($this);
784-
785-
return $result ?? $this;
786-
}
787-
788-
return $this;
778+
return $this->when($this->contains($needles), $callback, $default);
789779
}
790780

791781
/**
@@ -798,17 +788,7 @@ public function whenContains($needles, $callback, $default = null)
798788
*/
799789
public function whenContainsAll(array $needles, $callback, $default = null)
800790
{
801-
if ($this->containsAll($needles)) {
802-
$result = $callback($this);
803-
804-
return $result ?? $this;
805-
} elseif ($default) {
806-
$result = $default($this);
807-
808-
return $result ?? $this;
809-
}
810-
811-
return $this;
791+
return $this->when($this->containsAll($needles), $callback, $default);
812792
}
813793

814794
/**

0 commit comments

Comments
 (0)