Skip to content

Commit

Permalink
Unified Image Criteria argument names
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Jan 18, 2024
1 parent 273aa8c commit 0cab2ff
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
30 changes: 15 additions & 15 deletions src/contracts/Repository/Values/Content/Query/Criterion/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;

use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Image\AbstractImageCompositeCriterion;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Image\FileSize;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Image\Height;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Image\MimeType;
Expand All @@ -28,7 +28,7 @@
*
* @template-extends \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Image\AbstractImageCompositeCriterion<ImageCriteria>
*/
final class Image extends Criterion\Image\AbstractImageCompositeCriterion
final class Image extends AbstractImageCompositeCriterion
{
public const IMAGE_SEARCH_CRITERIA = [
'mimeTypes',
Expand All @@ -44,56 +44,56 @@ protected function getSupportedCriteria(): array
}

/**
* @phpstan-param ImageCriteria $data
* @phpstan-param ImageCriteria $imageCriteriaData
*
* @return array<\Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion>
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*/
protected function buildCriteria(
string $fieldDefIdentifier,
array $data
array $imageCriteriaData
): array {
$criteria = [];
$critqeria = [];

if (isset($data['mimeTypes'])) {
if (isset($imageCriteriaData['mimeTypes'])) {
$criteria[] = new MimeType(
$fieldDefIdentifier,
$data['mimeTypes']
$imageCriteriaData['mimeTypes']
);
}

if (isset($data['size'])) {
$size = $data['size'];
if (isset($imageCriteriaData['size'])) {
$size = $imageCriteriaData['size'];
$criteria[] = new FileSize(
$fieldDefIdentifier,
$this->getMinValue($size),
$this->getMaxValue($size),
);
}

if (isset($data['width'])) {
$width = $data['width'];
if (isset($imageCriteriaData['width'])) {
$width = $imageCriteriaData['width'];
$criteria[] = new Width(
$fieldDefIdentifier,
$this->getMinValue($width),
$this->getMaxValue($width)
);
}

if (isset($data['height'])) {
$height = $data['height'];
if (isset($imageCriteriaData['height'])) {
$height = $imageCriteriaData['height'];
$criteria[] = new Height(
$fieldDefIdentifier,
$this->getMinValue($height),
$this->getMaxValue($height)
);
}

if (isset($data['orientation'])) {
if (isset($imageCriteriaData['orientation'])) {
$criteria[] = new Orientation(
$fieldDefIdentifier,
$data['orientation']
$imageCriteriaData['orientation']
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,47 @@
abstract class AbstractImageCompositeCriterion extends CompositeCriterion
{
/**
* @phpstan-param TImageCriteria $data
* @phpstan-param TImageCriteria $imageCriteriaData
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*/
public function __construct(
string $fieldDefIdentifier,
array $data
array $imageCriteriaData
) {
$this->validate($data, $this->getSupportedCriteria());
$this->validate($imageCriteriaData, $this->getSupportedCriteria());

$criteria = new Criterion\LogicalAnd(
$this->buildCriteria($fieldDefIdentifier, $data)
$this->buildCriteria($fieldDefIdentifier, $imageCriteriaData)
);

parent::__construct($criteria);
}

/**
* @phpstan-param TImageCriteria $data
* @phpstan-param TImageCriteria $imageCriteriaData
*
* @return array<\Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion>
*/
abstract protected function buildCriteria(string $fieldDefIdentifier, array $data): array;
abstract protected function buildCriteria(string $fieldDefIdentifier, array $imageCriteriaData): array;

/**
* @return array<string>
*/
abstract protected function getSupportedCriteria(): array;

/**
* @phpstan-param TImageCriteria $data
* @phpstan-param TImageCriteria $imageCriteriaData
*
* @param array<string> $supportedCriteria
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*/
protected function validate(
array $data,
array $imageCriteriaData,
array $supportedCriteria
): void {
if (empty($data)) {
if (empty($imageCriteriaData)) {
throw new InvalidArgumentException(
'$data',
sprintf(
Expand All @@ -74,7 +74,7 @@ protected function validate(
}

$notSupportedCriteria = array_diff(
array_keys($data),
array_keys($imageCriteriaData),
$supportedCriteria
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,29 @@ protected function getSupportedCriteria(): array
}

/**
* @phpstan-param ImageCriteria $data
* @phpstan-param ImageCriteria $imageCriteriaData
*
* @return array<\Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion>
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*/
protected function buildCriteria(
string $fieldDefIdentifier,
array $data
array $imageCriteriaData
): array {
$criteria = [];

if (isset($data['width'])) {
$width = $data['width'];
if (isset($imageCriteriaData['width'])) {
$width = $imageCriteriaData['width'];
$criteria[] = new Width(
$fieldDefIdentifier,
$this->getMinValue($width),
$this->getMaxValue($width)
);
}

if (isset($data['height'])) {
$height = $data['height'];
if (isset($imageCriteriaData['height'])) {
$height = $imageCriteriaData['height'];
$criteria[] = new Height(
$fieldDefIdentifier,
$this->getMinValue($height),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@
final class FileSize extends AbstractImageRangeCriterion
{
/**
* @param numeric $minFileSize
* @param numeric|null $maxFileSize
* @param numeric $minValue
* @param numeric|null $maxValue
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*/
public function __construct(
string $fieldDefIdentifier,
$minFileSize = 0,
$maxFileSize = null
$minValue = 0,
$maxValue = null
) {
if ($minFileSize > 0) {
$minFileSize *= 1024 * 1024;
if ($minValue > 0) {
$minValue *= 1024 * 1024;
}

if ($maxFileSize > 0) {
$maxFileSize *= 1024 * 1024;
if ($maxValue > 0) {
$maxValue *= 1024 * 1024;
}

parent::__construct(
$fieldDefIdentifier,
$minFileSize,
$maxFileSize
$minValue,
$maxValue
);
}
}

0 comments on commit 0cab2ff

Please sign in to comment.