Skip to content

Commit 8282ee4

Browse files
committed
IBX-10458: Applied review remarks
1 parent 2d97bdf commit 8282ee4

File tree

22 files changed

+198
-127
lines changed

22 files changed

+198
-127
lines changed
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
*/
77
declare(strict_types=1);
88

9-
namespace Ibexa\Contracts\Core\Repository\Values\ContentType\Query;
9+
namespace Ibexa\Contracts\Core\Persistence\Content\Type;
1010

1111
use Doctrine\DBAL\Query\QueryBuilder;
12+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\CriterionInterface;
1213
use Ibexa\Core\Persistence\Legacy\Content\Type\Gateway\CriterionVisitor\CriterionVisitor;
1314

1415
/**
@@ -17,12 +18,12 @@
1718
interface CriterionHandlerInterface
1819
{
1920
/**
20-
* @param T $criterion
21+
* @param \Ibexa\Contracts\Core\Repository\Values\ContentType\Query\CriterionInterface $criterion
2122
*/
2223
public function supports(CriterionInterface $criterion): bool;
2324

2425
/**
25-
* @param T $criterion
26+
* @param \Ibexa\Contracts\Core\Repository\Values\ContentType\Query\CriterionInterface $criterion
2627
*
2728
* @return string|\Doctrine\DBAL\Query\Expression\CompositeExpression
2829
*/

