-
Notifications
You must be signed in to change notification settings - Fork 6
IBX-7653: Add IsContainer criterion support #63
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
Merged
dew326
merged 10 commits into
4.6
from
IBX-7653-images-visible-in-tree-browser-in-image-picker
May 16, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4e5ba8c
IBX-7653: Add IsContainer criterion support
tischsoic 72273cb
fix
tischsoic 7c185c4
fix-cs
tischsoic 55b0819
phpstan
tischsoic b305fe7
after CR
tischsoic 7d7bae6
use toString helper
tischsoic fbdb898
Move duplicated code into one class
tischsoic 6cae83a
aftre huddle review - BaseIsContainer
tischsoic 6a5418f
declare(strict_types=1);
tischsoic 98eb4b6
add internal annotation
tischsoic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ibexa\Solr\Query\Common\CriterionVisitor; | ||
|
|
||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; | ||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Operator; | ||
| use Ibexa\Contracts\Solr\Query\CriterionVisitor; | ||
|
|
||
| /** | ||
| * @internal | ||
| */ | ||
| abstract class BaseIsContainer extends CriterionVisitor | ||
| { | ||
| abstract protected function getTargetField(): string; | ||
|
|
||
| public function canVisit(Criterion $criterion): bool | ||
| { | ||
| return $criterion instanceof Criterion\IsContainer && $criterion->operator === Operator::EQ; | ||
| } | ||
|
|
||
| public function visit(Criterion $criterion, CriterionVisitor $subVisitor = null): string | ||
| { | ||
| $value = $criterion->value; | ||
|
|
||
| if (!is_array($value) || !is_bool($value[0])) { | ||
| throw new \LogicException(sprintf( | ||
| '%s value should be of type array<bool>, received %s.', | ||
| Criterion\IsContainer::class, | ||
| get_debug_type($value), | ||
| )); | ||
| } | ||
|
|
||
| return $this->getTargetField() . ':' . $this->toString($value[0]); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ibexa\Solr\Query\Content\CriterionVisitor; | ||
|
|
||
| use Ibexa\Solr\Query\Common\CriterionVisitor\BaseIsContainer; | ||
|
|
||
| /** | ||
| * @internal | ||
| */ | ||
| final class IsContainer extends BaseIsContainer | ||
| { | ||
| public function getTargetField(): string | ||
| { | ||
| return 'content_type_is_container_b'; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ibexa\Solr\Query\Location\CriterionVisitor; | ||
|
|
||
| use Ibexa\Solr\Query\Common\CriterionVisitor\BaseIsContainer; | ||
|
|
||
| /** | ||
| * @internal | ||
| */ | ||
| final class IsContainer extends BaseIsContainer | ||
| { | ||
| public function getTargetField(): string | ||
| { | ||
| return 'is_container_b'; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is almost the same code as the
Content\CriterionVisitor. Consider extracting common code.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I have checked, we do not extract the common part (e.g.
LocationIdIn,LocationRemoteIdInetc.) so I didn't want to introduce another abstraction just forIsContainer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a technical debt that can be easily mitigated. Sonar Cloud analysis is valid.
My question here would be if this can be refactored into a common base for all visitors or just for IsContainer? The latter approach is a minimum requirement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say that extracting this code into an abstract is debatable in this case. Those classes share code, but are for different domains.
I would argue that a trait is a candidate, especially since there are valid cases where code related to checking value is different for a Criterion. We basically need to inject a validation method to ensure that argument passed is correct. This is a specific behavior that we need for a particular set of Criterions.
Thoughts?