Skip to content

Commit 6924e46

Browse files
authored
Utilize PHP version constraint from composer.json to narrow PHP_* constants
1 parent 11998ed commit 6924e46

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+521
-21
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,48 @@ jobs:
292292
- script: |
293293
cd e2e/bug-11819
294294
../../bin/phpstan
295+
- script: |
296+
cd e2e/composer-max-version
297+
composer install
298+
../../bin/phpstan analyze test.php --level=0
299+
- script: |
300+
cd e2e/composer-min-max-version
301+
composer install
302+
../../bin/phpstan analyze test.php --level=0
303+
- script: |
304+
cd e2e/composer-min-open-end-version
305+
composer install
306+
../../bin/phpstan analyze test.php --level=0
307+
- script: |
308+
cd e2e/composer-min-version-v5
309+
composer install --ignore-platform-reqs
310+
../../bin/phpstan analyze test.php --level=0
311+
- script: |
312+
cd e2e/composer-min-version-v7
313+
composer install --ignore-platform-reqs
314+
../../bin/phpstan analyze test.php --level=0
315+
- script: |
316+
cd e2e/composer-min-version
317+
composer install
318+
../../bin/phpstan analyze test.php --level=0
319+
- script: |
320+
cd e2e/composer-no-versions
321+
composer install
322+
../../bin/phpstan analyze test.php --level=0
323+
- script: |
324+
cd e2e/composer-version-config-invalid
325+
OUTPUT=$(../bashunit -a exit_code "1" ../../bin/phpstan)
326+
echo "$OUTPUT"
327+
../bashunit -a contains 'Invalid configuration' "$OUTPUT"
328+
../bashunit -a contains 'Invalid PHP version range: phpVersion.max should be greater or equal to phpVersion.min.' "$OUTPUT"
329+
- script: |
330+
cd e2e/composer-version-config-patch
331+
composer install --ignore-platform-reqs
332+
../../bin/phpstan analyze test.php --level=0
333+
- script: |
334+
cd e2e/composer-version-config
335+
composer install
336+
../../bin/phpstan analyze test.php --level=0
295337
296338
steps:
297339
- name: "Checkout"
@@ -308,5 +350,8 @@ jobs:
308350
- name: "Install dependencies"
309351
run: "composer install --no-interaction --no-progress"
310352

353+
- name: "Install bashunit"
354+
run: "curl -s https://bashunit.typeddevs.com/install.sh | bash -s e2e/ 0.17.0"
355+
311356
- name: "Test"
312357
run: ${{ matrix.script }}

conf/config.neon

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,13 @@ services:
339339
-
340340
class: PHPStan\Php\PhpVersionFactoryFactory
341341
arguments:
342-
versionId: %phpVersion%
342+
phpVersion: %phpVersion%
343+
composerAutoloaderProjectPaths: %composerAutoloaderProjectPaths%
344+
345+
-
346+
class: PHPStan\Php\ComposerPhpVersionFactory
347+
arguments:
348+
phpVersion: %phpVersion%
343349
composerAutoloaderProjectPaths: %composerAutoloaderProjectPaths%
344350

345351
-

conf/parametersSchema.neon

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,13 @@ parametersSchema:
7979
minimumNumberOfJobsPerProcess: int(),
8080
buffer: int()
8181
])
82-
phpVersion: schema(anyOf(schema(int(), min(70100), max(80499))), nullable())
82+
phpVersion: schema(anyOf(
83+
schema(int(), min(70100), max(80499)),
84+
structure([
85+
min: schema(int(), min(70100), max(80499)),
86+
max: schema(int(), min(70100), max(80499))
87+
])
88+
), nullable())
8389
polluteScopeWithLoopInitialAssignments: bool()
8490
polluteScopeWithAlwaysIterableForeach: bool()
8591
polluteScopeWithBlock: bool()

e2e/composer-max-version/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor/
2+
composer.lock
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require": {
3+
"php": "<=8.3"
4+
}
5+
}

e2e/composer-max-version/test.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
\PHPStan\Testing\assertType('int<50207, 80300>', PHP_VERSION_ID);
4+
\PHPStan\Testing\assertType('int<5, 8>', PHP_MAJOR_VERSION);
5+
\PHPStan\Testing\assertType('int<0, max>', PHP_MINOR_VERSION);
6+
\PHPStan\Testing\assertType('int<0, max>', PHP_RELEASE_VERSION);
7+
8+
\PHPStan\Testing\assertType('-1|0|1', version_compare(PHP_VERSION, '7.0.0'));
9+
\PHPStan\Testing\assertType('bool', version_compare(PHP_VERSION, '7.0.0', '<'));
10+
\PHPStan\Testing\assertType('bool', version_compare(PHP_VERSION, '7.0.0', '>'));
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor/
2+
composer.lock
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require": {
3+
"php": ">=8.1, <=8.2.99"
4+
}
5+
}

e2e/composer-min-max-version/test.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
\PHPStan\Testing\assertType('int<80100, 80299>', PHP_VERSION_ID);
4+
\PHPStan\Testing\assertType('8', PHP_MAJOR_VERSION);
5+
\PHPStan\Testing\assertType('int<1, 2>', PHP_MINOR_VERSION);
6+
\PHPStan\Testing\assertType('int<0, max>', PHP_RELEASE_VERSION);
7+
8+
\PHPStan\Testing\assertType('1', version_compare(PHP_VERSION, '7.0.0'));
9+
\PHPStan\Testing\assertType('false', version_compare(PHP_VERSION, '7.0.0', '<'));
10+
\PHPStan\Testing\assertType('true', version_compare(PHP_VERSION, '7.0.0', '>'));
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor/
2+
composer.lock

0 commit comments

Comments
 (0)