Skip to content

Commit

Permalink
NGSTACK-843 php-cs-fixer apply rules from site api and run on edited …
Browse files Browse the repository at this point in the history
…files
  • Loading branch information
Katarina Miočić committed May 10, 2024
1 parent f7258c9 commit e5248c7
Show file tree
Hide file tree
Showing 28 changed files with 214 additions and 195 deletions.
10 changes: 6 additions & 4 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@
'method_chaining_indentation' => false,
'multiline_whitespace_before_semicolons' => false,
'native_function_invocation' => ['include' => ['@all']],
'no_superfluous_phpdoc_tags' => false,
'no_superfluous_phpdoc_tags' => true,
'no_unset_on_property' => false,
'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'],
'php_unit_internal_class' => false,
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
'php_unit_test_class_requires_covers' => false,
'phpdoc_align' => false,
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'phpdoc_no_alias_tag' => ['replacements' => ['type' => 'var', 'link' => 'see']],
'single_line_comment_style' => false,
'trailing_comma_in_multiline' => ['elements' => ['arrays', 'arguments']],
'trailing_comma_in_multiline' => ['elements' => ['arrays', 'arguments', 'match', 'parameters']],
'yoda_style' => false,
'php_unit_strict' => false,
'php_unit_test_annotation' => false,
Expand All @@ -50,7 +51,8 @@
'static_lambda' => true,
'ternary_to_null_coalescing' => true,
'use_arrow_functions' => true,
])
'no_alias_language_construct_call' => true,
])
->setRiskyAllowed(true)
->setFinder($finder)
;
;
22 changes: 13 additions & 9 deletions bundle/Command/IndexPageContentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

use Ibexa\Contracts\Core\Persistence\Handler as PersistenceHandler;
use Ibexa\Contracts\Core\Repository\ContentService;
use Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException;
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
use Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException;
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentList;
use Ibexa\Contracts\Core\Repository\Values\Content\Query;
use Ibexa\Contracts\Core\Repository\Values\Filter\Filter;
use Ibexa\Contracts\Core\Search\Handler as SearchHandler;
Expand All @@ -16,9 +20,8 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentList;

use Symfony\Component\Console\Style\SymfonyStyle;

use function count;
use function explode;

Expand Down Expand Up @@ -57,14 +60,14 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
}

/**
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
* @throws NotFoundException
* @throws InvalidArgumentException
* @throws UnauthorizedException
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
foreach ($this->sitesConfig as $site => $siteConfig) {
$this->style->info("Indexing for site " . $site);
$this->style->info('Indexing for site ' . $site);
$this->indexContent($output, $input, $siteConfig);
}

Expand Down Expand Up @@ -103,11 +106,10 @@ private function indexContent(OutputInterface $output, InputInterface $input, ar

$output->writeln('');
$this->style->info('Finished.');

}

/**
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
* @throws InvalidArgumentException
*/
private function getTotalCount(array $allowedContentTypes, array $contentIds): int
{
Expand All @@ -121,7 +123,7 @@ private function getTotalCount(array $allowedContentTypes, array $contentIds): i
}

/**
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
* @throws InvalidArgumentException
*/
private function getChunk(int $limit, int $offset, array $allowedContentTypes, array $contentIds): ContentList
{
Expand All @@ -130,6 +132,7 @@ private function getChunk(int $limit, int $offset, array $allowedContentTypes, a
->withLimit($limit)
->withOffset($offset)
;

return $this->contentService->find($filter);
}

Expand All @@ -141,6 +144,7 @@ private function getFilter(array $allowedContentTypes, array $contentIds = []):
if (count($contentIds) > 0) {
$filter->andWithCriterion(new Query\Criterion\ContentId($contentIds));
}

return $filter;
}

Expand Down
7 changes: 5 additions & 2 deletions bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

use function array_keys;
use function is_string;

class Configuration implements ConfigurationInterface
{
protected string $rootNodeName;
Expand Down Expand Up @@ -83,6 +86,7 @@ private function addPageIndexingSection(ArrayNodeDefinition $nodeDefinition): vo
return true;
}
}

return false;
};
$nodeDefinition
Expand All @@ -106,7 +110,7 @@ private function addPageIndexingSection(ArrayNodeDefinition $nodeDefinition): vo
->children()
->integerNode('tree_root_location_id')
->info('Site root Location ID')
->beforeNormalization()->always(static fn ($v) => is_string($v) ? (int)$v : $v)->end()
->beforeNormalization()->always(static fn ($v) => is_string($v) ? (int) $v : $v)->end()
->end()
->arrayNode('languages_siteaccess_map')
->info('Language code mapped to page siteaccess')
Expand Down Expand Up @@ -163,5 +167,4 @@ private function addPageIndexingSection(ArrayNodeDefinition $nodeDefinition): vo
->end()
->end();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

