Skip to content

Commit

Permalink
Merge pull request #30 from dachcom-digital/coding-standard/refactor-…
Browse files Browse the repository at this point in the history
…master

[CS] Refactor
  • Loading branch information
solverat authored Jan 6, 2025
2 parents 0c8c87a + dbf5e7e commit ce3d222
Show file tree
Hide file tree
Showing 22 changed files with 324 additions and 97 deletions.
11 changes: 11 additions & 0 deletions src/Builder/ClientBuilder.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace DsElasticSearchBundle\Builder;

use DynamicSearchBundle\Logger\LoggerInterface;
Expand Down
13 changes: 12 additions & 1 deletion src/Builder/ClientBuilderInterface.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace DsElasticSearchBundle\Builder;

use Elasticsearch\Client;

interface ClientBuilderInterface
{
public function build(array $indexOptions): Client;
}
}
19 changes: 17 additions & 2 deletions src/Command/RebuildIndexCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace DsElasticSearchBundle\Command;

use DsElasticSearchBundle\Builder\ClientBuilderInterface;
Expand Down Expand Up @@ -40,13 +51,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int

if (empty($contextName)) {
$output->writeln('<error>no context definition name given</error>');

return 0;
}

$contextDefinition = $this->contextDefinitionBuilder->buildContextDefinition($contextName, ContextDefinitionInterface::CONTEXT_DISPATCH_TYPE_INDEX);

if (!$contextDefinition instanceof ContextDefinitionInterface) {
$output->writeln(sprintf('<error>no context definition with name "%s" found</error>', $contextName));

return 0;
}

Expand All @@ -56,7 +69,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln(
sprintf(
'%s. (The current context index provider also requires pre-configured indices. Please make sure your document definition implements the "%s" interface)',
$e->getMessage(), PreConfiguredIndexProviderInterface::class
$e->getMessage(),
PreConfiguredIndexProviderInterface::class
)
);

Expand All @@ -80,7 +94,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$indexService = new IndexPersistenceService($client, $options);

if ($indexService->indexExists()) {

/** @var QuestionHelper $helper */
$helper = $this->getHelper('question');

Expand All @@ -96,6 +109,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$indexService->dropIndex();
} catch (\Throwable $e) {
$output->writeln(sprintf('Error while dropping index: %s', $e->getMessage()));

return 0;
}
}
Expand All @@ -104,6 +118,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$indexService->createIndex($indexDocument);
} catch (\Throwable $e) {
$output->writeln(sprintf('Error while creating index: %s', $e->getMessage()));

return 0;
}

Expand Down
13 changes: 12 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace DsElasticSearchBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
Expand All @@ -11,4 +22,4 @@ public function getConfigTreeBuilder(): TreeBuilder
{
return new TreeBuilder('ds_elasticsearch');
}
}
}
17 changes: 14 additions & 3 deletions src/DependencyInjection/DsElasticSearchExtension.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace DsElasticSearchBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;

class DsElasticSearchExtension extends Extension
{
Expand All @@ -17,4 +28,4 @@ public function load(array $configs, ContainerBuilder $container): void
$loader = new YamlFileLoader($container, new FileLocator([__DIR__ . '/../../config']));
$loader->load('services.yaml');
}
}
}
11 changes: 11 additions & 0 deletions src/DsElasticSearchBundle.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace DsElasticSearchBundle;

use DynamicSearchBundle\Provider\Extension\ProviderBundleInterface;
Expand Down
17 changes: 14 additions & 3 deletions src/DsElasticSearchEvents.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace DsElasticSearchBundle;

