-
Notifications
You must be signed in to change notification settings - Fork 94
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
Update to PHPStan level 3; various fixes #281
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
parameters: | ||
level: 1 | ||
level: 3 | ||
paths: | ||
- src | ||
- tests |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,8 @@ public function __construct(Gherkin $gherkin) | |
public function supports($resource) | ||
{ | ||
return is_string($resource) | ||
&& is_dir($this->findAbsolutePath($resource)); | ||
&& ($path = $this->findAbsolutePath($resource)) !== false | ||
&& is_dir($path); | ||
} | ||
|
||
/** | ||
|
@@ -57,6 +58,9 @@ public function supports($resource) | |
public function load($resource) | ||
{ | ||
$path = $this->findAbsolutePath($resource); | ||
if ($path === false) { | ||
throw new \LogicException("Unable to locate absolute path of supported resource: $resource"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hope that what is happening here is clear - it should not be possible for this exception to be thrown unless something happens between calling |
||
} | ||
|
||
$iterator = new RecursiveIteratorIterator( | ||
new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ class OutlineNode implements ScenarioInterface | |
*/ | ||
private $steps; | ||
/** | ||
* @var ExampleTableNode|ExampleTableNode[] | ||
* @var array<array-key, ExampleTableNode> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the (original) constructor code, this property could never contain a singular value. |
||
*/ | ||
private $tables; | ||
/** | ||
|
@@ -52,7 +52,7 @@ class OutlineNode implements ScenarioInterface | |
* @param string|null $title | ||
* @param string[] $tags | ||
* @param StepNode[] $steps | ||
* @param ExampleTableNode|ExampleTableNode[] $tables | ||
* @param ExampleTableNode|array<array-key, ExampleTableNode> $tables | ||
* @param string $keyword | ||
* @param int $line | ||
*/ | ||
|
@@ -69,11 +69,7 @@ public function __construct( | |
$this->steps = $steps; | ||
$this->keyword = $keyword; | ||
$this->line = $line; | ||
if (!is_array($tables)) { | ||
$this->tables = [$tables]; | ||
} else { | ||
$this->tables = $tables; | ||
} | ||
$this->tables = is_array($tables) ? $tables : [$tables]; | ||
} | ||
|
||
/** | ||
|
@@ -197,7 +193,7 @@ public function getExamples() | |
/** | ||
* Returns examples tables array for the outline. | ||
* | ||
* @return ExampleTableNode[] | ||
* @return array<array-key, ExampleTableNode> | ||
*/ | ||
public function getExampleTables() | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
|
||
class LineFilterTest extends FilterTestCase | ||
{ | ||
public function testIsFeatureMatchFilter() | ||
public function testIsFeatureMatchFilter(): void | ||
{ | ||
$feature = new FeatureNode(null, null, [], null, [], null, null, null, 1); | ||
|
||
|
@@ -32,7 +32,7 @@ public function testIsFeatureMatchFilter() | |
$this->assertFalse($filter->isFeatureMatch($feature)); | ||
} | ||
|
||
public function testIsScenarioMatchFilter() | ||
public function testIsScenarioMatchFilter(): void | ||
{ | ||
$scenario = new ScenarioNode(null, [], [], null, 2); | ||
|
||
|
@@ -54,7 +54,7 @@ public function testIsScenarioMatchFilter() | |
$this->assertTrue($filter->isScenarioMatch($outline)); | ||
} | ||
|
||
public function testFilterFeatureScenario() | ||
public function testFilterFeatureScenario(): void | ||
{ | ||
$filter = new LineFilter(2); | ||
$feature = $filter->filterFeature($this->getParsedFeature()); | ||
|
@@ -71,19 +71,20 @@ public function testFilterFeatureScenario() | |
$this->assertCount(0, $scenarios = $feature->getScenarios()); | ||
} | ||
|
||
public function testFilterFeatureOutline() | ||
public function testFilterFeatureOutline(): void | ||
{ | ||
$filter = new LineFilter(13); | ||
$feature = $filter->filterFeature($this->getParsedFeature()); | ||
/* @var OutlineNode[] $scenarios */ | ||
$this->assertCount(1, $scenarios = $feature->getScenarios()); | ||
$this->assertSame('Scenario#3', $scenarios[0]->getTitle()); | ||
$this->assertInstanceOf(OutlineNode::class, $scenarios[0]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These |
||
$this->assertCount(4, $scenarios[0]->getExampleTable()->getRows()); | ||
|
||
$filter = new LineFilter(20); | ||
$feature = $filter->filterFeature($this->getParsedFeature()); | ||
$this->assertCount(1, $scenarios = $feature->getScenarios()); | ||
$this->assertSame('Scenario#3', $scenarios[0]->getTitle()); | ||
$this->assertInstanceOf(OutlineNode::class, $scenarios[0]); | ||
$exampleTableNodes = $scenarios[0]->getExampleTables(); | ||
$this->assertCount(1, $exampleTableNodes); | ||
$this->assertCount(2, $exampleTableNodes[0]->getRows()); | ||
|
@@ -97,6 +98,7 @@ public function testFilterFeatureOutline() | |
$feature = $filter->filterFeature($this->getParsedFeature()); | ||
$this->assertCount(1, $scenarios = $feature->getScenarios()); | ||
$this->assertSame('Scenario#3', $scenarios[0]->getTitle()); | ||
$this->assertInstanceOf(OutlineNode::class, $scenarios[0]); | ||
$exampleTableNodes = $scenarios[0]->getExampleTables(); | ||
$this->assertCount(1, $exampleTableNodes); | ||
$this->assertCount(2, $exampleTableNodes[0]->getRows()); | ||
|
@@ -110,6 +112,7 @@ public function testFilterFeatureOutline() | |
$feature = $filter->filterFeature($this->getParsedFeature()); | ||
$this->assertCount(1, $scenarios = $feature->getScenarios()); | ||
$this->assertSame('Scenario#3', $scenarios[0]->getTitle()); | ||
$this->assertInstanceOf(OutlineNode::class, $scenarios[0]); | ||
$this->assertCount(1, $scenarios[0]->getExampleTable()->getRows()); | ||
$this->assertSame([['action', 'outcome']], $scenarios[0]->getExampleTable()->getRows()); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't see any better way to solve this - downstream users with PHPStan that extended this class will now get warnings, unless they fix it in a similar way to (for example), the
DirectoryLoader
changes in this PR.