Skip to content

Commit

Permalink
refactor #297 Modernize the codebase (sstok)
Browse files Browse the repository at this point in the history
This PR was merged into the main branch.
labels: bc-break

Discussion
----------

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | yes
| Deprecations? | no
| Tickets       | 
| License       | MIT

- Drop support for OEL PHP versions
- Drop support for Symfony < 4.4
- Drop support for older Elasticsearch versions. And add support for newer versions
- Drop usage of the ElasticaBundle
- Upgrade the quality tools


Commits
-------

6e8451e Bump minimum PHP version to 7.4
afae894 [Elasticsearch] Upgrade to Elastica 5
cf5d060 Allow Money v4.0
32e9b58 Drop support for Symfony 4
cd27c12 Upgrade PHPStan (with baseline)
0ccb9e7 Upgrade Php-cs-fixer
62adba1 Enable PHPStan annotation for pr's
dc79685 Fix PHPUnit deprecations
  • Loading branch information
sstok authored Sep 5, 2021
2 parents 2e9d537 + dc79685 commit 71cfc8d
Show file tree
Hide file tree
Showing 63 changed files with 1,079 additions and 598 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:

# https://hub.docker.com/_/elasticsearch/
elasticsearch:
image: elasticsearch:5.6.3
image: elasticsearch:7.3.0
ports:
- "59200:9200"
options: -e="discovery.type=single-node" -e="xpack.security.enabled=false" --health-cmd="curl http://localhost:9200/_cluster/health" --health-interval=10s --health-timeout=5s --health-retries=10
Expand Down Expand Up @@ -125,4 +125,5 @@ jobs:
-
name: Run PHP-QA
run: |
make lint
make cs-full-check
vendor/bin/phpstan analyse --memory-limit=-1 --error-format=checkstyle | cs2pr
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
/.php_cs.cache
build/**
*.phar
var/
/var/

.phpunit.result.cache
/lib/Symfony/SearchBundle/Tests/Functional/Application/var/
.php-cs-fixer.cache
84 changes: 84 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

$header = <<<EOF
This file is part of the RollerworksSearch package.
(c) Sebastiaan Stok <[email protected]>
This source file is subject to the MIT license that is bundled
with this source code in the file LICENSE.
EOF;

/** @var \Symfony\Component\Finder\Finder $finder */
$finder = PhpCsFixer\Finder::create();
$finder
->in([__DIR__.'/lib'])
->notPath('Symfony/SearchBundle/Tests/Functional/Application/var')
->exclude('Fixtures')
;

$config = new PhpCsFixer\Config();
$config
->setRiskyAllowed(true)
->setRules([
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP74Migration' => true,
'@PHP74Migration:risky' => true,
'@PHPUnit84Migration:risky' => true,
'@DoctrineAnnotation' => true,
'blank_line_before_statement' => [
'statements' => [
'break',
'case',
'continue',
'declare',
'default',
'do',
'exit',
'for',
'foreach',
'goto',
'if',
'include',
'include_once',
'require',
'require_once',
'return',
'switch',
'throw',
'try',
'while',
],
],
'comment_to_phpdoc' => ['ignored_tags' => ['codeCoverageIgnoreStart', 'codeCoverageIgnoreEnd']],
'concat_space' => ['spacing' => 'one'],
'doctrine_annotation_array_assignment' => ['operator' => '='],
'general_phpdoc_annotation_remove' => ['annotations' => [/*'author', */'since', 'package', 'subpackage']],
'header_comment' => ['header' => $header],
'list_syntax' => ['syntax' => 'short'],
'mb_str_functions' => true,
'method_argument_space' => ['on_multiline' => 'ignore'],
'method_chaining_indentation' => false,
'no_extra_blank_lines' => ['tokens' => ['extra', 'use_trait']],
'no_superfluous_phpdoc_tags' => ['remove_inheritdoc' => true],
'not_operator_with_successor_space' => true,
'ordered_class_elements' => false,
'ordered_imports' => true,
'php_unit_method_casing' => ['case' => 'snake_case'],
'php_unit_strict' => false,
'php_unit_test_annotation' => ['style' => 'annotation'],
'php_unit_test_class_requires_covers' => false,
'phpdoc_to_comment' => false,
'phpdoc_var_without_name' => false,
'self_static_accessor' => true,
'single_line_throw' => false,
'static_lambda' => true,
'strict_comparison' => false,
'yoda_style' => ['equal' => false, 'identical' => false],
])
->setFinder($finder);

return $config;
114 changes: 0 additions & 114 deletions .php_cs.dist

This file was deleted.

6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
QA_DOCKER_IMAGE=jakzal/phpqa:1.58.9-php7.4-alpine
QA_DOCKER_IMAGE=jakzal/phpqa:1.59.1-php7.4-alpine
QA_DOCKER_COMMAND=docker run --init -t --rm --user "$(shell id -u):$(shell id -g)" --volume /tmp/tmp-phpqa-$(shell id -u):/tmp --volume "$(shell pwd):/project" --workdir /project ${QA_DOCKER_IMAGE}

dist: install cs-full phpstan test
Expand All @@ -24,8 +24,8 @@ test-coverage: ensure docker-up
sh -c "${QA_DOCKER_COMMAND} phpdbg -qrr /usr/local/bin/phpcov merge --clover build/logs/clover.xml build/cov"
@$(MAKE) docker-down

phpstan: ensure
sh -c "${QA_DOCKER_COMMAND} phpstan analyse"
phpstan:
php -d memory_limit=1G vendor/bin/phpstan analyse

