Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-6937: Changed expected min and max value types to numeric instead of int #308

Merged
merged 3 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions phpstan-baseline-7.4.neon
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,12 @@ parameters:
path: src/lib/Search/Common/FieldNameResolver.php

-
message: "#^Parameter \\#1 \\$str of function trim expects string, int\\|string given\\.$#"
message: "#^Parameter \\#1 \\$str of function trim expects string, bool\\|float\\|int\\|string given\\.$#"
count: 1
path: src/lib/Search/Legacy/Content/Gateway/CriterionHandler/Ancestor.php

-
message: "#^Parameter \\#1 \\$str of function trim expects string, int\\|string given\\.$#"
message: "#^Parameter \\#1 \\$str of function trim expects string, bool\\|float\\|int\\|string given\\.$#"
count: 1
path: src/lib/Search/Legacy/Content/Location/Gateway/CriterionHandler/Ancestor.php

Expand Down
4 changes: 2 additions & 2 deletions phpstan-baseline-8.0.neon
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,12 @@ parameters:
path: src/lib/Search/Common/FieldNameResolver.php

-
message: "#^Parameter \\#1 \\$string of function trim expects string, int\\|string given\\.$#"
message: "#^Parameter \\#1 \\$string of function trim expects string, bool\\|float\\|int\\|string given\\.$#"
count: 1
path: src/lib/Search/Legacy/Content/Gateway/CriterionHandler/Ancestor.php

-
message: "#^Parameter \\#1 \\$string of function trim expects string, int\\|string given\\.$#"
message: "#^Parameter \\#1 \\$string of function trim expects string, bool\\|float\\|int\\|string given\\.$#"
count: 1
path: src/lib/Search/Legacy/Content/Location/Gateway/CriterionHandler/Ancestor.php

Expand Down
113 changes: 51 additions & 62 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

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,26 +60,27 @@ 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',
'Value should be grater or equal 0'
'Value should be greater or equal 0'
);
}

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

Expand All @@ -86,7 +90,7 @@ protected function validate(
) {
throw new InvalidArgumentException(
'$minValue',
'Value should be grater than' . $maxValue
'Value should be greater than' . $maxValue
);
}
}
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
Loading