Skip to content
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

Utilize composer min-php version to narrow PHP_VERSION_ID #2968

Open
wants to merge 19 commits into
base: 1.10.x
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/e2e-tests.yml
Expand Up @@ -237,6 +237,30 @@ jobs:
cd e2e/baseline-uninit-prop-trait
../../bin/phpstan analyse --configuration test-no-baseline.neon --generate-baseline test-baseline.neon
../../bin/phpstan analyse --configuration test.neon
- script: |
cd e2e/composer-max-version
composer install
../../bin/phpstan analyze test.php --level=0
- script: |
cd e2e/composer-min-max-version
composer install
../../bin/phpstan analyze test.php --level=0
- script: |
cd e2e/composer-min-open-end-version
composer install
../../bin/phpstan analyze test.php --level=0
- script: |
cd e2e/composer-min-version-bc
composer install
../../bin/phpstan analyze test.php --level=0
- script: |
cd e2e/composer-min-version
composer install
../../bin/phpstan analyze test.php --level=0
- script: |
cd e2e/composer-version-config
composer install
../../bin/phpstan analyze test.php --level=0

steps:
- name: "Checkout"
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/static-analysis.yml
Expand Up @@ -60,6 +60,11 @@ jobs:
shell: bash
run: "vendor/bin/simple-downgrade downgrade -c build/downgrade.php ${{ matrix.php-version }}"

- name: "Downgrade composer/semver for brianium/paratest:4.0.0 compatibility"
if: matrix.php-version == '7.2'
run: composer require composer/semver:"3.4.0 as 1.7.2"
shell: bash

- name: "Paratest patch"
if: matrix.php-version == '7.2'
run: composer config extra.patches.brianium/paratest --json --merge '["patches/paratest.patch"]'
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Expand Up @@ -191,6 +191,10 @@ jobs:
shell: bash
run: "vendor/bin/simple-downgrade downgrade -c build/downgrade.php ${{ matrix.php-version }}"

- name: "Downgrade composer/semver for brianium/paratest:4.0.0 compatibility"
run: composer require composer/semver:"3.4.0 as 1.7.2"
shell: bash

- name: "Paratest patch"
run: composer config extra.patches.brianium/paratest --json --merge '["patches/paratest.patch"]'
shell: bash
Expand Down
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -9,6 +9,7 @@
"composer-runtime-api": "^2.0",
"clue/ndjson-react": "^1.0",
"composer/ca-bundle": "^1.2",
"composer/semver": "^3.4",
"composer/xdebug-handler": "^3.0.3",
"fidry/cpu-core-counter": "^0.5.0",
"hoa/compiler": "3.17.08.08",
Expand Down
83 changes: 82 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion conf/config.neon
Expand Up @@ -374,8 +374,16 @@ services:
-
class: PHPStan\Php\PhpVersionFactoryFactory
arguments:
versionId: %phpVersion%
phpVersion: %phpVersion%
composerAutoloaderProjectPaths: %composerAutoloaderProjectPaths%
bleedingEdge: %featureToggles.bleedingEdge%

-
class: PHPStan\Php\ComposerPhpVersionFactory
arguments:
phpVersion: %phpVersion%
composerAutoloaderProjectPaths: %composerAutoloaderProjectPaths%
bleedingEdge: %featureToggles.bleedingEdge%

-
class: PHPStan\PhpDocParser\Lexer\Lexer
Expand Down
8 changes: 7 additions & 1 deletion conf/parametersSchema.neon
Expand Up @@ -131,7 +131,13 @@ parametersSchema:
minimumNumberOfJobsPerProcess: int(),
buffer: int()
])
phpVersion: schema(anyOf(schema(int(), min(70100), max(80399))), nullable())
phpVersion: schema(anyOf(
schema(int(), min(70100), max(80399)),
structure([
min: schema(int(), min(70100), max(80399)),
max: schema(int(), min(70100), max(80399))
])
), nullable())
polluteScopeWithLoopInitialAssignments: bool()
polluteScopeWithAlwaysIterableForeach: bool()
propertyAlwaysWrittenTags: listOf(string())
Expand Down
2 changes: 2 additions & 0 deletions e2e/composer-max-version/.gitignore
@@ -0,0 +1,2 @@
/vendor/
composer.lock
5 changes: 5 additions & 0 deletions e2e/composer-max-version/composer.json
@@ -0,0 +1,5 @@
{
"require": {
"php": "<=8.3"
}
}
2 changes: 2 additions & 0 deletions e2e/composer-max-version/phpstan.neon
@@ -0,0 +1,2 @@
includes:
- ../../conf/bleedingEdge.neon
10 changes: 10 additions & 0 deletions e2e/composer-max-version/test.php
@@ -0,0 +1,10 @@
<?php

