Skip to content

Conversation

@mnocon
Copy link
Contributor

@mnocon mnocon commented Dec 10, 2024

Question Answer
JIRA Ticket N/A
Versions v5
Edition all

PHPStan is failing with:

  :13    Parameter #1 $criterion (Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion) of method App\Query\Criterion\Elasticsearch\CameraManufacturerVisitor::supports() is not contravariant with parameter #1 $criterion  
         (Ibexa\Contracts\Core\Repository\Values\Content\Query\CriterionInterface) of method Ibexa\Contracts\Elasticsearch\Query\CriterionVisitor::supports().                                                                         
  :18    Parameter #2 $criterion (Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion) of method App\Query\Criterion\Elasticsearch\CameraManufacturerVisitor::visit() is not contravariant with parameter #2 $criterion     
         (Ibexa\Contracts\Core\Repository\Values\Content\Query\CriterionInterface) of method Ibexa\Contracts\Elasticsearch\Query\CriterionVisitor::visit().                                                                            
 ------ -----

After the changes from ibexa/solr#80

Preview: https://ez-systems-developer-documentation--2576.com.readthedocs.build/en/2576/search/extensibility/create_custom_search_criterion/

The code samples bot detects changes, but the including files do not have to be adjusted.

Checklist

  • Text renders correctly
  • Text has been checked with vale
  • Description metadata is up to date
  • Redirects cover removed/moved pages
  • Code samples are working
  • PHP code samples have been fixed with PHP CS fixer
  • Added link to this PR in relevant JIRA ticket or code PR

@mnocon mnocon requested review from a team and ViniTou December 11, 2024 07:53
@mnocon mnocon marked this pull request as ready for review December 11, 2024 07:53
@konradoboza konradoboza requested a review from a team December 11, 2024 07:54
@github-actions
Copy link

code_samples/ change report

Before (on target branch)After (in current PR)

code_samples/search/elasticsearch/src/Query/Criterion/Elasticsearch/CameraManufacturerVisitor.php

docs/search/extensibility/create_custom_search_criterion.md@43: ``` php
docs/search/extensibility/create_custom_search_criterion.md@44: --8<--
docs/search/extensibility/create_custom_search_criterion.md@45: code_samples/search/elasticsearch/src/Query/Criterion/Elasticsearch/CameraManufacturerVisitor.php
docs/search/extensibility/create_custom_search_criterion.md@46: --8<--
docs/search/extensibility/create_custom_search_criterion.md@47: ```

001⫶<?php
002⫶
003⫶declare(strict_types=1);
004⫶
005⫶namespace App\Query\Criterion\Elasticsearch;
006⫶

code_samples/search/elasticsearch/src/Query/Criterion/Elasticsearch/CameraManufacturerVisitor.php

docs/search/extensibility/create_custom_search_criterion.md@43: ``` php
docs/search/extensibility/create_custom_search_criterion.md@44: --8<--
docs/search/extensibility/create_custom_search_criterion.md@45: code_samples/search/elasticsearch/src/Query/Criterion/Elasticsearch/CameraManufacturerVisitor.php
docs/search/extensibility/create_custom_search_criterion.md@46: --8<--
docs/search/extensibility/create_custom_search_criterion.md@47: ```

001⫶<?php
002⫶
003⫶declare(strict_types=1);
004⫶
005⫶namespace App\Query\Criterion\Elasticsearch;
006⫶
007⫶use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
007⫶use Ibexa\Contracts\Core\Repository\Values\Content\Query\CriterionInterface;
008⫶use Ibexa\Contracts\Elasticsearch\Query\CriterionVisitor;
009⫶use Ibexa\Contracts\Elasticsearch\Query\LanguageFilter;
010⫶
011⫶final class CameraManufacturerVisitor implements CriterionVisitor
012⫶{
008⫶use Ibexa\Contracts\Elasticsearch\Query\CriterionVisitor;
009⫶use Ibexa\Contracts\Elasticsearch\Query\LanguageFilter;
010⫶
011⫶final class CameraManufacturerVisitor implements CriterionVisitor
012⫶{
013⫶    public function supports(Criterion $criterion, LanguageFilter $languageFilter): bool
013⫶    public function supports(CriterionInterface $criterion, LanguageFilter $languageFilter): bool
014⫶    {
015⫶ return $criterion instanceof CameraManufacturerCriterion;
016⫶ }
017⫶
014⫶    {
015⫶ return $criterion instanceof CameraManufacturerCriterion;
016⫶ }
017⫶
018⫶    public function visit(CriterionVisitor $dispatcher, Criterion $criterion, LanguageFilter $languageFilter): array
019⫶ {
020⫶ return [
021⫶ 'terms' => [
022⫶ 'exif_camera_manufacturer_id' => (array)$criterion->value,
023⫶ ],
024⫶ ];
025⫶ }
026⫶}
018⫶    /**
019⫶ * @param \App\Query\Criterion\Elasticsearch\CameraManufacturerCriterion $criterion
020⫶ */
021⫶ public function visit(CriterionVisitor $dispatcher, CriterionInterface $criterion, LanguageFilter $languageFilter): array
022⫶ {
023⫶ return [
024⫶ 'terms' => [
025⫶ 'exif_camera_manufacturer_id' => (array)$criterion->value,
026⫶ ],
027⫶ ];
028⫶ }
029⫶}


