Skip to content

Commit a146678

Browse files
committed
Try different stubs for PHP 8.4 and 8.5+
1 parent e5bb66f commit a146678

File tree

5 files changed

+96
-3
lines changed

5 files changed

+96
-3
lines changed

conf/config.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ parameters:
77
bootstrapFiles:
88
- ../stubs/runtime/ReflectionUnionType.php
99
- ../stubs/runtime/ReflectionAttribute.php
10-
- ../stubs/runtime/Attribute.php
10+
- ../stubs/runtime/Attribute85.php
1111
- ../stubs/runtime/ReflectionIntersectionType.php
1212
excludePaths: []
1313
level: null

src/Reflection/BetterReflection/BetterReflectionSourceLocatorFactory.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use function extension_loaded;
3232
use function is_dir;
3333
use function is_file;
34+
use const PHP_VERSION_ID;
3435

3536
#[AutowiredService]
3637
final class BetterReflectionSourceLocatorFactory
@@ -76,7 +77,11 @@ public function __construct(
7677
public function create(): SourceLocator
7778
{
7879
$locators = [
79-
$this->optimizedSingleFileSourceLocatorRepository->getOrCreate(__DIR__ . '/../../../stubs/runtime/Attribute.php'),
80+
$this->optimizedSingleFileSourceLocatorRepository->getOrCreate(
81+
PHP_VERSION_ID < 80500
82+
? __DIR__ . '/../../../stubs/runtime/Attribute84.php'
83+
: __DIR__ . '/../../../stubs/runtime/Attribute85.php',
84+
),
8085
];
8186

8287
if ($this->singleReflectionFile !== null) {
File renamed without changes.

stubs/runtime/Attribute85.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
if (\PHP_VERSION_ID < 80000 && !class_exists('Attribute', false)) {
4+
#[Attribute(Attribute::TARGET_CLASS)]
5+
class Attribute
6+
{
7+
8+
/** @var int */
9+
public $flags;
10+
11+
/**
12+
* Marks that attribute declaration is allowed only in classes.
13+
*/
14+
const TARGET_CLASS = 1;
15+
16+
/**
17+
* Marks that attribute declaration is allowed only in functions.
18+
*/
19+
const TARGET_FUNCTION = 1 << 1;
20+
21+
/**
22+
* Marks that attribute declaration is allowed only in class methods.
23+
*/
24+
const TARGET_METHOD = 1 << 2;
25+
26+
/**
27+
* Marks that attribute declaration is allowed only in class properties.
28+
*/
29+
const TARGET_PROPERTY = 1 << 3;
30+
31+
/**
32+
* Marks that attribute declaration is allowed only in class constants.
33+
*/
34+
const TARGET_CLASS_CONSTANT = 1 << 4;
35+
36+
/**
37+
* Marks that attribute declaration is allowed only in function or method parameters.
38+
*/
39+
const TARGET_PARAMETER = 1 << 5;
40+
41+
/**
42+
* Marks that attribute declaration is allowed only in global constants with "const" keyword.
43+
*/
44+
const TARGET_CONSTANT = 1 << 6;
45+
46+
/**
47+
* Marks that attribute declaration is allowed anywhere.
48+
*/
49+
const TARGET_ALL = (1 << 7) - 1;
50+
51+
/**
52+
* Notes that an attribute declaration in the same place is
53+
* allowed multiple times.
54+
*/
55+
const IS_REPEATABLE = 1 << 7;
56+
57+
/**
58+
* @param int $flags A value in the form of a bitmask indicating the places
59+
* where attributes can be defined.
60+
*/
61+
public function __construct($flags = self::TARGET_ALL)
62+
{
63+
$this->flags = $flags;
64+
}
65+
66+
}
67+
}
68+
69+
if (\PHP_VERSION_ID < 80100 && !class_exists('ReturnTypeWillChange', false)) {
70+
#[Attribute(Attribute::TARGET_METHOD)]
71+
final class ReturnTypeWillChange
72+
{
73+
}
74+
}
75+
76+
if (\PHP_VERSION_ID < 80200 && !class_exists('AllowDynamicProperties', false)) {
77+
#[Attribute(Attribute::TARGET_CLASS)]
78+
final class AllowDynamicProperties
79+
{
80+
}
81+
}
82+
83+
if (\PHP_VERSION_ID < 80200 && !class_exists('SensitiveParameter', false)) {
84+
#[Attribute(Attribute::TARGET_PARAMETER)]
85+
final class SensitiveParameter
86+
{
87+
}
88+
}

tests/PHPStan/Command/CommandHelperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public static function dataParameters(): array
165165
'bootstrapFiles' => [
166166
realpath(__DIR__ . '/../../../stubs/runtime/ReflectionUnionType.php'),
167167
realpath(__DIR__ . '/../../../stubs/runtime/ReflectionAttribute.php'),
168-
realpath(__DIR__ . '/../../../stubs/runtime/Attribute.php'),
168+
realpath(__DIR__ . '/../../../stubs/runtime/Attribute85.php'),
169169
realpath(__DIR__ . '/../../../stubs/runtime/ReflectionIntersectionType.php'),
170170
__DIR__ . DIRECTORY_SEPARATOR . 'relative-paths' . DIRECTORY_SEPARATOR . 'here.php',
171171
],

0 commit comments

Comments
 (0)