Skip to content
Open
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 .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
- 'e2e/applied-polyfill-php80'
- 'e2e/config-dist-fallback'
- 'e2e/config-file-priority'
- 'e2e/custom-file-extensions'
- 'e2e/only-option'
- 'e2e/parallel-custom-config'
- 'e2e/parallel-unused-skips'
Expand Down
1 change: 1 addition & 0 deletions e2e/custom-file-extensions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor
5 changes: 5 additions & 0 deletions e2e/custom-file-extensions/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"php": "^8.1"
}
}
22 changes: 22 additions & 0 deletions e2e/custom-file-extensions/expected-output.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1 file with changes
===================

1) src/ChildService.inc:4

---------- begin diff ----------
@@ Line 4 @@

class ChildService extends ParentService
{
- public function run($value)
+ public function run($value, $flag = false)
{
}
}
----------- end diff -----------

Applied rules:
* AddParamBasedOnParentClassMethodRector


[OK] 1 file would have been changed (dry-run) by Rector
11 changes: 11 additions & 0 deletions e2e/custom-file-extensions/rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector;

return RectorConfig::configure()
->withPaths([__DIR__ . '/src'])
->withFileExtensions(['php', 'inc'])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this should be differentiate between file extension scanned by rector and phpstan I guess, since scanned by rector means it will fixable via rector.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A file that Rector processes has to be scanned by PHPStan as well: otherwise, since 2.8, any rule that needs the reflection of a class in it throws "should be known at this point", which is what happened to the 116 .inc files of the project in the issue. So this passes only the extensions Rector processes. PHPStan can still scan more than Rector changes: a fileExtensions list from a config given to withPHPStanConfigs() is merged with it (I checked with module added on top of this e2e project). On main, such a config is also the workaround for the issue, as the e2e project passes with fileExtensions: [php, inc] in it. Would you rather keep that workaround and document it, or have a separate option for the PHPStan list?

->withRules([AddParamBasedOnParentClassMethodRector::class]);
10 changes: 10 additions & 0 deletions e2e/custom-file-extensions/src/ChildService.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App;

class ChildService extends ParentService
{
public function run($value)
{
}
}
10 changes: 10 additions & 0 deletions e2e/custom-file-extensions/src/ParentService.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App;

class ParentService
{
public function run($value, $flag = false)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ public function __construct()
$this->container = $containerFactory->create(
SimpleParameterProvider::provideStringParameter(Option::CONTAINER_CACHE_DIRECTORY),
$additionalConfigFiles,
[]
[],
// let PHPStan find classes in files with any configured extension, not only in *.php ones
additionalParameters: [
'fileExtensions' => SimpleParameterProvider::provideArrayParameter(Option::FILE_EXTENSIONS),
]
);
} catch (Throwable $throwable) {
if ($throwable->getMessage() === "File 'phar://phpstan.phar/conf/bleedingEdge.neon' is missing or is not readable.") {
Expand Down
Loading