cs: ensure
sh -c "${QA_DOCKER_COMMAND} php-cs-fixer fix -vvv --diff"
Expand Down
14 changes: 12 additions & 2 deletions UPGRADE-2.0.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
UPGRADE FROM 2.0-BETA1 to 2.0-BETA2
===================================

* Support for PHP 7.1 was dropped, you need at least PHP 7.2 or greater.
* Support for PHP < 7.4 was dropped.

* Support for Symfony below 4.4 was dropped.
* Support for Symfony 4 was dropped.

* Support for PHPUnit < 9.5 was dropped.

### Elasticsearch

* Support for Elastica 6 was dropped.

* Support for Elasticsearch 6 was dropped.

_See the upgrade instructions of Elasticsearch itself for more information._

### Doctrine ORM

Expand Down
43 changes: 24 additions & 19 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"php": ">=7.4",
"nesbot/carbon": "^2.38",
"psr/container": "^1.0.0",
"symfony/intl": "^4.4 || ^5.0",
"symfony/options-resolver": "^4.4 || ^5.0",
"symfony/property-access": "^4.4 || ^5.0",
"symfony/intl": "^5.3",
"symfony/options-resolver": "^5.3",
"symfony/property-access": "^5.3",
"symfony/string": "^5.1"
},
"replace": {
Expand All @@ -40,24 +40,29 @@
"doctrine/dbal": "^2.10.3",
"doctrine/doctrine-bundle": "^1.9.1 || ^2.0",
"doctrine/orm": "^2.7.3",
"friendsofsymfony/elastica-bundle": "^5.0 || ^5.2@dev",
"jangregor/phpstan-prophecy": "^0.8.1",
"matthiasnoback/symfony-dependency-injection-test": "^3.0 || ^4.1.1",
"moneyphp/money": "^3.2.0",
"phpunit/phpunit": "^7.5.20 || ^8.0 || ^9.5.7",
"moneyphp/money": "^3.2.0 || ^4.0",
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/phpstan": "^0.12.94",
"phpstan/phpstan-doctrine": "^0.12.42",
"phpstan/phpstan-phpunit": "^0.12.21",
"phpstan/phpstan-symfony": "^0.12.41",
"phpunit/phpunit": "^9.5.7",
"psr/simple-cache": "^1.0.0",
"ruflin/elastica": "^3.2 || ^6.0.0",
"symfony/asset": "^4.4 || ^5.0",
"symfony/browser-kit": "^4.4 || ^5.0",
"symfony/dom-crawler": "^4.4 || ^5.0",
"symfony/framework-bundle": "^4.4 || ^5.0",
"symfony/http-foundation": "^4.4 || ^5.0",
"symfony/phpunit-bridge": "^4.4 || ^5.0",
"symfony/routing": "^4.4 || ^5.0",
"symfony/templating": "^4.4 || ^5.0",
"symfony/translation": "^4.4 || ^5.0",
"symfony/twig-bundle": "^4.4 || ^5.0",
"symfony/validator": "^4.4 || ^5.0",
"symfony/var-dumper": "^4.4 || ^5.0"
"ruflin/elastica": "^7.0",
"symfony/asset": "^5.3",
"symfony/browser-kit": "^5.3",
"symfony/dom-crawler": "^5.3",
"symfony/framework-bundle": "^5.3",
"symfony/http-foundation": "^5.3",
"symfony/phpunit-bridge": "^5.3",
"symfony/routing": "^5.3",
"symfony/templating": "^5.3",
"symfony/translation": "^5.3",
"symfony/twig-bundle": "^5.3",
"symfony/validator": "^5.3",
"symfony/var-dumper": "^5.3"
},
"suggest": {
"moneyphp/money": "To use the MoneyType"
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ services:
- "53306:3306"

elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:5.6.3
image: docker.elastic.co/elasticsearch/elasticsearch:7.3.0
environment:
- "discovery.type=single-node"
- "xpack.security.enabled=false"
Expand Down
20 changes: 0 additions & 20 deletions docker/Dockerfile-qa

This file was deleted.

7 changes: 2 additions & 5 deletions lib/ApiPlatform/Elasticsearch/Extension/SearchExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Doctrine\Persistence\ManagerRegistry;
use Elastica\Client;
use Elastica\Document;
use Elastica\Query;
use Elastica\Search;
use Rollerworks\Component\Search\ApiPlatform\ArrayKeysValidator;
use Rollerworks\Component\Search\Elasticsearch\ElasticsearchFactory;
Expand Down Expand Up @@ -121,11 +120,9 @@ public function applyToCollection(QueryBuilder $queryBuilder, QueryNameGenerator

foreach ($mappings as $mapping) {
$index = $this->client->getIndex($mapping->indexName);
$type = $index->getType($mapping->typeName);
$search
->addIndex($index)
->addType($type);
$search->addIndex($index);
}

$response = $search->search($query);

// NOTE: written like this so we only check if we have a normalizer once
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Doctrine\ORM\QueryBuilder;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Rollerworks\Component\Search\ApiPlatform\Doctrine\Orm\Extension\SearchExtension;
use Rollerworks\Component\Search\Doctrine\Orm\CachedDqlConditionGenerator;
use Rollerworks\Component\Search\Doctrine\Orm\DoctrineOrmFactory;
Expand All @@ -33,6 +34,8 @@
/** @internal */
final class SearchExtensionTest extends TestCase
{
use ProphecyTrait;

/** @test */
public function apply_to_collection_with_valid_condition(): void
{
Expand Down
Loading

0 comments on commit 71cfc8d

Please sign in to comment.