Skip to content

Commit 289ecd0

Browse files
authored
RequiredPhpVersionVisitor: report promoted properties as requiring PHP 8.0 (#5882)
1 parent c7307df commit 289ecd0

26 files changed

Lines changed: 40 additions & 32 deletions

‎build/PHPStan/Build/RequiredPhpVersionVisitor.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ public function enterNode(Node $node): ?Node
8888
$this->require(self::PHP_8_1, 'readonly properties', $node);
8989
}
9090

91+
if ($node instanceof Node\Param && $node->flags !== 0) {
92+
$this->require(self::PHP_8_0, 'promoted properties', $node);
93+
}
94+
9195
if ($node instanceof Node\Param && ($node->flags & Modifiers::READONLY) !== 0) {
9296
$this->require(self::PHP_8_1, 'readonly promoted properties', $node);
9397
}

‎tests/PHPStan/Analyser/data/bug-7116.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<?php declare(strict_types = 1);
2-
1+
<?php // lint >= 8.0
2+
declare(strict_types = 1);
33
namespace Bug7116;
44

55
#[\Attribute(\Attribute::TARGET_CLASS)]

‎tests/PHPStan/Analyser/nsrt/assert-constructor.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php // lint >= 8.0
22

33
namespace AssertConstructor;
44

‎tests/PHPStan/Analyser/nsrt/assert-this.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php // lint >= 8.0
22

33
namespace AssertThis;
44

‎tests/PHPStan/Analyser/nsrt/bug-13851.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<?php declare(strict_types=1);
2-
1+
<?php // lint >= 8.0
2+
declare(strict_types=1);
33
namespace Bug13851;
44

55
use function PHPStan\Testing\assertType;

‎tests/PHPStan/Analyser/nsrt/bug-14645.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php // lint >= 8.0
22

33
namespace Bug14645;
44

‎tests/PHPStan/Analyser/nsrt/bug-6633.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<?php declare(strict_types = 1);
2-
1+
<?php // lint >= 8.0
2+
declare(strict_types = 1);
33
namespace Bug6633;
44

55
use function PHPStan\Testing\assertType;

‎tests/PHPStan/Analyser/nsrt/bug-8008.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php // lint >= 8.0
22

33
namespace Bug8008;
44

‎tests/PHPStan/Analyser/nsrt/bug-9455.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php // lint >= 8.0
22

33
namespace Bug9455;
44

‎tests/PHPStan/Build/RequiredPhpVersionCommentTest.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ public static function dataDetectedVersion(): iterable
122122
yield 'mixed property type' => ['<?php class Foo { public mixed $x; }', 80000];
123123
yield 'enum' => ['<?php enum Foo { case A; }', 80100];
124124
yield 'readonly property' => ['<?php class Foo { public readonly int $x; }', 80100];
125+
yield 'promoted property' => ['<?php class Foo { public function __construct(public int $x) {} }', 80000];
126+
yield 'promoted property protected' => ['<?php class Foo { public function __construct(protected int $x) {} }', 80000];
127+
yield 'promoted property private' => ['<?php class Foo { public function __construct(private int $x) {} }', 80000];
128+
yield 'non-promoted parameter' => ['<?php class Foo { public function __construct(int $x) {} }', null];
125129
yield 'readonly promoted property' => ['<?php class Foo { public function __construct(public readonly int $x) {} }', 80100];
126130
yield 'union type' => ['<?php function foo(A|B $x) {}', 80000];
127131
yield 'union return type' => ['<?php function foo(): A|B {}', 80000];

0 commit comments

Comments
 (0)