Skip to content
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

General refactoring #76

Merged
merged 14 commits into from
May 11, 2021
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0']
php-versions: ['7.4', '8.0']
name: integration-tests (PHP ${{ matrix.php-versions }})
steps:
- uses: actions/checkout@v2
Expand Down
37 changes: 16 additions & 21 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
<?php

declare(strict_types=1);

if (!file_exists(__DIR__.'/src')) {
exit(0);
}

return PhpCsFixer\Config::create()
->setRules(
[
$finder = PhpCsFixer\Finder::create()
->in(__DIR__.'/src')
->in(__DIR__.'/tests')
->append([__FILE__]);
$config = new PhpCsFixer\Config();
$config->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHPUnit75Migration:risky' => true,
'php_unit_dedicate_assert' => ['target' => 'newest'],
'array_syntax' => ['syntax' => 'short'],
'fopen_flags' => false,
'protected_to_private' => false,
'combine_nested_dirname' => true,
'declare_strict_types' => true,
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => true,
'import_functions' => true,
'import_classes' => false,
'import_functions' => false,
'import_constants' => false,
],
'phpdoc_no_package' => false,
'no_superfluous_phpdoc_tags' => false,
'ordered_imports' => ['sortAlgorithm' => 'none'],
]
)
->setRiskyAllowed(true)
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__.'/src')
->append([__FILE__])
);
->setFinder($finder)
;

return $config;
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:7.2.0-fpm-alpine as php
FROM php:7.4-fpm-alpine as php