use Symfony\Component\Yaml\Yaml;

use function array_key_exists;
use function file_get_contents;

class NetgenIbexaSearchExtraExtension extends Extension implements PrependExtensionInterface
{
Expand All @@ -21,8 +22,9 @@ class NetgenIbexaSearchExtraExtension extends Extension implements PrependExtens
'languages_siteaccess_map' => [],
'host' => null,
'fields' => [],
'allowed_content_types' => []
'allowed_content_types' => [],
];

public function getAlias(): string
{
return 'netgen_ibexa_search_extra';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
namespace Netgen\IbexaSearchExtra\Container\Compiler;

use Ibexa\Contracts\Core\Persistence\Content\Handler;
use Ibexa\Elasticsearch\DocumentMapper\DocumentFactoryInterface;
use Netgen\IbexaSearchExtra\Core\Search\Elasticsearch\DocumentMapper\DocumentFactory;
use Netgen\IbexaSearchExtra\Core\Search\Elasticsearch\Query\CriterionVisitor\Content\VisibilityVisitor as ContentVisibilityVisitor;
use Netgen\IbexaSearchExtra\Core\Search\Elasticsearch\Query\CriterionVisitor\Location\VisibilityVisitor as LocationVisibilityVisitor;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Ibexa\Elasticsearch\DocumentMapper\DocumentFactoryInterface;

use function array_keys;
use function sprintf;

/**
* This compiler pass will register elastic search field mappers.
Expand All @@ -40,6 +42,23 @@ public function process(ContainerBuilder $container): void
->addTag('ibexa.search.elasticsearch.query.location.criterion.visitor');
}

public function processDocumentFactory(ContainerBuilder $container): void
{
$container
->register(DocumentFactory::class, DocumentFactory::class)
->setDecoratedService(DocumentFactoryInterface::class)
->setArguments([
new Reference('.inner'),
new Reference(Handler::class),
new Reference('netgen.ibexa_search_extra.elasticsearch.field_mapper.content.aggregate'),
new Reference('netgen.ibexa_search_extra.elasticsearch.field_mapper.location.aggregate'),
new Reference('netgen.ibexa_search_extra.elasticsearch.field_mapper.content_translation.aggregate'),
new Reference('netgen.ibexa_search_extra.elasticsearch.field_mapper.location_translation.aggregate'),
new Reference('netgen.ibexa_search_extra.elasticsearch.field_mapper.block.aggregate'),
new Reference('netgen.ibexa_search_extra.elasticsearch.field_mapper.block_translation.aggregate'),
]);
}

private function processVisitors(ContainerBuilder $container, string $name): void
{
if (!$container->hasDefinition(sprintf('netgen.ibexa_search_extra.elasticsearch.field_mapper.%s.aggregate', $name))) {
Expand All @@ -59,25 +78,4 @@ private function registerMappers(Definition $definition, array $mapperIds): void
$definition->addMethodCall('addMapper', [new Reference($id)]);
}
}

/**
* @param ContainerBuilder $container
* @return void
*/
public function processDocumentFactory(ContainerBuilder $container): void
{
$container
->register(DocumentFactory::class, DocumentFactory::class)
->setDecoratedService(DocumentFactoryInterface::class)
->setArguments([
new Reference('.inner'),
new Reference(Handler::class),
new Reference('netgen.ibexa_search_extra.elasticsearch.field_mapper.content.aggregate'),
new Reference('netgen.ibexa_search_extra.elasticsearch.field_mapper.location.aggregate'),
new Reference('netgen.ibexa_search_extra.elasticsearch.field_mapper.content_translation.aggregate'),
new Reference('netgen.ibexa_search_extra.elasticsearch.field_mapper.location_translation.aggregate'),
new Reference('netgen.ibexa_search_extra.elasticsearch.field_mapper.block.aggregate'),
new Reference('netgen.ibexa_search_extra.elasticsearch.field_mapper.block_translation.aggregate'),
]);
}
}
5 changes: 2 additions & 3 deletions lib/Container/Compiler/PageIndexingPass.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
<?php

declare(strict_types=1);

namespace Netgen\IbexaSearchExtra\Container\Compiler;

use Netgen\IbexaSearchExtra\Core\Search\Solr\FieldMapper\ContentTranslation\ContentPageTextFieldMapper;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Ibexa\Elasticsearch\DocumentMapper\DocumentFactoryInterface;


