Repository navigation
Keep the analysed PHP version as the floor of a PHP_VERSION_ID < X guard #6746
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
base: 2.3.x
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 |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace PHPStan\Rules\Classes; | ||
|
|
||
| use PHPStan\Rules\Rule; | ||
| use PHPStan\Testing\RuleTestCase; | ||
| use PHPUnit\Framework\Attributes\RequiresPhp; | ||
|
|
||
| /** | ||
| * @extends RuleTestCase<InvalidPromotedPropertiesRule> | ||
| */ | ||
| class InvalidPromotedPropertiesRulePhpVersionRangeTest extends RuleTestCase | ||
| { | ||
|
|
||
| protected function getRule(): Rule | ||
| { | ||
| return new InvalidPromotedPropertiesRule(); | ||
| } | ||
|
|
||
| #[RequiresPhp('>= 8.0.0')] | ||
| public function testBug15425(): void | ||
| { | ||
| $this->analyse([__DIR__ . '/data/bug-15425-range.php'], [ | ||
| [ | ||
| 'Promoted properties are supported only on PHP 8.0 and later.', | ||
| 10, | ||
| ], | ||
| ]); | ||
| } | ||
|
|
||
| public static function getAdditionalConfigFiles(): array | ||
| { | ||
| return [ | ||
| __DIR__ . '/invalidPromotedPropertiesPhpVersionRange.neon', | ||
| ]; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace PHPStan\Rules\Classes; | ||
|
|
||
| use PHPStan\Rules\Rule; | ||
| use PHPStan\Testing\RuleTestCase; | ||
| use PHPUnit\Framework\Attributes\RequiresPhp; | ||
|
|
||
| /** | ||
| * @extends RuleTestCase<ReadOnlyClassRule> | ||
| */ | ||
| class ReadOnlyClassRulePhp81Test extends RuleTestCase | ||
| { | ||
|
|
||
| protected function getRule(): Rule | ||
| { | ||
| return new ReadOnlyClassRule(); | ||
| } | ||
|
|
||
| #[RequiresPhp('>= 8.2.0')] | ||
| public function testBug15425(): void | ||
| { | ||
| $this->analyse([__DIR__ . '/data/bug-15425-readonly.php'], [ | ||
| [ | ||
| 'Readonly classes are supported only on PHP 8.2 and later.', | ||
| 8, | ||
| ], | ||
| ]); | ||
| } | ||
|
|
||
| public static function getAdditionalConfigFiles(): array | ||
| { | ||
| return [ | ||
| __DIR__ . '/readOnlyClassPhp81.neon', | ||
| ]; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "require": { | ||
| "php": "<8.4" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?php // lint >= 8.0 | ||
|
|
||
| declare(strict_types = 1); | ||
|
|
||
| namespace Bug15425Range; | ||
|
|
||
| if (PHP_VERSION_ID < 80300) { | ||
| final class Foo | ||
| { | ||
| public function __construct(public ?string $message = null) | ||
| { | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?php // lint >= 8.2 | ||
|
|
||
| declare(strict_types = 1); | ||
|
|
||
| namespace Bug15425Readonly; | ||
|
|
||
| if (PHP_VERSION_ID < 80400) { | ||
| final readonly class Foo | ||
| { | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?php // lint >= 8.0 | ||
|
|
||
| declare(strict_types = 1); | ||
|
|
||
| namespace Bug15425; | ||
|
|
||
| if (PHP_VERSION_ID < 80400) { | ||
|
Contributor
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. please add another variant of this condition in the test in which the previously reported false-positive-error would be valid |
||
| final class Foo | ||
| { | ||
| public function __construct(public ?string $message = null) | ||
| { | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (PHP_VERSION_ID < 80000) { | ||
| final class Bar | ||
| { | ||
| public function __construct(public ?string $message = null) | ||
| { | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| parameters: | ||
|
Contributor
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. Why do we need this config? |
||
| # composer.json "php": "<8.4" gives a version range without a lower bound | ||
| composerAutoloaderProjectPaths: | ||
| - %rootDir%/tests/PHPStan/Rules/Classes/data/bug-15425-composer | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| parameters: | ||
| phpVersion: 80100 |
Uh oh!
There was an error while loading. Please reload this page.
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.
Why do we need the composer.json files? I think the
PHP_VERSION_ID < 80400should be enough.does the expected behaviour only reproduce with a composer.json?