\PHPStan\Testing\assertType('int<50207, 80300>', PHP_VERSION_ID);
\PHPStan\Testing\assertType('int<5, 8>', PHP_MAJOR_VERSION);
\PHPStan\Testing\assertType('int<0, max>', PHP_MINOR_VERSION);
\PHPStan\Testing\assertType('int<0, max>', PHP_RELEASE_VERSION);

\PHPStan\Testing\assertType('-1|0|1', version_compare(PHP_VERSION, '7.0.0'));
\PHPStan\Testing\assertType('bool', version_compare(PHP_VERSION, '7.0.0', '<'));
\PHPStan\Testing\assertType('bool', version_compare(PHP_VERSION, '7.0.0', '>'));
2 changes: 2 additions & 0 deletions e2e/composer-min-max-version/.gitignore
@@ -0,0 +1,2 @@
/vendor/
composer.lock
5 changes: 5 additions & 0 deletions e2e/composer-min-max-version/composer.json
@@ -0,0 +1,5 @@
{
"require": {
"php": ">=8.1, <=8.2.99"
}
}
2 changes: 2 additions & 0 deletions e2e/composer-min-max-version/phpstan.neon
@@ -0,0 +1,2 @@
includes:
- ../../conf/bleedingEdge.neon
10 changes: 10 additions & 0 deletions e2e/composer-min-max-version/test.php
@@ -0,0 +1,10 @@
<?php

\PHPStan\Testing\assertType('int<80099, 80299>', PHP_VERSION_ID);
\PHPStan\Testing\assertType('8', PHP_MAJOR_VERSION);
\PHPStan\Testing\assertType('int<0, 2>', PHP_MINOR_VERSION);
Comment on lines +3 to +5
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
\PHPStan\Testing\assertType('int<80099, 80299>', PHP_VERSION_ID);
\PHPStan\Testing\assertType('8', PHP_MAJOR_VERSION);
\PHPStan\Testing\assertType('int<0, 2>', PHP_MINOR_VERSION);
\PHPStan\Testing\assertType('int<80100, 80299>', PHP_VERSION_ID);
\PHPStan\Testing\assertType('8', PHP_MAJOR_VERSION);
\PHPStan\Testing\assertType('int<1, 2>', PHP_MINOR_VERSION);

AFAK PHP_VERSION_ID starts with the major/minor even if run on alpha release

PHP_MINOR_VERSION should be narrowed if PHP_MAJOR_VERSION is one constant number

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I saw it. But I do not support it. The reason is composer already check this during runtime and if the check is really, really wanted, the user should ignore that error instead.

\PHPStan\Testing\assertType('int<0, max>', PHP_RELEASE_VERSION);

\PHPStan\Testing\assertType('1', version_compare(PHP_VERSION, '7.0.0'));
\PHPStan\Testing\assertType('false', version_compare(PHP_VERSION, '7.0.0', '<'));
\PHPStan\Testing\assertType('true', version_compare(PHP_VERSION, '7.0.0', '>'));
2 changes: 2 additions & 0 deletions e2e/composer-min-open-end-version/.gitignore
@@ -0,0 +1,2 @@
/vendor/
composer.lock
5 changes: 5 additions & 0 deletions e2e/composer-min-open-end-version/composer.json
@@ -0,0 +1,5 @@
{
"require": {
"php": ">= 8.1"
}
}
2 changes: 2 additions & 0 deletions e2e/composer-min-open-end-version/phpstan.neon
@@ -0,0 +1,2 @@
includes:
- ../../conf/bleedingEdge.neon
6 changes: 6 additions & 0 deletions e2e/composer-min-open-end-version/test.php
@@ -0,0 +1,6 @@
<?php

\PHPStan\Testing\assertType('int<80099, max>', PHP_VERSION_ID);
\PHPStan\Testing\assertType('int<8, max>', PHP_MAJOR_VERSION);
\PHPStan\Testing\assertType('int<0, max>', PHP_MINOR_VERSION);
\PHPStan\Testing\assertType('int<0, max>', PHP_RELEASE_VERSION);
2 changes: 2 additions & 0 deletions e2e/composer-min-version-bc/.gitignore
@@ -0,0 +1,2 @@
/vendor/
composer.lock
5 changes: 5 additions & 0 deletions e2e/composer-min-version-bc/composer.json
@@ -0,0 +1,5 @@
{
"require": {
"php": "^8.1"
}
}
7 changes: 7 additions & 0 deletions e2e/composer-min-version-bc/test.php
@@ -0,0 +1,7 @@
<?php

