Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
Fix phpstan warnings and enhance check (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avariya authored Nov 22, 2018
1 parent de8607e commit 66155dc
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ php:
- 7
- 7.1
- 7.2
# - nightly // phpcs not support 7.3 yet
- nightly
install:
- composer self-update
before_script:
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
parameters:
excludes_analyse:
- src/DependencyInjection/Configuration.php
2 changes: 1 addition & 1 deletion src/Entity/Search/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Response
private $timing;

/**
* @var ArrayCollection<Printdeal\PandosearchBundle\Entity\Suggestion>
* @var ArrayCollection<\Printdeal\PandosearchBundle\Entity\Suggestion>
* @Serializer\Type("ArrayCollection<Printdeal\PandosearchBundle\Entity\Suggestion>")
*/
private $suggestions;
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Suggestion/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Response
protected $hits = [];

/**
* @var ArrayCollection<Printdeal\PandosearchBundle\Entity\Suggestion>
* @var ArrayCollection<\Printdeal\PandosearchBundle\Entity\Suggestion>
* @Serializer\Type("ArrayCollection<Printdeal\PandosearchBundle\Entity\Suggestion>")
*/
private $suggestions;
Expand Down
5 changes: 3 additions & 2 deletions src/Locator/HttpClientLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions tests/Service/SearchServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,31 +24,31 @@
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(
Mock $clientLocator = null,
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()
Expand Down

0 comments on commit 66155dc

Please # to comment.