diff --git a/code_samples/search/elasticsearch/src/Query/Criterion/Elasticsearch/CameraManufacturerVisitor.php b/code_samples/search/elasticsearch/src/Query/Criterion/Elasticsearch/CameraManufacturerVisitor.php index 62e4d4f495..38f7025c41 100644 --- a/code_samples/search/elasticsearch/src/Query/Criterion/Elasticsearch/CameraManufacturerVisitor.php +++ b/code_samples/search/elasticsearch/src/Query/Criterion/Elasticsearch/CameraManufacturerVisitor.php @@ -4,22 +4,23 @@ namespace App\Query\Criterion\Elasticsearch; -use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; +use Ibexa\Contracts\Core\Repository\Values\Content\Query\CriterionInterface; use Ibexa\Contracts\Elasticsearch\Query\CriterionVisitor; use Ibexa\Contracts\Elasticsearch\Query\LanguageFilter; final class CameraManufacturerVisitor implements CriterionVisitor { - public function supports(Criterion $criterion, LanguageFilter $languageFilter): bool + public function supports(CriterionInterface $criterion, LanguageFilter $languageFilter): bool { return $criterion instanceof CameraManufacturerCriterion; } - public function visit(CriterionVisitor $dispatcher, Criterion $criterion, LanguageFilter $languageFilter): array + public function visit(CriterionVisitor $dispatcher, CriterionInterface $criterion, LanguageFilter $languageFilter): array { + /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion $criterion */ return [ 'terms' => [ - 'exif_camera_manufacturer_id' => (array)$criterion->value, + 'exif_camera_manufacturer_id' => property_exists($criterion, 'value') ? (array)$criterion->value : [], ], ]; } diff --git a/code_samples/search/solr/src/Query/Criterion/Solr/CameraManufacturerVisitor.php b/code_samples/search/solr/src/Query/Criterion/Solr/CameraManufacturerVisitor.php index c5ae4bacfd..8d0cb4d5d1 100644 --- a/code_samples/search/solr/src/Query/Criterion/Solr/CameraManufacturerVisitor.php +++ b/code_samples/search/solr/src/Query/Criterion/Solr/CameraManufacturerVisitor.php @@ -4,23 +4,24 @@ namespace App\Query\Criterion\Solr; -use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; +use Ibexa\Contracts\Core\Repository\Values\Content\Query\CriterionInterface; use Ibexa\Contracts\Solr\Query\CriterionVisitor; final class CameraManufacturerVisitor extends CriterionVisitor { - public function canVisit(Criterion $criterion) + public function canVisit(CriterionInterface $criterion) { return $criterion instanceof CameraManufacturerCriterion; } - public function visit(Criterion $criterion, CriterionVisitor $subVisitor = null) + public function visit(CriterionInterface $criterion, CriterionVisitor $subVisitor = null) { + /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion $criterion */ $expressions = array_map( function ($value): string { return 'exif_camera_manufacturer_id:"' . $this->escapeQuote((string) $value) . '"'; }, - $criterion->value + property_exists($criterion, 'value') ? (array)$criterion->value : [] ); return '(' . implode(' OR ', $expressions) . ')'; diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 6c7781a0be..d4286b0c69 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -390,11 +390,6 @@ parameters: count: 1 path: code_samples/search/solr/src/Query/Aggregation/Solr/PriorityRangeAggregationVisitor.php - - - message: "#^Parameter \\#2 \\$array of function array_map expects array, array\\\\|bool\\|float\\|int\\|string given\\.$#" - count: 1 - path: code_samples/search/solr/src/Query/Criterion/Solr/CameraManufacturerVisitor.php - - message: "#^Call to an undefined method Ibexa\\\\FieldTypePage\\\\FieldType\\\\Page\\\\Block\\\\Renderer\\\\RenderRequestInterface\\:\\:getParameters\\(\\)\\.$#" count: 1 diff --git a/tools/code_samples/code_samples_usage.php b/tools/code_samples/code_samples_usage.php index e1844fdcec..66cd8a1ebe 100644 --- a/tools/code_samples/code_samples_usage.php +++ b/tools/code_samples/code_samples_usage.php @@ -133,7 +133,8 @@ function getBlockContents(array $block): array $rawBlockCodeLines = []; $oneBasedBlockCodeLines = []; $includedFilesLines = []; - foreach ($block as $blockSourceLine) { + $skip = false; + foreach ($block as $blockSourceLineIndex => $blockSourceLine) { if (preg_match('@```.* hl_lines="([^"]+)"@', $blockSourceLine, $matches)) { $rawHighlightedLines = explode(' ', $matches[1]); foreach ($rawHighlightedLines as $rawHighlightedLine) { @@ -171,7 +172,17 @@ function getBlockContents(array $block): array $solvedLine = str_replace($matchString, implode(PHP_EOL . $matches['glue'][$matchIndex], $sample) . PHP_EOL, $solvedLine); } $rawBlockCodeLines = array_merge($rawBlockCodeLines, explode(PHP_EOL, $solvedLine)); - } elseif (!str_contains($blockSourceLine, '```')) { + } elseif (str_contains($blockSourceLine, '--8<--')) { + if (!$skip) { + $includedFilePath = trim($block[$blockSourceLineIndex+1]); + $includedFilesLines[$includedFilePath] = file($includedFilePath, FILE_IGNORE_NEW_LINES); + if (!is_array($includedFilesLines[$includedFilePath])) { + throw new RuntimeException("The following included file can't be opened: $includedFilePath"); + } + $rawBlockCodeLines = array_merge($rawBlockCodeLines, $includedFilesLines[$includedFilePath]); + } + $skip = !$skip; + } elseif (!str_contains($blockSourceLine, '```') && !$skip) { $rawBlockCodeLines[] = $blockSourceLine; } }