Skip to content

Commit 57825c3

Browse files
bors[bot]Holger Löskencodedge
authored
Merge #76
76: General refactoring r=curquiza a=codedge This PR improves the code in various aspects ## PHP version [Supported PHP versions](https://www.php.net/supported-versions.php) are >=7.4 are >=8.0. Both, Symfony 4.4 and 5.0, can run using these versions. ## Strict types Using strict types is good. You know 😉 ## Type hints By using PHP 7.4 as minimum version type hints can be set class properties. There are still places left in the code where multiple types are used or general `object` types. These place can (should?) be refactored at a later stage. ## Comments A lot of comments just describe the passed/parameter values and return values. Due to type hints they are obsolte. ## Composer packages The `MeiliSearchImportCommand` needs the `Doctrine\Persistence\ManagerRegistry` injected so Doctrine cannot only be a dev requirement. I added the `doctrine/orm` package to the `require` section instead of `require-dev`. This is also needed for the [Symfony recipe](symfony/recipes-contrib#1128) PR I opened. ## Tests Some testing configuration seem to be unnecessary. I removed some configuration. Still, the tests run fine. Co-authored-by: Holger Lösken <[email protected]> Co-authored-by: Holger Lösken <[email protected]>
2 parents d7c6790 + f1d659d commit 57825c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+375
-784
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
php-versions: ['7.2', '7.3', '7.4', '8.0']
17+
php-versions: ['7.4', '8.0']
1818
name: integration-tests (PHP ${{ matrix.php-versions }})
1919
steps:
2020
- uses: actions/checkout@v2

.php_cs.dist

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
if (!file_exists(__DIR__.'/src')) {
46
exit(0);
57
}
68

