Skip to content

Commit c1a7a31

Browse files
committed
Adjust parameter types
1 parent 7635c2b commit c1a7a31

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/Html.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function addClass(array|string $value): Html
135135
/**
136136
* Add a class based on a boolean value.
137137
*/
138-
public function addClassIf(bool $check, string $class_name_1 = '', string $class_name_0 = ''): Html
138+
public function addClassIf(?bool $check, string $class_name_1 = '', string $class_name_0 = ''): Html
139139
{
140140
return $this->addClass($check ? $class_name_1 : $class_name_0);
141141
}
@@ -145,7 +145,7 @@ public function addClassIf(bool $check, string $class_name_1 = '', string $class
145145
*
146146
* @param mixed ...$attr
147147
*/
148-
public function addAttrIf(bool $check, ...$attr): Html
148+
public function addAttrIf(?bool $check, ...$attr): Html
149149
{
150150
if ($check) {
151151
return $this->attr(...$attr);
@@ -495,9 +495,9 @@ public function hidden(): Html
495495
/**
496496
* Shortcut to set('href', $value). Only works with A tags.
497497
*/
498-
public function href(string $value = ''): Html
498+
public function href(?string $value = ''): Html
499499
{
500-
if ($this->tag === 'a') {
500+
if ($this->tag === 'a' && ! is_null($value)) {
501501
return parent::attr('href', $value);
502502
}
503503

@@ -757,19 +757,19 @@ public function rows(int|string $rows): Html
757757
/**
758758
* Add an route link.
759759
*/
760-
public function route(string $text, string $route, array $parameters = [], string $target = ''): Html
760+
public function route(?string $text, string $route, array $parameters = [], string $target = ''): Html
761761
{
762762
$href = route($route, $parameters);
763763
$href .= !empty($target) ? '#'.$target : '';
764764

765-
return $this->addElement('a')->text($text)
765+
return $this->addElement('a')->text($text ?? '')
766766
->href($href);
767767
}
768768

769769
/**
770770
* Add an route href.
771771
*/
772-
public function routeHref(string $route, array $parameters = [], string $target = ''): Html
772+
public function routeHref(?string $route, array $parameters = [], string $target = ''): Html
773773
{
774774
$href = route($route, $parameters);
775775
$href .= !empty($target) ? '#'.$target : '';
@@ -882,7 +882,7 @@ public function src(string $value): Html
882882
/**
883883
* Add a style based on a boolean value.
884884
*/
885-
public function addStyleIf(bool $check, string $style_1 = '', string $style_0 = ''): Html
885+
public function addStyleIf(?bool $check, string $style_1 = '', string $style_0 = ''): Html
886886
{
887887
return $this->style($check ? $style_1 : $style_0);
888888
}
@@ -945,16 +945,20 @@ public function text($value, ...$args): Html
945945
*
946946
* @param mixed $args
947947
*/
948-
public function textIf(bool $test, string $value, ...$args): Html
948+
public function textIf(?bool $test, string $value, ...$args): Html
949949
{
950950
return $test ? $this->text($value, ...$args) : $this;
951951
}
952952

953953
/**
954954
* Shortcut to set('title', $value).
955955
*/
956-
public function title(string $value): Html
956+
public function title(?string $value): Html
957957
{
958+
if (is_null($value)) {
959+
return $this;
960+
}
961+
958962
return parent::attr('title', $value);
959963
}
960964

0 commit comments

Comments
 (0)