From 66155dc594d3074e8948d3a01302ae952f658e23 Mon Sep 17 00:00:00 2001 From: Romanchenko Olexy Date: Thu, 22 Nov 2018 11:24:24 +0200 Subject: [PATCH] Fix phpstan warnings and enhance check (#38) --- .travis.yml | 4 ++-- composer.json | 3 ++- phpstan.neon | 6 ++++++ src/Entity/Search/Response.php | 2 +- src/Entity/Suggestion/Response.php | 2 +- src/Locator/HttpClientLocator.php | 5 +++-- tests/Service/SearchServiceTest.php | 14 +++++++------- 7 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 phpstan.neon diff --git a/.travis.yml b/.travis.yml index 51ecc73..c8fe03a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ php: - 7 - 7.1 - 7.2 -# - nightly // phpcs not support 7.3 yet + - nightly install: - composer self-update before_script: @@ -14,7 +14,7 @@ script: - ./bin/phpcs --standard=psr12 src - ./bin/phpmd src text cleancode,codesize,controversial,design,unusedcode - ./bin/phpcpd src - - ./bin/phpstan analyse -n --no-ansi --level=1 src tests + - ./bin/phpstan analyse -n --no-ansi --level=7 src tests -c phpstan.neon after_success: - ./bin/pdepend --summary-xml=/tmp/summary.xml --jdepend-chart=/tmp/jdepend.svg --overview-pyramid=/tmp/pyramid.svg src - ./bin/phploc src diff --git a/composer.json b/composer.json index bbadb01..957f346 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,8 @@ "phpmd/phpmd" : "^2.6", "pdepend/pdepend": "^2.5", "phploc/phploc": "^4.0", - "phpstan/phpstan": "^0.9|^0.10" + "phpstan/phpstan": "^0.9|^0.10", + "phpstan/phpstan-phpunit": "^0.9|^0.10.0" }, "config": { "bin-dir": "bin" diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..0e58b85 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,6 @@ +includes: + - vendor/phpstan/phpstan-phpunit/extension.neon + - vendor/phpstan/phpstan-phpunit/rules.neon +parameters: + excludes_analyse: + - src/DependencyInjection/Configuration.php diff --git a/src/Entity/Search/Response.php b/src/Entity/Search/Response.php index eff9391..2ed3f6b 100644 --- a/src/Entity/Search/Response.php +++ b/src/Entity/Search/Response.php @@ -51,7 +51,7 @@ class Response private $timing; /** - * @var ArrayCollection + * @var ArrayCollection<\Printdeal\PandosearchBundle\Entity\Suggestion> * @Serializer\Type("ArrayCollection") */ private $suggestions; diff --git a/src/Entity/Suggestion/Response.php b/src/Entity/Suggestion/Response.php index dd6ebb3..f45e58d 100644 --- a/src/Entity/Suggestion/Response.php +++ b/src/Entity/Suggestion/Response.php @@ -14,7 +14,7 @@ class Response protected $hits = []; /** - * @var ArrayCollection + * @var ArrayCollection<\Printdeal\PandosearchBundle\Entity\Suggestion> * @Serializer\Type("ArrayCollection") */ private $suggestions; diff --git a/src/Locator/HttpClientLocator.php b/src/Locator/HttpClientLocator.php index ecab11c..47e8414 100644 --- a/src/Locator/HttpClientLocator.php +++ b/src/Locator/HttpClientLocator.php @@ -55,8 +55,9 @@ public function getClient(string $localization = self::DEFAULT_GUZZLE_CLIENT): C return $this->clients[$localization]; } - if (count($this->clients) === 1) { - return reset($this->clients); + $client = reset($this->clients); + if ($client instanceof ClientInterface) { + return $client; } throw new ClientNotFoundException($localization); diff --git a/tests/Service/SearchServiceTest.php b/tests/Service/SearchServiceTest.php index 07b1400..859892d 100644 --- a/tests/Service/SearchServiceTest.php +++ b/tests/Service/SearchServiceTest.php @@ -7,7 +7,7 @@ use JMS\Serializer\Exception\UnsupportedFormatException; use JMS\Serializer\SerializerInterface; use PHPUnit\Framework\TestCase; -use \PHPUnit_Framework_MockObject_MockObject as Mock; +use PHPUnit\Framework\MockObject\MockObject as Mock; use Printdeal\PandosearchBundle\Criteria\SearchCriteria; use Printdeal\PandosearchBundle\Criteria\SuggestCriteria; use Printdeal\PandosearchBundle\Exception\ClientNotFoundException; @@ -24,9 +24,9 @@ class SearchServiceTest extends TestCase { /** - * @param Mock|null $clientLocator - * @param Mock|null $queryBuilder - * @param Mock|null $serializer + * @param HttpClientLocator|Mock $clientLocator + * @param QueryBuilder|Mock $queryBuilder + * @param SerializerInterface|Mock $serializer * @return SearchService */ private function getSearchServiceMock( @@ -34,21 +34,21 @@ private function getSearchServiceMock( Mock $queryBuilder = null, Mock $serializer = null ) { - if (!$clientLocator) { + if (is_null($clientLocator)) { /** @var HttpClientLocator $clientLocator */ $clientLocator = $this->getMockBuilder(HttpClientLocator::class) ->disableOriginalConstructor() ->getMock(); } - if (!$queryBuilder) { + if (is_null($queryBuilder)) { /** @var QueryBuilder $queryBuilder */ $queryBuilder = $this->getMockBuilder(QueryBuilder::class) ->disableOriginalConstructor() ->getMock(); } - if (!$serializer) { + if (is_null($serializer)) { /** @var SerializerInterface $serializer */ $serializer = $this->getMockBuilder(SerializerInterface::class) ->disableOriginalConstructor()