7-
return PhpCsFixer\Config::create()
8-
->setRules(
9-
[
9+
$finder = PhpCsFixer\Finder::create()
10+
->in(__DIR__.'/src')
11+
->in(__DIR__.'/tests')
12+
->append([__FILE__]);
13+
$config = new PhpCsFixer\Config();
14+
$config->setRules([
1015
'@Symfony' => true,
11-
'@Symfony:risky' => true,
12-
'@PHPUnit75Migration:risky' => true,
13-
'php_unit_dedicate_assert' => ['target' => 'newest'],
14-
'array_syntax' => ['syntax' => 'short'],
15-
'fopen_flags' => false,
16-
'protected_to_private' => false,
17-
'combine_nested_dirname' => true,
16+
'declare_strict_types' => true,
1817
'global_namespace_import' => [
19-
'import_classes' => true,
20-
'import_constants' => true,
21-
'import_functions' => true,
18+
'import_classes' => false,
19+
'import_functions' => false,
20+
'import_constants' => false,
2221
],
23-
'phpdoc_no_package' => false,
24-
'no_superfluous_phpdoc_tags' => false,
25-
'ordered_imports' => ['sortAlgorithm' => 'none'],
2622
]
2723
)
2824
->setRiskyAllowed(true)
29-
->setFinder(
30-
PhpCsFixer\Finder::create()
31-
->in(__DIR__.'/src')
32-
->append([__FILE__])
33-
);
25+
->setFinder($finder)
26+
;
27+
28+
return $config;

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM php:7.2.0-fpm-alpine as php
1+
FROM php:7.4-fpm-alpine as php
22

33
# persistent / runtime deps
44
RUN apk add --no-cache \

bors.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
status = [
2-
'integration-tests (PHP 7.2)',
3-
'integration-tests (PHP 7.3)',
42
'integration-tests (PHP 7.4)',
53
'integration-tests (PHP 8.0)',
64
'linter-check'

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818
}
1919
],
2020
"require": {
21-
"php": ">=7.2",
21+
"php": "^7.4|^8.0",
2222
"ext-json": "*",
23+
"doctrine/orm": "^2.8",
2324
"meilisearch/meilisearch-php": "^0.17",
2425
"symfony/filesystem": "^4.0 || ^5.0",
2526
"symfony/property-access": "^4.0 || ^5.0",
2627
"symfony/serializer": "^4.0 || ^5.0"
2728
},
2829
"require-dev": {
29-
"doctrine/doctrine-bundle": "^2.0",
30-
"doctrine/orm": "^2.5",
31-
"friendsofphp/php-cs-fixer": "^2.16",
30+
"doctrine/doctrine-bundle": "^2.3",
31+
"friendsofphp/php-cs-fixer": "^2.18",
3232
"jms/serializer-bundle": "^3.0",
3333
"nyholm/psr7": "^1.3",
3434
"phpunit/phpunit": "^8.5",

docker-entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if [ "$1" = 'php-fpm' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then
1212
setfacl -dR -m u:www-data:rwX -m u:"$(whoami)":rwX var
1313

1414
if [ "$APP_ENV" != 'prod' ]; then
15-
composer install --prefer-dist --no-progress --no-suggest --no-interaction
15+
composer install --prefer-dist --no-progress --no-interaction
1616
fi
1717
fi
1818

src/Command/IndexCommand.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,22 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MeiliSearch\Bundle\Command;
46

57
use MeiliSearch\Bundle\SearchService;
68
use Symfony\Component\Console\Command\Command;
79
use Symfony\Component\Console\Input\InputInterface;
810
use Symfony\Component\Console\Output\OutputInterface;
9-
use function array_keys;
10-
use function count;
11-
use function explode;
1211

1312
/**
1413
* Class IndexCommand.
15-
*
16-
* @package MeiliSearch\Bundle\Command
1714
*/
1815
abstract class IndexCommand extends Command
1916
{
20-
/** @var SearchService */
21-
protected $searchService;
17+
protected SearchService $searchService;
2218

23-
/**
24-
* IndexCommand constructor.
25-
*
26-
* @param SearchService $searchService
27-
* @param string|null $name
28-
*/
29-
public function __construct(SearchService $searchService, string $name = null)
19+
public function __construct(SearchService $searchService, ?string $name = null)
3020
{
3121
$this->searchService = $searchService;
3222
parent::__construct($name);
@@ -38,7 +28,7 @@ protected function getEntitiesFromArgs(InputInterface $input, OutputInterface $o
3828
$indexNames = [];
3929

4030
if ($indexList = $input->getOption('indices')) {
41-
$indexNames = explode(',', $indexList);
31+
$indexNames = \explode(',', $indexList);
4232
}
4333

4434
$config = $this->searchService->getConfiguration();

src/Command/MeiliSearchClearCommand.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MeiliSearch\Bundle\Command;
46

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

911
/**
1012
* Class MeiliSearchClearCommand.
11-
*
12-
* @package MeiliSearch\Bundle\Command
1313
*/
1414
final class MeiliSearchClearCommand extends IndexCommand
1515
{
16-
/** @var string */
1716
protected static $defaultName = 'meili:clear';
1817

19-
/**
20-
* {@inheritdoc}
21-
*/
2218
protected function configure()
2319
{
2420
$this

src/Command/MeiliSearchImportCommand.php

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MeiliSearch\Bundle\Command;
46

57
use Doctrine\Persistence\ManagerRegistry;
@@ -8,57 +10,26 @@
810
use MeiliSearch\Bundle\Model\Aggregator;
911
use MeiliSearch\Bundle\SearchService;
1012
use MeiliSearch\Client;
11-
use MeiliSearch\Exceptions\ApiException;
12-
use MeiliSearch\Exceptions\TimeOutException;
1313
use Symfony\Component\Console\Input\InputInterface;
1414
use Symfony\Component\Console\Input\InputOption;
1515
use Symfony\Component\Console\Output\OutputInterface;
16-
use function array_key_exists;
17-
use function array_map;
18-
use function array_merge;
19-
use function array_unique;
20-
use function count;
21-
use function is_subclass_of;
22-
use function method_exists;
23-
use function sprintf;
24-
use function ucfirst;
25-
use const SORT_REGULAR;
2616

2717
/**
2818
* Class MeiliSearchImportCommand.
29-
*
30-
* @package MeiliSearch\Bundle\Command
3119
*/
3220
final class MeiliSearchImportCommand extends IndexCommand
3321
{
34-
/**
35-
* @var string
36-
*/
3722
protected static $defaultName = 'meili:import';
23+
protected Client $searchClient;
24+
protected ManagerRegistry $managerRegistry;
3825

39-
/** @var Client */
40-
protected $searchClient;
41-
42-
/** @var ManagerRegistry */
43-
protected $managerRegistry;
44-
45-
/**
46-
* MeiliSearchImportCommand constructor.
47-
*
48-
* @param SearchService $searchService
49-
* @param ManagerRegistry $managerRegistry
50-
* @param Client $searchClient
51-
*/
5226
public function __construct(SearchService $searchService, ManagerRegistry $managerRegistry, Client $searchClient)
5327
{
5428
parent::__construct($searchService);
5529
$this->managerRegistry = $managerRegistry;
5630
$this->searchClient = $searchClient;
5731
}
5832

59-
/**
60-
* {@inheritdoc}
61-
*/
6233
protected function configure()
6334
{
6435
$this
@@ -72,12 +43,6 @@ protected function configure()
7243
);
7344
}
7445

75-
/**
76-
* {@inheritdoc}
77-
*
78-
* @throws TimeOutException
79-
* @throws ApiException
80-
*/
8146
protected function execute(InputInterface $input, OutputInterface $output): int
8247
{
8348
$entitiesToIndex = $this->getEntitiesFromArgs($input, $output);
@@ -164,11 +129,7 @@ function ($entity) {
164129
return 0;
165130
}
166131

167-
/**
168-
* @param array $batch
169-
*
170-
* @return array
171-
*
132+
/*
172133
* @throws TimeOutException
173134
*/
174135
private function formatIndexingResponse(array $batch): array

src/DependencyInjection/Configuration.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MeiliSearch\Bundle\DependencyInjection;
46

57
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
68
use Symfony\Component\Config\Definition\ConfigurationInterface;
79

810
/**
911
* Class Configuration.
10-
*
11-
* @package MeiliSearch\Bundle\DependencyInjection
1212
*/
1313
final class Configuration implements ConfigurationInterface
1414
{
15-
/**
16-
* {@inheritdoc}
17-
*/
18-
public function getConfigTreeBuilder()
15+
public function getConfigTreeBuilder(): TreeBuilder
1916
{
2017
$treeBuilder = new TreeBuilder('meili_search');
2118
$rootNode = $treeBuilder->getRootNode();

src/DependencyInjection/MeiliSearchExtension.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MeiliSearch\Bundle\DependencyInjection;
46

57
use MeiliSearch\Bundle\Engine;
@@ -10,22 +12,18 @@
1012
use Symfony\Component\DependencyInjection\Loader;
1113
use Symfony\Component\DependencyInjection\Reference;
1214
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
13-
use function count;
14-
use function dirname;
1515

1616
/**
1717
* Class MeiliSearchExtension.
18-
*
19-
* @package MeiliSearch\Bundle\DependencyInjection
2018
*/
2119
final class MeiliSearchExtension extends Extension
2220
{
2321
/**
2422
* {@inheritdoc}
2523
*/
26-
public function load(array $configs, ContainerBuilder $container)
24+
public function load(array $configs, ContainerBuilder $container): void
2725
{
28-
$loader = new Loader\XmlFileLoader($container, new FileLocator(dirname(__DIR__).'/Resources/config'));
26+
$loader = new Loader\XmlFileLoader($container, new FileLocator(\dirname(__DIR__).'/Resources/config'));
2927
$loader->load('services.xml');
3028

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

38-
if (count($doctrineSubscribedEvents = $config['doctrineSubscribedEvents']) > 0) {
36+
if (\count($doctrineSubscribedEvents = $config['doctrineSubscribedEvents']) > 0) {
3937
$container->getDefinition('search.search_indexer_subscriber')->setArgument(1, $doctrineSubscribedEvents);
4038
} else {
4139
$container->removeDefinition('search.search_indexer_subscriber');

src/Document/Aggregator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MeiliSearch\Bundle\Document;
46

57
use MeiliSearch\Bundle\Model\Aggregator as BaseAggregator;
68

79
/**
810
* Class Aggregator.
9-
*
10-
* @package MeiliSearch\Bundle\Document
1111
*/
1212
abstract class Aggregator extends BaseAggregator
1313
{

0 commit comments

Comments
 (0)