// no bleeding edge enabled
\PHPStan\Testing\assertType('int<50207, max>', PHP_VERSION_ID);
\PHPStan\Testing\assertType('int<5, max>', PHP_MAJOR_VERSION);
\PHPStan\Testing\assertType('int<0, max>', PHP_MINOR_VERSION);
\PHPStan\Testing\assertType('int<0, max>', PHP_RELEASE_VERSION);
2 changes: 2 additions & 0 deletions e2e/composer-min-version/.gitignore
@@ -0,0 +1,2 @@
/vendor/
composer.lock
5 changes: 5 additions & 0 deletions e2e/composer-min-version/composer.json
@@ -0,0 +1,5 @@
{
"require": {
"php": "^8.1"
}
}
2 changes: 2 additions & 0 deletions e2e/composer-min-version/phpstan.neon
@@ -0,0 +1,2 @@
includes:
- ../../conf/bleedingEdge.neon
6 changes: 6 additions & 0 deletions e2e/composer-min-version/test.php
@@ -0,0 +1,6 @@
<?php

\PHPStan\Testing\assertType('int<80099, 90000>', PHP_VERSION_ID);
\PHPStan\Testing\assertType('int<8, 9>', PHP_MAJOR_VERSION);
\PHPStan\Testing\assertType('int<0, max>', PHP_MINOR_VERSION);
\PHPStan\Testing\assertType('int<0, max>', PHP_RELEASE_VERSION);
2 changes: 2 additions & 0 deletions e2e/composer-version-config-patch/.gitignore
@@ -0,0 +1,2 @@
/vendor/
composer.lock
5 changes: 5 additions & 0 deletions e2e/composer-version-config-patch/composer.json
@@ -0,0 +1,5 @@
{
"require": {
"php": ">=8.0.2, <8.0.15"
}
}
2 changes: 2 additions & 0 deletions e2e/composer-version-config-patch/phpstan.neon
@@ -0,0 +1,2 @@
includes:
- ../../conf/bleedingEdge.neon
7 changes: 7 additions & 0 deletions e2e/composer-version-config-patch/test.php
@@ -0,0 +1,7 @@
<?php

// constraint from composer.json is overruled by phpstan.neon config
\PHPStan\Testing\assertType('int<80001, 80015>', PHP_VERSION_ID);
\PHPStan\Testing\assertType('8', PHP_MAJOR_VERSION);
\PHPStan\Testing\assertType('0', PHP_MINOR_VERSION);
\PHPStan\Testing\assertType('int<1, 15>', PHP_RELEASE_VERSION);
2 changes: 2 additions & 0 deletions e2e/composer-version-config/.gitignore
@@ -0,0 +1,2 @@
/vendor/
composer.lock
5 changes: 5 additions & 0 deletions e2e/composer-version-config/composer.json
@@ -0,0 +1,5 @@
{
"require": {
"php": "^8.0"
}
}
6 changes: 6 additions & 0 deletions e2e/composer-version-config/phpstan.neon
@@ -0,0 +1,6 @@
includes:
- ../../conf/bleedingEdge.neon
parameters:
phpVersion:
min: 80103
max: 80304
11 changes: 11 additions & 0 deletions e2e/composer-version-config/test.php
@@ -0,0 +1,11 @@
<?php

// constraint from composer.json is overruled by phpstan.neon config
\PHPStan\Testing\assertType('int<80103, 80304>', PHP_VERSION_ID);
\PHPStan\Testing\assertType('8', PHP_MAJOR_VERSION);
\PHPStan\Testing\assertType('int<1, 3>', PHP_MINOR_VERSION);
\PHPStan\Testing\assertType('int<0, max>', PHP_RELEASE_VERSION);

\PHPStan\Testing\assertType('1', version_compare(PHP_VERSION, '7.0.0'));
\PHPStan\Testing\assertType('false', version_compare(PHP_VERSION, '7.0.0', '<'));
\PHPStan\Testing\assertType('true', version_compare(PHP_VERSION, '7.0.0', '>'));