class PageIndexingPass implements CompilerPassInterface
{

public function process(ContainerBuilder $container)
{
$usePageIndexing = $container->getParameter(
Expand Down
3 changes: 2 additions & 1 deletion lib/Core/Search/Common/PageTextExtractor.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

declare(strict_types=1);

namespace Netgen\IbexaSearchExtra\Core\Search\Common;

abstract class PageTextExtractor
{
abstract public function extractPageText(int $contentId, string $languageCode);

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Ibexa\Contracts\Core\Persistence\Content\Handler as ContentHandler;
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
use Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException;
use Netgen\IbexaSearchExtra\Core\Search\Common\PageTextExtractor;
use Netgen\IbexaSearchExtra\Core\Search\Common\SiteConfigResolver;
use Netgen\IbexaSearchExtra\Exception\IndexPageUnavailableException;
use Psr\Log\LoggerInterface;
Expand All @@ -18,6 +19,7 @@
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RouterInterface;

use function count;
use function explode;
use function in_array;
Expand All @@ -27,11 +29,12 @@
use function mb_substr;
use function sprintf;
use function trim;

use const XML_ELEMENT_NODE;
use const XML_HTML_DOCUMENT_NODE;
use const XML_TEXT_NODE;

class NativePageTextExtractor extends \Netgen\IbexaSearchExtra\Core\Search\Common\PageTextExtractor
class NativePageTextExtractor extends PageTextExtractor
{
/** @var array<int, array<string, array<string, array<int, string>|string>>> */
private array $cache = [];
Expand All @@ -41,7 +44,7 @@ class NativePageTextExtractor extends \Netgen\IbexaSearchExtra\Core\Search\Commo
public function __construct(
private readonly ContentHandler $contentHandler,
private readonly RouterInterface $router,
private readonly SiteConfigResolver $siteConfigResolver
private readonly SiteConfigResolver $siteConfigResolver,
) {
$this->logger = new NullLogger();
}
Expand All @@ -52,9 +55,6 @@ public function setLogger(LoggerInterface $logger): void
}

/**
* @param int $contentId
* @param string $languageCode
*
* @return array<string, array<int, string>|string>
*/
public function extractPageText(int $contentId, string $languageCode): array
Expand Down Expand Up @@ -85,12 +85,7 @@ public function extractPageText(int $contentId, string $languageCode): array
}

/**
* @param string $languageCode
* @param int $contentId
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
*
* @return string
* @throws NotFoundException
*/
private function generateUrl(string $languageCode, int $contentId, array $siteConfig): string
{
Expand Down Expand Up @@ -118,7 +113,6 @@ private function generateUrl(string $languageCode, int $contentId, array $siteCo
],
UrlGeneratorInterface::ABSOLUTE_URL,
);

}

private function resolveSiteAccess(ContentInfo $contentInfo, string $languageCode): string
Expand All @@ -128,18 +122,16 @@ private function resolveSiteAccess(ContentInfo $contentInfo, string $languageCod
if (!isset($siteConfig['languages_siteaccess_map'][$languageCode])) {
throw new RuntimeException(
sprintf(
"Language not supported for matched siteaccess group %s",
$siteConfig['site']
)
'Language not supported for matched siteaccess group %s',
$siteConfig['site'],
),
);
}

return $siteConfig['languages_siteaccess_map'][$languageCode];

}

/**
* @param \DOMNode $node
* @param array<string, array<int, string>> $textArray
*
* @return array<string, array<int, string>>
Expand All @@ -158,7 +150,6 @@ private function recursiveExtractTextArray(DOMNode $node, array &$textArray, int
foreach ($node->childNodes as $childNode) {
$this->recursiveExtractTextArray($childNode, $textArray, $contentId);
}

}
if ($node->nodeType === XML_TEXT_NODE) {
$textContent = trim($node->textContent);
Expand Down Expand Up @@ -207,7 +198,7 @@ private function hasClass(DOMNode $node, string $className): bool
/**
* @throws NotFoundException
* @throws UnauthorizedException
* @throws \RuntimeException
* @throws RuntimeException
*/
private function fetchPageSource(int $contentId, string $languageCode, array $siteConfig): string
{
Expand All @@ -218,7 +209,7 @@ private function fetchPageSource(int $contentId, string $languageCode, array $si

$response = $httpClient->request(
'GET',
$url
$url,
);

$html = $response->getContent();
Expand All @@ -237,8 +228,6 @@ private function fetchPageSource(int $contentId, string $languageCode, array $si
}

/**
* @param string $html
*
* @return array<string, array<int, string>>
*/
private function extractTextArray(string $html, int $contentId): array
Expand Down
Loading

0 comments on commit e5248c7

Please sign in to comment.