Skip to content

Commit

Permalink
rework properties in LikeExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Apr 15, 2023
1 parent ad4fc03 commit bbb1fa2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 27 deletions.
25 changes: 4 additions & 21 deletions src/Collection/Expression/LikeExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,11 @@ public static function contains(string $input): LikeExpression
public const MODE_ENDS_WITH = 2;
public const MODE_CONTAINS = 3;

/** @var string */
private $input;

/** @var int */
private $mode;


private function __construct(string $input, int $mode)
{
$this->input = $input;
$this->mode = $mode;
}


public function getInput(): string
{
return $this->input;
}


public function getMode(): int
private function __construct(
public readonly string $input,
public readonly int $mode,
)
{
return $this->mode;
}
}
12 changes: 6 additions & 6 deletions src/Collection/Functions/CompareLikeFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public function processArrayExpression(

$likeExpression = $args[1];
assert($likeExpression instanceof LikeExpression);
$mode = $likeExpression->getMode();
$mode = $likeExpression->mode;

if ($valueReference->propertyMetadata !== null) {
$targetValue = $helper->normalizeValue($likeExpression->getInput(), $valueReference->propertyMetadata, true);
$targetValue = $helper->normalizeValue($likeExpression->input, $valueReference->propertyMetadata, checkMultiDimension: true);
} else {
$targetValue = $likeExpression->getInput();
$targetValue = $likeExpression->input;
}

if ($valueReference->aggregator !== null) {
Expand Down Expand Up @@ -73,13 +73,13 @@ public function processQueryBuilderExpression(

$likeExpression = $args[1];
assert($likeExpression instanceof LikeExpression);
$mode = $likeExpression->getMode();
$mode = $likeExpression->mode;

if ($expression->valueNormalizer !== null) {
$cb = $expression->valueNormalizer;
$value = $cb($likeExpression->getInput());
$value = $cb($likeExpression->input);
} else {
$value = $likeExpression->getInput();
$value = $likeExpression->input;
}

return $this->evaluateInDb($mode, $expression, $value);
Expand Down

0 comments on commit bbb1fa2

Please sign in to comment.