diff --git a/.gitignore b/.gitignore index 3452648..5186b79 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /vendor/ composer.lock .php_cs.cache +.phpunit.result.cache diff --git a/Makefile b/Makefile index 1196ddf..9caad7d 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ test: vendor/bin/phpunit --testdox --colors=always --group=functional .PHONY: qa -qa: php-cs-fixer-ci +qa: php-cs-fixer-ci phpstan .PHONY: php-cs-fixer php-cs-fixer: @@ -20,6 +20,10 @@ php-cs-fixer: php-cs-fixer-ci: vendor/bin/php-cs-fixer fix --dry-run --no-interaction --allow-risky=yes --diff --verbose +PHONY: phpstan +phpstan: + vendor/bin/phpstan analyse --level=max src/ + .PHONY: changelog changelog: git log $$(git describe --abbrev=0 --tags)...HEAD --no-merges --pretty=format:"* [%h](http://github.com/${TRAVIS_REPO_SLUG}/commit/%H) %s (%cN)" diff --git a/composer.json b/composer.json index 8b9d26b..f9a6026 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,8 @@ ], "require-dev": { "phpunit/phpunit": "^8.0", - "broadway/coding-standard": "^1.0" + "broadway/coding-standard": "^1.0", + "phpstan/phpstan": "@stable" }, "autoload": { "psr-4": { diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..9d52fd9 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,2 @@ +parameters: + checkMissingIterableValueType: false diff --git a/src/ElasticSearchRepository.php b/src/ElasticSearchRepository.php index 202069d..15553fc 100644 --- a/src/ElasticSearchRepository.php +++ b/src/ElasticSearchRepository.php @@ -25,10 +25,19 @@ */ class ElasticSearchRepository implements Repository { + /** @var Client */ private $client; + + /** @var Serializer */ private $serializer; + + /** @var string */ private $index; + + /** @var string */ private $class; + + /** @var string[] */ private $notAnalyzedFields; public function __construct( @@ -121,7 +130,7 @@ public function remove($id): void } } - private function searchAndDeserializeHits(array $query) + private function searchAndDeserializeHits(array $query): array { try { $result = $this->client->search($query); @@ -153,7 +162,7 @@ protected function search(array $query, array $facets = [], int $size = 500): ar } } - protected function query(array $query) + protected function query(array $query): array { return $this->searchAndDeserializeHits( [ @@ -183,7 +192,7 @@ private function buildFindAllQuery(): array ]; } - private function deserializeHit(array $hit) + private function deserializeHit(array $hit): Identifiable { return $this->serializer->deserialize( [ @@ -193,12 +202,12 @@ private function deserializeHit(array $hit) ); } - private function deserializeHits(array $hits) + private function deserializeHits(array $hits): array { return array_map([$this, 'deserializeHit'], $hits); } - private function buildFilter(array $filter) + private function buildFilter(array $filter): array { $retval = []; @@ -247,8 +256,6 @@ public function createIndex(): bool /** * Deletes the index for this repository's ReadModel. - * - * @return True, if the index was successfully deleted */ public function deleteIndex(): bool { diff --git a/src/ElasticSearchRepositoryFactory.php b/src/ElasticSearchRepositoryFactory.php index a26bb72..d78e486 100644 --- a/src/ElasticSearchRepositoryFactory.php +++ b/src/ElasticSearchRepositoryFactory.php @@ -23,7 +23,10 @@ */ class ElasticSearchRepositoryFactory implements RepositoryFactory { + /** @var Client */ private $client; + + /** @var Serializer */ private $serializer; public function __construct(Client $client, Serializer $serializer)