Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPStan level 4 #2080

Merged
merged 1 commit into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
* Updated `symfony/phpunit-bridge` to `6.0` by @franmomu [#2067](https://github.com/ruflin/Elastica/pull/2067)
* Updated `php-cs-fixer` to `3.8.0` [#2074](https://github.com/ruflin/Elastica/pull/2074)
* Increased `PHPStan` level to `4` [#2080](https://github.com/ruflin/Elastica/pull/2080)
### Deprecated
* Deprecated `Elastica\Reindex::WAIT_FOR_COMPLETION_FALSE`, use a boolean as parameter instead by @franmomu [#2070](https://github.com/ruflin/Elastica/pull/2070)
* Passing anything else than a boolean as 1st argument to `Reindex::setWaitForCompletion`, pass a boolean instead by @franmomu [#2070](https://github.com/ruflin/Elastica/pull/2070)
Expand Down
40 changes: 40 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
parameters:
ignoreErrors:
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
path: src/Client.php

-
message: "#^Method Elastica\\\\QueryBuilder\\:\\:aggregation\\(\\) should return Elastica\\\\QueryBuilder\\\\DSL\\\\Aggregation but returns Elastica\\\\QueryBuilder\\\\Facade\\.$#"
count: 1
Expand Down Expand Up @@ -75,6 +80,31 @@ parameters:
count: 1
path: tests/DocumentTest.php

-
message: "#^Dead catch \\- Elastica\\\\Exception\\\\InvalidException is never thrown in the try block\\.$#"
count: 1
path: tests/DocumentTest.php

-
message: "#^Expression \"\\$document\\-\\>field5\" on a separate line does not do anything\\.$#"
count: 1
path: tests/DocumentTest.php

-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
path: tests/DocumentTest.php

-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
path: tests/IndexTest.php

-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 2
path: tests/Multi/SearchTest.php

-
message: "#^Call to an undefined method ReflectionType\\:\\:getName\\(\\)\\.$#"
count: 2
Expand All @@ -95,6 +125,16 @@ parameters:
count: 1
path: tests/QueryBuilderTest.php

-
message: "#^Expression \"\\$index\\-\\>search\\('elastica search'\\)\\[3\\]\" on a separate line does not do anything\\.$#"
count: 1
path: tests/ResultSetTest.php

-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
path: tests/SnapshotTest.php

-
message: "#^Call to an undefined method GuzzleHttp\\\\Exception\\\\TransferException\\:\\:getRequest\\(\\)\\.$#"
count: 6
Expand Down
3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ includes:
- phpstan-baseline.neon

parameters:
level: 3
level: 4
paths:
- src
- tests
excludePaths:
- src/Transport/HttpAdapter.php
- src/Query/Match.php
treatPhpDocTypesAsCertain: false
ignoreErrors:
# we don't have different constructors for parent/child
- '~^Unsafe usage of new static\(\)\.$~'
10 changes: 6 additions & 4 deletions tests/Collapse/CollapseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ public function testSetInnerHitsOverridesExistingValue(): void
$collapse->setInnerHits($innerHits1);
$collapse->addInnerHits($innerHits2);

$this->assertCount(2, $collapse->getParam('inner_hits'));
$this->assertIsArray($collapse->getParam('inner_hits'));
$this->assertEquals($innerHits1, $collapse->getParam('inner_hits')[0]);
$this->assertEquals($innerHits2, $collapse->getParam('inner_hits')[1]);
$innerHits = $collapse->getParam('inner_hits');

$this->assertCount(2, $innerHits);
$this->assertIsArray($innerHits);
$this->assertEquals($innerHits1, $innerHits[0]);
$this->assertEquals($innerHits2, $innerHits[1]);
Comment on lines +115 to +120
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been changed to not confuse PHPStan, because below there is this call:

$this->assertInstanceOf(InnerHits::class, $collapse->getParam('inner_hits'));

So without this change, this was the error:

 ------ -------------------------------------------------------------------------------------------------------------------------------------------
  Line   tests/Collapse/CollapseTest.php
 ------ -------------------------------------------------------------------------------------------------------------------------------------------
  125    Call to method PHPUnit\Framework\Assert::assertInstanceOf() with 'Elastica\\Collapse\\InnerHits' and array will always evaluate to false.
 ------ -------------------------------------------------------------------------------------------------------------------------------------------


$innerHitsOverride = new InnerHits();
$innerHitsOverride->setName('override');
Expand Down