src/contracts/Repository/Values/ContentType/Query/ContentTypeQuery.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
final class ContentTypeQuery
1212
{
13+
public const DEFAULT_LIMIT = 25;
14+
1315
private ?CriterionInterface $criterion;
1416

1517
/** @var \Ibexa\Contracts\Core\Repository\Values\ContentType\Query\SortClause[] */
@@ -26,7 +28,7 @@ public function __construct(
2628
?CriterionInterface $criterion = null,
2729
array $sortClauses = [],
2830
int $offset = 0,
29-
int $limit = 25
31+
int $limit = self::DEFAULT_LIMIT
3032
) {
3133
$this->criterion = $criterion;
3234
$this->sortClauses = $sortClauses;

src/contracts/Repository/Values/ContentType/Query/Criterion/ContentTypeGroupIds.php renamed to src/contracts/Repository/Values/ContentType/Query/Criterion/ContainsFieldDefinitionId.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@
1010

1111
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\CriterionInterface;
1212

13-
final class ContentTypeGroupIds implements CriterionInterface
13+
final class ContainsFieldDefinitionId implements CriterionInterface
1414
{
15-
/** @var list<int> */
16-
private array $value;
15+
/** @var list<int>|int */
16+
private $value;
1717

1818
/**
19-
* @param list<int> $value
19+
* @param list<int>|int $value
2020
*/
21-
public function __construct(array $value)
21+
public function __construct($value)
2222
{
2323
$this->value = $value;
2424
}
2525

2626
/**
27-
* @return list<int>
27+
* @return list<int>|int
2828
*/
29-
public function getValue(): array
29+
public function getValue()
3030
{
3131
return $this->value;
3232
}
3333

3434
/**
35-
* @param list<int> $value
35+
* @param list<int>|int $value
3636
*/
37-
public function setValue(array $value): void
37+
public function setValue($value): void
3838
{
3939
$this->value = $value;
4040
}

src/contracts/Repository/Values/ContentType/Query/Criterion/Identifiers.php renamed to src/contracts/Repository/Values/ContentType/Query/Criterion/ContentTypeGroupId.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@
1010

1111
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\CriterionInterface;
1212

13-
final class Identifiers implements CriterionInterface
13+
final class ContentTypeGroupId implements CriterionInterface
1414
{
15-
/** @var list<string> */
16-
private array $value;
15+
/** @var list<int>|int */
16+
private $value;
1717

1818
/**
19-
* @param list<string> $value
19+
* @param list<int>|int $value
2020
*/
21-
public function __construct(array $value)
21+
public function __construct($value)
2222
{
2323
$this->value = $value;
2424
}
2525

2626
/**
27-
* @return list<string>
27+
* @return list<int>|int
2828
*/
29-
public function getValue(): array
29+
public function getValue()
3030
{
3131
return $this->value;
3232
}
3333

3434
/**
35-
* @param list<string> $value
35+
* @param list<int>|int $value
3636
*/
37-
public function setValue(array $value): void
37+
public function setValue($value): void
3838
{
3939
$this->value = $value;
4040
}

src/contracts/Repository/Values/ContentType/Query/Criterion/Ids.php renamed to src/contracts/Repository/Values/ContentType/Query/Criterion/ContentTypeId.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@
1010

1111
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\CriterionInterface;
1212

13-
final class Ids implements CriterionInterface
13+
final class ContentTypeId implements CriterionInterface
1414
{
15-
/** @var list<int> */
16-
private array $value;
15+
/** @var list<int>|int */
16+
private $value;
1717

1818
/**
19-
* @param list<int> $value
19+
* @param list<int>|int $value
2020
*/
21-
public function __construct(array $value)
21+
public function __construct($value)
2222
{
2323
$this->value = $value;
2424
}
2525

2626
/**
27-
* @return list<int>
27+
* @return list<int>|int
2828
*/
29-
public function getValue(): array
29+
public function getValue()
3030
{
3131
return $this->value;
3232
}
3333

3434
/**
35-
* @param list<int> $value
35+
* @param list<int>|int $value
3636
*/
37-
public function setValue(array $value): void
37+
public function setValue($value): void
3838
{
3939
$this->value = $value;
4040
}
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@
1010

1111
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\CriterionInterface;
1212

13-
final class ContainsFieldDefinitionIds implements CriterionInterface
13+
final class ContentTypeIdentifier implements CriterionInterface
1414
{
15-
/** @var list<int> */
16-
private array $value;
15+
/** @var list<string>|string */
16+
private $value;
1717

1818
/**
19-
* @param list<int> $value
19+
* @param list<string>|string $value
2020
*/
21-
public function __construct(array $value)
21+
public function __construct($value)
2222
{
2323
$this->value = $value;
2424
}
2525

2626
/**
27-
* @return list<int>
27+
* @return list<string>|string
2828
*/
29-
public function getValue(): array
29+
public function getValue()
3030
{
3131
return $this->value;
3232
}
3333

3434
/**
35-
* @param list<int> $value
35+
* @param list<string>|string $value
3636
*/
37-
public function setValue(array $value): void
37+
public function setValue($value): void
3838
{
3939
$this->value = $value;
4040
}

src/contracts/Repository/Values/ContentType/Query/Criterion/IsSystem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class IsSystem implements CriterionInterface
1414
{
1515
private bool $value;
1616

17-
public function __construct(bool $value)
17+
public function __construct(bool $value = true)
1818
{
1919
$this->value = $value;
2020
}

src/contracts/Repository/Values/ContentType/SearchResult.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,23 @@
1818
*/
1919
final class SearchResult extends ValueObject implements IteratorAggregate
2020
{
21-
public int $totalCount = 0;
21+
protected int $totalCount = 0;
22+
23+
/** @var array<int, \Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType> */
24+
protected array $items = [];
25+
26+
public function getTotalCount(): int
27+
{
28+
return $this->totalCount;
29+
}
2230

2331
/**
24-
* @var array<int, \Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType>
32+
* @return array<int, \Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType>
2533
*/
26-
public array $items = [];
34+
public function getContentTypes(): array
35+
{
36+
return $this->items;
37+
}
2738

2839
/**
2940
* @return \Traversable<int, \Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType>
Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,22 @@
99
namespace Ibexa\Core\Persistence\Legacy\Content\Type\Gateway\CriterionHandler;
1010

1111
use Doctrine\DBAL\Connection;
12+
use Doctrine\DBAL\ParameterType;
1213
use Doctrine\DBAL\Query\QueryBuilder;
13-
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Base;
14-
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContainsFieldDefinitionIds as ContainsFieldDefinitionIdsCriterion;
14+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContainsFieldDefinitionId as ContainsFieldDefinitionIdCriterion;
1515
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\CriterionInterface;
1616
use Ibexa\Core\Persistence\Legacy\Content\Type\Gateway\CriterionVisitor\CriterionVisitor;
17+
use Ibexa\Core\Repository\Values\ContentType\Query\Base;
1718

18-
final class ContainsFieldDefinitionIds extends Base
19+
final class ContainsFieldDefinitionId extends Base
1920
{
2021
public function supports(CriterionInterface $criterion): bool
2122
{
22-
return $criterion instanceof ContainsFieldDefinitionIdsCriterion;
23+
return $criterion instanceof ContainsFieldDefinitionIdCriterion;
2324
}
2425

2526
/**
26-
* @param \Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContainsFieldDefinitionIds $criterion
27+
* @param \Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContainsFieldDefinitionId $criterion
2728
*/
2829
public function apply(
2930
CriterionVisitor $criterionVisitor,
@@ -32,9 +33,17 @@ public function apply(
3233
): string {
3334
$this->joinFieldDefinitions($qb);
3435

35-
return $qb->expr()->in(
36+
$value = $criterion->getValue();
37+
if (is_array($value)) {
38+
return $qb->expr()->in(
39+
'a.id',
40+
$qb->createNamedParameter($criterion->getValue(), Connection::PARAM_INT_ARRAY)
41+
);
42+
}
43+
44+
return $qb->expr()->eq(
3645
'a.id',
37-
$qb->createNamedParameter($criterion->getValue(), Connection::PARAM_INT_ARRAY)
46+
$qb->createNamedParameter($criterion->getValue(), ParameterType::INTEGER)
3847
);
3948
}
4049
}
Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,22 @@
99
namespace Ibexa\Core\Persistence\Legacy\Content\Type\Gateway\CriterionHandler;
1010

1111
use Doctrine\DBAL\Connection;
12+
use Doctrine\DBAL\ParameterType;
1213
use Doctrine\DBAL\Query\QueryBuilder;
13-
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Base;
14-
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContentTypeGroupIds as ContentTypeGroupIdsCriterion;
14+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContentTypeGroupId as ContentTypeGroupIdCriterion;
1515
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\CriterionInterface;
1616
use Ibexa\Core\Persistence\Legacy\Content\Type\Gateway\CriterionVisitor\CriterionVisitor;
17+
use Ibexa\Core\Repository\Values\ContentType\Query\Base;
1718

18-
final class ContentTypeGroupIds extends Base
19+
final class ContentTypeGroupId extends Base
1920
{
2021
public function supports(CriterionInterface $criterion): bool
2122
{
22-
return $criterion instanceof ContentTypeGroupIdsCriterion;
23+
return $criterion instanceof ContentTypeGroupIdCriterion;
2324
}
2425

2526
/**
26-
* @param \Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContentTypeGroupIds $criterion
27+
* @param \Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContentTypeGroupId $criterion
2728
*/
2829
public function apply(
2930
CriterionVisitor $criterionVisitor,
@@ -32,9 +33,17 @@ public function apply(
3233
): string {
3334
$this->joinContentTypeGroupAssignmentTable($qb);
3435

35-
return $qb->expr()->in(
36+
$value = $criterion->getValue();
37+
if (is_array($value)) {
38+
return $qb->expr()->in(
39+
'g.group_id',
40+
$qb->createNamedParameter($criterion->getValue(), Connection::PARAM_INT_ARRAY)
41+
);
42+
}
43+
44+
return $qb->expr()->eq(
3645
'g.group_id',
37-
$qb->createNamedParameter($criterion->getValue(), Connection::PARAM_INT_ARRAY)
46+
$qb->createNamedParameter($criterion->getValue(), ParameterType::INTEGER)
3847
);
3948
}
4049
}

0 commit comments

Comments
 (0)