code_samples/search/solr/src/Query/Criterion/Solr/CameraManufacturerVisitor.php

docs/search/extensibility/create_custom_search_criterion.md@35: ``` php
docs/search/extensibility/create_custom_search_criterion.md@36: --8<--
docs/search/extensibility/create_custom_search_criterion.md@37: code_samples/search/solr/src/Query/Criterion/Solr/CameraManufacturerVisitor.php
docs/search/extensibility/create_custom_search_criterion.md@38: --8<--
docs/search/extensibility/create_custom_search_criterion.md@39: ```

001⫶<?php
002⫶
003⫶declare(strict_types=1);
004⫶
005⫶namespace App\Query\Criterion\Solr;
006⫶


code_samples/search/solr/src/Query/Criterion/Solr/CameraManufacturerVisitor.php

docs/search/extensibility/create_custom_search_criterion.md@35: ``` php
docs/search/extensibility/create_custom_search_criterion.md@36: --8<--
docs/search/extensibility/create_custom_search_criterion.md@37: code_samples/search/solr/src/Query/Criterion/Solr/CameraManufacturerVisitor.php
docs/search/extensibility/create_custom_search_criterion.md@38: --8<--
docs/search/extensibility/create_custom_search_criterion.md@39: ```

001⫶<?php
002⫶
003⫶declare(strict_types=1);
004⫶
005⫶namespace App\Query\Criterion\Solr;
006⫶
007⫶use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
007⫶use Ibexa\Contracts\Core\Repository\Values\Content\Query\CriterionInterface;
008⫶use Ibexa\Contracts\Solr\Query\CriterionVisitor;
009⫶
010⫶final class CameraManufacturerVisitor extends CriterionVisitor
011⫶{
008⫶use Ibexa\Contracts\Solr\Query\CriterionVisitor;
009⫶
010⫶final class CameraManufacturerVisitor extends CriterionVisitor
011⫶{
012⫶    public function canVisit(Criterion $criterion)
012⫶    public function canVisit(CriterionInterface $criterion)
013⫶    {
014⫶ return $criterion instanceof CameraManufacturerCriterion;
015⫶ }
016⫶
013⫶    {
014⫶ return $criterion instanceof CameraManufacturerCriterion;
015⫶ }
016⫶
017⫶    public function visit(Criterion $criterion, CriterionVisitor $subVisitor = null)
018⫶ {
019⫶ $expressions = array_map(
020⫶ function ($value): string {
021⫶ return 'exif_camera_manufacturer_id:"' . $this->escapeQuote((string) $value) . '"';
022⫶ },
023⫶ $criterion->value
024⫶ );
025⫶
026⫶ return '(' . implode(' OR ', $expressions) . ')';
027⫶ }
028⫶}
017⫶    /**
018⫶ * @param \App\Query\Criterion\Solr\CameraManufacturerCriterion $criterion
019⫶ */
020⫶ public function visit(CriterionInterface $criterion, CriterionVisitor $subVisitor = null)
021⫶ {
022⫶ $expressions = array_map(
023⫶ function ($value): string {
024⫶ return 'exif_camera_manufacturer_id:"' . $this->escapeQuote((string) $value) . '"';
025⫶ },
026⫶ $criterion->value
027⫶ );
028⫶
029⫶ return '(' . implode(' OR ', $expressions) . ')';
030⫶ }
031⫶}


Download colorized diff

Copy link
Contributor

@adriendupuis adriendupuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Way more elegant than what I tried in #2577

@mnocon mnocon merged commit e9b50b8 into master Dec 12, 2024
6 checks passed
@mnocon mnocon deleted the fix-phpstan branch December 12, 2024 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants