Skip to content

Commit

Permalink
ValidatedTerm: Accept null as label
Browse files Browse the repository at this point in the history
An oversight. The label was always optional.
Also cleans up some type declarations which
were anything but correct.
  • Loading branch information
nilmerg committed Jul 21, 2023
1 parent 482d588 commit 7544e80
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Control/SearchBar/ValidatedOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function setSearchValue(string $searchValue): ValidatedTerm
throw new LogicException('Operators cannot be changed');
}

public function setLabel(string $label): ValidatedTerm
public function setLabel(?string $label): ValidatedTerm
{
throw new LogicException('Operators cannot be changed');
}
Expand Down
24 changes: 12 additions & 12 deletions src/Control/SearchBar/ValidatedTerm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ abstract class ValidatedTerm
/** @var string The default validation constraint */
const DEFAULT_PATTERN = '^\s*(?!%s\b).*\s*$';

/** @var mixed The search value */
/** @var string The search value */
protected $searchValue;

/** @var string The label */
/** @var ?string The label */
protected $label;

/** @var string The validation message */
/** @var ?string The validation message */
protected $message;

/** @var string The validation constraint */
/** @var ?string The validation constraint */
protected $pattern;

/** @var bool Whether the term has been adjusted */
Expand All @@ -27,10 +27,10 @@ abstract class ValidatedTerm
/**
* Create a new ValidatedTerm
*
* @param mixed $searchValue The search value
* @param string $searchValue The search value
* @param ?string $label The label
*/
public function __construct($searchValue, $label = null)
public function __construct(string $searchValue, ?string $label = null)
{
$this->searchValue = $searchValue;
$this->label = $label;
Expand Down Expand Up @@ -106,13 +106,13 @@ public function getLabel(): ?string
/**
* Set the label
*
* @param string $label
* @param ?string $label
*
* @return $this
*/
public function setLabel(string $label): self
public function setLabel(?string $label): self
{
$this->label = (string) $label;
$this->label = $label;
$this->changed = true;

return $this;
Expand All @@ -121,7 +121,7 @@ public function setLabel(string $label): self
/**
* Get the validation message
*
* @return string
* @return ?string
*/
public function getMessage(): ?string
{
Expand All @@ -131,7 +131,7 @@ public function getMessage(): ?string
/**
* Set the validation message
*
* @param ?string $message
* @param string $message
*
* @return $this
*/
Expand Down Expand Up @@ -167,7 +167,7 @@ public function getPattern(): string
*/
public function setPattern(string $pattern): self
{
$this->pattern = (string) $pattern;
$this->pattern = $pattern;

return $this;
}
Expand Down

0 comments on commit 7544e80

Please sign in to comment.