Skip to content

Commit

Permalink
Changed expected min and max value types to numeric instead of int
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Dec 12, 2023
1 parent 51d0515 commit b171d78
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/contracts/Repository/Values/Content/Query/Criterion.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract class Criterion implements CriterionInterface
/**
* The value(s) matched by the criteria.
*
* @var string[]|int[]|int|string|bool
* @var scalar[]|scalar
*/
public $value;

Expand All @@ -50,7 +50,7 @@ abstract class Criterion implements CriterionInterface
* @param string|null $operator
* The operator the Criterion uses. If null is given, will default to Operator::IN if $value is an array,
* Operator::EQ if it is not.
* @param string[]|int[]|int|string|bool $value
* @param scalar[]|scalar $value
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Value|null $valueData
*
* @todo Add a dedicated exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* @template TImageCriteria of array
*
* @phpstan-type Range array{
* min?: int|null,
* max?: int|null,
* min?: numeric|null,
* max?: numeric|null,
* }
*/
abstract class AbstractImageCompositeCriterion extends CompositeCriterion
Expand Down Expand Up @@ -91,17 +91,21 @@ protected function validate(
}

/**
* @param array{min?: int|null} $data
* @param array{min?: numeric|null} $data
*
* @return numeric
*/
protected function getMinValue(array $data): int
protected function getMinValue(array $data)
{
return $data['min'] ?? 0;
}

/**
* @param array{max?: int|null} $data
* @param array{max?: numeric|null} $data
*
* @return numeric|null
*/
protected function getMaxValue(array $data): ?int
protected function getMaxValue(array $data)
{
return $data['max'] ?? null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@
abstract class AbstractImageRangeCriterion extends Criterion
{
/**
* @param numeric $minValue
* @param numeric|null $maxValue
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*/
public function __construct(
string $fieldDefIdentifier,
int $minValue = 0,
?int $maxValue = null
$minValue = 0,
$maxValue = null
) {
$this->validate($minValue, $maxValue);

$value[] = $minValue;
$operator = Operator::GTE;

if ($maxValue >= 1) {
if ($maxValue > 0) {
$operator = Operator::BETWEEN;
$value[] = $maxValue;
}
Expand Down Expand Up @@ -57,12 +60,13 @@ public function getSpecifications(): array
}

/**
* @param numeric $minValue
* @param numeric|null $maxValue
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*/
protected function validate(
int $minValue,
?int $maxValue
): void {
protected function validate($minValue, $maxValue): void
{
if ($minValue < 0) {
throw new InvalidArgumentException(
'$minValue',
Expand All @@ -72,11 +76,11 @@ protected function validate(

if (
null !== $maxValue
&& $maxValue < 1
&& $maxValue <= 0
) {
throw new InvalidArgumentException(
'$maxValue',
'Value should be grater or equal 1'
'Value should be grater than 0'
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
final class FileSize extends AbstractImageRangeCriterion
{
/**
* @param numeric $minFileSize
* @param numeric|null $maxFileSize
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*/
public function __construct(
string $fieldDefIdentifier,
int $minFileSize = 0,
?int $maxFileSize = null
$minFileSize = 0,
$maxFileSize = null
) {
if ($minFileSize > 0) {
$minFileSize *= 1024 * 1024;
Expand Down

0 comments on commit b171d78

Please sign in to comment.