# persistent / runtime deps
RUN apk add --no-cache \
Expand Down
2 changes: 0 additions & 2 deletions bors.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
status = [
'integration-tests (PHP 7.2)',
'integration-tests (PHP 7.3)',
'integration-tests (PHP 7.4)',
'integration-tests (PHP 8.0)',
'linter-check'
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
}
],
"require": {
"php": ">=7.2",
"php": "^7.4|^8.0",
"ext-json": "*",
"doctrine/orm": "^2.8",
"meilisearch/meilisearch-php": "^0.17",
"symfony/filesystem": "^4.0 || ^5.0",
"symfony/property-access": "^4.0 || ^5.0",
"symfony/serializer": "^4.0 || ^5.0"
},
"require-dev": {
"doctrine/doctrine-bundle": "^2.0",
"doctrine/orm": "^2.5",
"friendsofphp/php-cs-fixer": "^2.16",
"doctrine/doctrine-bundle": "^2.3",
"friendsofphp/php-cs-fixer": "^2.18",
"jms/serializer-bundle": "^3.0",
"nyholm/psr7": "^1.3",
"phpunit/phpunit": "^8.5",
Expand Down
2 changes: 1 addition & 1 deletion docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if [ "$1" = 'php-fpm' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then
setfacl -dR -m u:www-data:rwX -m u:"$(whoami)":rwX var

if [ "$APP_ENV" != 'prod' ]; then
composer install --prefer-dist --no-progress --no-suggest --no-interaction
composer install --prefer-dist --no-progress --no-interaction
fi
fi

Expand Down
20 changes: 5 additions & 15 deletions src/Command/IndexCommand.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
<?php

declare(strict_types=1);

namespace MeiliSearch\Bundle\Command;

use MeiliSearch\Bundle\SearchService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use function array_keys;
use function count;
use function explode;

/**
* Class IndexCommand.
*
* @package MeiliSearch\Bundle\Command
*/
abstract class IndexCommand extends Command
{
/** @var SearchService */
protected $searchService;
protected SearchService $searchService;

/**
* IndexCommand constructor.
*
* @param SearchService $searchService
* @param string|null $name
*/
public function __construct(SearchService $searchService, string $name = null)
public function __construct(SearchService $searchService, ?string $name = null)
{
$this->searchService = $searchService;
parent::__construct($name);
Expand All @@ -38,7 +28,7 @@ protected function getEntitiesFromArgs(InputInterface $input, OutputInterface $o
$indexNames = [];

if ($indexList = $input->getOption('indices')) {
$indexNames = explode(',', $indexList);
$indexNames = \explode(',', $indexList);
}

$config = $this->searchService->getConfiguration();
Expand Down
8 changes: 2 additions & 6 deletions src/Command/MeiliSearchClearCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace MeiliSearch\Bundle\Command;

use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -8,17 +10,11 @@

/**
* Class MeiliSearchClearCommand.
*
* @package MeiliSearch\Bundle\Command
*/
final class MeiliSearchClearCommand extends IndexCommand
{
/** @var string */
protected static $defaultName = 'meili:clear';

/**
* {@inheritdoc}
*/
protected function configure()
{
$this
Expand Down
49 changes: 5 additions & 44 deletions src/Command/MeiliSearchImportCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace MeiliSearch\Bundle\Command;

use Doctrine\Persistence\ManagerRegistry;
Expand All @@ -8,57 +10,26 @@
use MeiliSearch\Bundle\Model\Aggregator;
use MeiliSearch\Bundle\SearchService;
use MeiliSearch\Client;
use MeiliSearch\Exceptions\ApiException;
use MeiliSearch\Exceptions\TimeOutException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use function array_key_exists;
use function array_map;
use function array_merge;
use function array_unique;
use function count;
use function is_subclass_of;
use function method_exists;
use function sprintf;
use function ucfirst;
use const SORT_REGULAR;

/**
* Class MeiliSearchImportCommand.
*
* @package MeiliSearch\Bundle\Command
*/
final class MeiliSearchImportCommand extends IndexCommand
{
/**
* @var string
*/
protected static $defaultName = 'meili:import';
protected Client $searchClient;
protected ManagerRegistry $managerRegistry;

/** @var Client */
protected $searchClient;

/** @var ManagerRegistry */
protected $managerRegistry;

/**
* MeiliSearchImportCommand constructor.
*
* @param SearchService $searchService
* @param ManagerRegistry $managerRegistry
* @param Client $searchClient
*/
public function __construct(SearchService $searchService, ManagerRegistry $managerRegistry, Client $searchClient)
{
parent::__construct($searchService);
$this->managerRegistry = $managerRegistry;
$this->searchClient = $searchClient;
}

/**
* {@inheritdoc}
*/
protected function configure()
{
$this
Expand All @@ -72,12 +43,6 @@ protected function configure()
);
}

/**
* {@inheritdoc}
*
* @throws TimeOutException
* @throws ApiException
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$entitiesToIndex = $this->getEntitiesFromArgs($input, $output);
Expand Down Expand Up @@ -164,11 +129,7 @@ function ($entity) {
return 0;
}

/**
* @param array $batch
*
* @return array
*
/*
* @throws TimeOutException
*/
private function formatIndexingResponse(array $batch): array
Expand Down
9 changes: 3 additions & 6 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
<?php

declare(strict_types=1);

namespace MeiliSearch\Bundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* Class Configuration.
*
* @package MeiliSearch\Bundle\DependencyInjection
*/
final class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('meili_search');
$rootNode = $treeBuilder->getRootNode();
Expand Down
12 changes: 5 additions & 7 deletions src/DependencyInjection/MeiliSearchExtension.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace MeiliSearch\Bundle\DependencyInjection;

use MeiliSearch\Bundle\Engine;
Expand All @@ -10,22 +12,18 @@
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use function count;
use function dirname;

/**
* Class MeiliSearchExtension.
*
* @package MeiliSearch\Bundle\DependencyInjection
*/
final class MeiliSearchExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new Loader\XmlFileLoader($container, new FileLocator(dirname(__DIR__).'/Resources/config'));
$loader = new Loader\XmlFileLoader($container, new FileLocator(\dirname(__DIR__).'/Resources/config'));
$loader->load('services.xml');

$configuration = new Configuration();
Expand All @@ -35,7 +33,7 @@ public function load(array $configs, ContainerBuilder $container)
$config['prefix'] = $container->getParameter('kernel.environment').'_';
}

if (count($doctrineSubscribedEvents = $config['doctrineSubscribedEvents']) > 0) {
if (\count($doctrineSubscribedEvents = $config['doctrineSubscribedEvents']) > 0) {
$container->getDefinition('search.search_indexer_subscriber')->setArgument(1, $doctrineSubscribedEvents);
} else {
$container->removeDefinition('search.search_indexer_subscriber');
Expand Down
4 changes: 2 additions & 2 deletions src/Document/Aggregator.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

declare(strict_types=1);

namespace MeiliSearch\Bundle\Document;

use MeiliSearch\Bundle\Model\Aggregator as BaseAggregator;

/**
* Class Aggregator.
*
* @package MeiliSearch\Bundle\Document
*/
abstract class Aggregator extends BaseAggregator
{
Expand Down
Loading