final class DsElasticSearchEvents
{
/**
* The BULK event occurs before during the processing of bulk method
* The BULK event occurs before during the processing of bulk method.
*/
public const BULK = 'ds_elasticsearch.bulk';

/**
* The PRE_COMMIT event occurs before committing queries to ES
* The PRE_COMMIT event occurs before committing queries to ES.
*/
public const PRE_COMMIT = 'ds_elasticsearch.pre_commit';

/**
* The POST_COMMIT event occurs after committing queries to ES
* The POST_COMMIT event occurs after committing queries to ES.
*/
public const POST_COMMIT = 'ds_elasticsearch.post_commit';

Expand Down
11 changes: 11 additions & 0 deletions src/Exception/ClientException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace DsElasticSearchBundle\Exception;

final class ClientException extends \Exception
Expand Down
11 changes: 11 additions & 0 deletions src/Index/Field/AbstractType.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace DsElasticSearchBundle\Index\Field;

use DynamicSearchBundle\Index\IndexFieldInterface;
Expand Down
11 changes: 11 additions & 0 deletions src/Index/Field/DynamicField.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace DsElasticSearchBundle\Index\Field;

final class DynamicField extends AbstractType
Expand Down
11 changes: 11 additions & 0 deletions src/Index/Field/ExplicitField.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace DsElasticSearchBundle\Index\Field;

final class ExplicitField extends AbstractType
Expand Down
12 changes: 12 additions & 0 deletions src/Normalizer/DocumentRawNormalizer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace DsElasticSearchBundle\Normalizer;

use DynamicSearchBundle\Context\ContextDefinitionInterface;
Expand All @@ -25,6 +36,7 @@ public function normalize(RawResultInterface $rawResult, ContextDefinitionInterf
{
if ($rawResult->hasParameter('fullDatabaseResponse') === false) {
$message = sprintf('Parameter "fullDatabaseResponse" is required to normalize raw result but is missing');

throw new NormalizerException($message, __CLASS__);
}

Expand Down
12 changes: 12 additions & 0 deletions src/Normalizer/DocumentSourceNormalizer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace DsElasticSearchBundle\Normalizer;

use DynamicSearchBundle\Context\ContextDefinitionInterface;
Expand Down Expand Up @@ -27,6 +38,7 @@ public function normalize(RawResultInterface $rawResult, ContextDefinitionInterf

if (!is_array($data)) {
$message = sprintf('Data needs to be type of "array", "%s" given', is_object($data) ? get_class($data) : gettype($data));

throw new NormalizerException($message, __CLASS__);
}

Expand Down
17 changes: 13 additions & 4 deletions src/OutputChannel/Filter/AggregationFilter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace DsElasticSearchBundle\OutputChannel\Filter;

use DynamicSearchBundle\EventDispatcher\OutputChannelModifierEventDispatcher;
Expand Down Expand Up @@ -31,7 +42,7 @@ public function configureOptions(OptionsResolver $resolver): void
$resolver->setAllowedTypes('relation_label', ['closure', 'null']);
$resolver->setAllowedTypes('field', ['string']);
$resolver->setAllowedTypes('query_type', ['string']);

$resolver->setDefaults([
'query_type' => BoolQuery::MUST,
'show_in_frontend' => true,
Expand Down Expand Up @@ -96,7 +107,7 @@ public function buildViewVars(RawResultInterface $rawResult, $filterValues, $que
$response = $rawResult->getParameter('fullDatabaseResponse');

$viewVars = [
'name' => $this->name,
'name' => $this->name,
'template' => [sprintf('%s/%s.html.twig', self::VIEW_TEMPLATE_PATH, $this->name), sprintf('%s/aggregation.html.twig', self::VIEW_TEMPLATE_PATH)],
'label' => $this->options['label'],
'multiple' => $this->options['multiple'],
Expand All @@ -119,7 +130,6 @@ protected function addQueryFilter(Search $query, array $queryFields): void
}

foreach ($queryFields as $key => $value) {

if ($key !== $this->name) {
continue;
}
Expand Down Expand Up @@ -159,7 +169,6 @@ protected function buildResultArray(array $buckets): array

$values = [];
foreach ($buckets as $bucket) {

$relationLabel = null;
if ($this->options['relation_label'] !== null) {
$relationLabel = call_user_func($this->options['relation_label'], $bucket['key'], $queryFields['locale'] ?? null);
Expand Down
Loading

0 comments on commit ce3d222

Please sign in to comment.