diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f0256f5..8047248 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,10 +2,10 @@ name: CI on: push: - branches: [ master ] + branches: [master] pull_request: schedule: - - cron: '0 0 * * MON' + - cron: "0 0 * * MON" jobs: check-cs: @@ -13,19 +13,19 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: PHP-CS-Fixer uses: docker://oskarstark/php-cs-fixer-ga with: - args: --config=.php-cs-fixer.php --diff --dry-run + args: --config=.php-cs-fixer.php --diff --dry-run phpstan: name: PHPStan runs-on: ubuntu-latest steps: - name: "Checkout" - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup PHP, with composer and extensions uses: shivammathur/setup-php@v2 @@ -35,9 +35,9 @@ jobs: - name: PHPStan uses: docker://oskarstark/phpstan-ga env: - REQUIRE_DEV: true + REQUIRE_DEV: true with: - args: analyse + args: analyse tests_es: name: Test PHP ${{ matrix.php-version }} & Symfony ${{ matrix.symfony-version }} ${{ matrix.composer-flags }} & Elasticsearch ${{ matrix.es-version }} @@ -49,33 +49,33 @@ jobs: matrix: include: # Every lowest supported version - - php-version: '8.0' - symfony-version: '5.4.*' - composer-flags: '--prefer-lowest' - es-version: '7.17.3' + - php-version: "8.0" + symfony-version: "5.4.*" + composer-flags: "--prefer-lowest" + es-version: "7.17.3" # Every lowest supported version && Symfony 6 - - php-version: '8.1' - symfony-version: '6.2.*' - composer-flags: '' - es-version: '7.17.3' + - php-version: "8.1" + symfony-version: "6.2.*" + composer-flags: "" + es-version: "7.17.3" # PHP 8.1, latest SF 6, ES 7 - - php-version: '8.1' - symfony-version: '6.*' - composer-flags: '' - es-version: '7.17.3' + - php-version: "8.1" + symfony-version: "6.*" + composer-flags: "" + es-version: "7.17.3" # PHP 8.2, latest SF 6, ES 8 - - php-version: '8.2' - symfony-version: '6.*' - composer-flags: '' - es-version: '8.2.0' + - php-version: "8.2" + symfony-version: "6.*" + composer-flags: "" + es-version: "8.2.0" # PHP 8.3, latest SF 7, ES 8 - - php-version: '8.3' - symfony-version: '7.*' - composer-flags: '' - es-version: '8.2.0' + - php-version: "8.3" + symfony-version: "7.*" + composer-flags: "" + es-version: "8.2.0" steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup PHP, with composer and extensions uses: shivammathur/setup-php@v2 @@ -94,24 +94,24 @@ jobs: - name: Configure sysctl limits run: | - sudo swapoff -a - sudo sysctl -w vm.swappiness=1 - sudo sysctl -w fs.file-max=262144 - sudo sysctl -w vm.max_map_count=262144 + sudo swapoff -a + sudo sysctl -w vm.swappiness=1 + sudo sysctl -w fs.file-max=262144 + sudo sysctl -w vm.max_map_count=262144 - name: Runs Elasticsearch ${{ matrix.es-version }} uses: elastic/elastic-github-actions/elasticsearch@master with: - security-enabled: false - stack-version: ${{ matrix.es-version }} - port: 9999 + security-enabled: false + stack-version: ${{ matrix.es-version }} + port: 9999 - name: Wait for ES to be ready run: | - while ! curl -s -X GET http://127.0.0.1:9999/_cluster/health\?wait_for_status\=green\&timeout\=60s | grep -q '"status":"green"' - do - echo "==> Waiting for cluster green status" && sleep 1 - done + while ! curl -s -X GET http://127.0.0.1:9999/_cluster/health\?wait_for_status\=green\&timeout\=60s | grep -q '"status":"green"' + do + echo "==> Waiting for cluster green status" && sleep 1 + done - name: Run Tests run: make test @@ -125,19 +125,19 @@ jobs: fail-fast: false matrix: include: - - php-version: '8.3' - symfony-version: '6.*' - composer-flags: '' + - php-version: "8.3" + symfony-version: "6.*" + composer-flags: "" os-version: 1.3.6 os-image: opensearchproject/opensearch:1.3.6 - - php-version: '8.3' - symfony-version: '6.*' - composer-flags: '' + - php-version: "8.3" + symfony-version: "6.*" + composer-flags: "" os-version: 2.3.0 os-image: opensearchproject/opensearch:2.3.0 - - php-version: '8.3' - symfony-version: '7.*' - composer-flags: '' + - php-version: "8.3" + symfony-version: "7.*" + composer-flags: "" os-version: 2.3.0 os-image: opensearchproject/opensearch:2.3.0 services: @@ -151,7 +151,7 @@ jobs: http.port: 9999 steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup PHP, with composer and extensions uses: shivammathur/setup-php@v2 @@ -170,17 +170,17 @@ jobs: - name: Configure sysctl limits run: | - sudo swapoff -a - sudo sysctl -w vm.swappiness=1 - sudo sysctl -w fs.file-max=262144 - sudo sysctl -w vm.max_map_count=262144 + sudo swapoff -a + sudo sysctl -w vm.swappiness=1 + sudo sysctl -w fs.file-max=262144 + sudo sysctl -w vm.max_map_count=262144 - name: Wait for OpenSearch to be ready run: | - while ! curl -s -X GET http://127.0.0.1:9999/_cluster/health\?wait_for_status\=green\&timeout\=60s | grep -q '"status":"green"' - do - echo "==> Waiting for cluster green status" && sleep 1 - done + while ! curl -s -X GET http://127.0.0.1:9999/_cluster/health\?wait_for_status\=green\&timeout\=60s | grep -q '"status":"green"' + do + echo "==> Waiting for cluster green status" && sleep 1 + done - name: Run Tests run: make test diff --git a/composer.json b/composer.json index ea6afe3..9384ccd 100644 --- a/composer.json +++ b/composer.json @@ -51,6 +51,9 @@ } }, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "symfony/flex": true + } } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 7ce80e3..cee7f76 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,5 +1,10 @@ parameters: ignoreErrors: + - + message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:children\\(\\)\\.$#" + count: 1 + path: src/Bridge/Symfony/DependencyInjection/Configuration.php + - message: "#^Method JoliCode\\\\Elastically\\\\Index\\:\\:getClient\\(\\) should return JoliCode\\\\Elastically\\\\Client but returns Elastica\\\\Client\\.$#" count: 1 @@ -9,18 +14,3 @@ parameters: message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\ResponseEvent\\:\\:isMasterRequest\\(\\)\\.$#" count: 1 path: src/Messenger/IndexationRequestSpoolSubscriber.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:children\\(\\)\\.$#" - count: 1 - path: src/Bridge/Symfony/DependencyInjection/Configuration.php - - - # We need https://github.com/ruflin/Elastica/pull/2176 - message: "#^Method JoliCode\\\\Elastically\\\\IndexBuilder\\:\\:slowDownRefresh\\(\\) has Elastica\\\\Exception\\\\ExceptionInterface in PHPDoc @throws tag but it's not thrown\\.$#" - count: 1 - path: src/IndexBuilder.php - - - # We need https://github.com/ruflin/Elastica/pull/2176 - message: "#^Method JoliCode\\\\Elastically\\\\IndexBuilder\\:\\:speedUpRefresh\\(\\) has Elastica\\\\Exception\\\\ExceptionInterface in PHPDoc @throws tag but it's not thrown\\.$#" - count: 1 - path: src/IndexBuilder.php diff --git a/src/Client.php b/src/Client.php index 19b22e3..088549c 100644 --- a/src/Client.php +++ b/src/Client.php @@ -31,7 +31,7 @@ class Client extends ElasticaClient private ResultSetBuilder $resultSetBuilder; private IndexNameMapper $indexNameMapper; - public function __construct($config = [], callable $callback = null, LoggerInterface $logger = null, ResultSetBuilder $resultSetBuilder = null, IndexNameMapper $indexNameMapper = null) + public function __construct($config = [], ?callable $callback = null, ?LoggerInterface $logger = null, ?ResultSetBuilder $resultSetBuilder = null, ?IndexNameMapper $indexNameMapper = null) { parent::__construct($config, $callback, $logger); diff --git a/src/Index.php b/src/Index.php index 66f2dba..256760f 100644 --- a/src/Index.php +++ b/src/Index.php @@ -39,7 +39,7 @@ public function getModel($id) return $this->resultSetBuilder->buildModelFromDocument($document); } - public function createSearch($query = '', $options = null, BuilderInterface $builder = null): Search + public function createSearch($query = '', $options = null, ?BuilderInterface $builder = null): Search { return parent::createSearch($query, $options, $builder ?? $this->resultSetBuilder); } diff --git a/src/Indexer.php b/src/Indexer.php index d0ff713..506779b 100644 --- a/src/Indexer.php +++ b/src/Indexer.php @@ -30,7 +30,7 @@ class Indexer private ?Bulk $currentBulk = null; - public function __construct(Client $client, SerializerInterface $serializer, int $bulkMaxSize = 100, array $bulkRequestParams = [], ContextBuilderInterface $contextBuilder = null) + public function __construct(Client $client, SerializerInterface $serializer, int $bulkMaxSize = 100, array $bulkRequestParams = [], ?ContextBuilderInterface $contextBuilder = null) { // TODO: on the destruct, maybe throw an exception for non empty indexer queues? diff --git a/src/Mapping/YamlProvider.php b/src/Mapping/YamlProvider.php index 411199e..2296213 100644 --- a/src/Mapping/YamlProvider.php +++ b/src/Mapping/YamlProvider.php @@ -20,7 +20,7 @@ final class YamlProvider implements MappingProviderInterface private string $configurationDirectory; private Parser $parser; - public function __construct(string $configurationDirectory, Parser $parser = null) + public function __construct(string $configurationDirectory, ?Parser $parser = null) { $this->configurationDirectory = $configurationDirectory; $this->parser = $parser ?? new Parser(); diff --git a/src/Model/Document.php b/src/Model/Document.php index ef33f90..e9a0184 100644 --- a/src/Model/Document.php +++ b/src/Model/Document.php @@ -18,14 +18,14 @@ class Document extends ElasticaDocument { private ?object $model; - public function __construct(?string $id, object $model = null, array|string $data = [], Index|string $index = '') + public function __construct(?string $id, ?object $model = null, array|string $data = [], Index|string $index = '') { parent::__construct($id, $data, $index); $this->model = $model; } - public static function createFromDocument(ElasticaDocument $document, object $model = null): self + public static function createFromDocument(ElasticaDocument $document, ?object $model = null): self { return new self($document->getId(), $model, $document->getData(), $document->getIndex()); } diff --git a/src/Transport/HttpClientTransport.php b/src/Transport/HttpClientTransport.php index 667627a..1288894 100644 --- a/src/Transport/HttpClientTransport.php +++ b/src/Transport/HttpClientTransport.php @@ -44,7 +44,7 @@ class HttpClientTransport extends AbstractTransport */ private string $scheme; - public function __construct(HttpClientInterface $client, string $scheme = 'http', Connection $connection = null) + public function __construct(HttpClientInterface $client, string $scheme = 'http', ?Connection $connection = null) { parent::__construct($connection); diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index 4c71424..5e46f29 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -24,7 +24,7 @@ protected function setUp(): void $this->getFactory()->buildClient()->request('*', 'DELETE'); } - protected function getFactory(string $path = null, array $config = []): Factory + protected function getFactory(?string $path = null, array $config = []): Factory { return new Factory($config + [ Factory::CONFIG_MAPPINGS_DIRECTORY => $path ?? __DIR__ . '/configs', @@ -33,7 +33,7 @@ protected function getFactory(string $path = null, array $config = []): Factory ]); } - protected function getClient(string $path = null, array $config = []): Client + protected function getClient(?string $path = null, array $config = []): Client { return $this->getFactory($path, $config)->buildClient(); } diff --git a/tests/IndexBuilderTest.php b/tests/IndexBuilderTest.php index d70fc1c..f17f612 100644 --- a/tests/IndexBuilderTest.php +++ b/tests/IndexBuilderTest.php @@ -281,7 +281,7 @@ public function testMigrate(): void $this->assertInstanceOf(ElasticaDocument::class, $document); } - private function getIndexBuilder(string $path = null, array $config = []): IndexBuilder + private function getIndexBuilder(?string $path = null, array $config = []): IndexBuilder { return $this->getFactory($path, $config)->buildIndexBuilder(); }