Skip to content

Commit

Permalink
incorporate feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Mar 24, 2024
1 parent 5c6a0cd commit 193f88d
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 28 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/e2e-tests.yml
Expand Up @@ -237,23 +237,27 @@ jobs:
- script: |
cd e2e/composer-max-version
composer install
../../bin/phpstan analyze test.php
../../bin/phpstan analyze test.php --level=0
- script: |
cd e2e/composer-min-max-version
composer install
../../bin/phpstan analyze test.php
../../bin/phpstan analyze test.php --level=0
- script: |
cd e2e/composer-min-open-end-version
composer install
../../bin/phpstan analyze test.php
../../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
../../bin/phpstan analyze test.php --level=0
- script: |
cd e2e/composer-version-config
composer install
../../bin/phpstan analyze test.php
../../bin/phpstan analyze test.php --level=0
steps:
- name: "Checkout"
Expand Down
2 changes: 0 additions & 2 deletions build/ignore-by-php-version.neon.php
Expand Up @@ -37,7 +37,5 @@
$config = [];
$config['includes'] = $includes;
$config['parameters']['phpVersion'] = PHP_VERSION_ID;
$config['parameters']['minPhpVersion'] = 70100;
$config['parameters']['maxPhpVersion'] = 90000;

return $config;
9 changes: 4 additions & 5 deletions conf/config.neon
Expand Up @@ -137,8 +137,6 @@ parameters:
minimumNumberOfJobsPerProcess: 2
buffer: 134217728 # 128 MB
phpVersion: null
minPhpVersion: null
maxPhpVersion: null
polluteScopeWithLoopInitialAssignments: true
polluteScopeWithAlwaysIterableForeach: true
propertyAlwaysWrittenTags: []
Expand Down Expand Up @@ -376,15 +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%
minVersion: %minPhpVersion%
maxVersion: %maxPhpVersion%
bleedingEdge: %featureToggles.bleedingEdge%

-
class: PHPStan\PhpDocParser\Lexer\Lexer
Expand Down
10 changes: 7 additions & 3 deletions conf/parametersSchema.neon
Expand Up @@ -131,9 +131,13 @@ parametersSchema:
minimumNumberOfJobsPerProcess: int(),
buffer: int()
])
phpVersion: schema(anyOf(schema(int(), min(70100), max(80399))), nullable())
minPhpVersion: schema(anyOf(schema(int(), min(70100), max(90000))), nullable())
maxPhpVersion: schema(anyOf(schema(int(), min(70100), max(90000))), 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/phpstan.neon
@@ -0,0 +1,2 @@
includes:
- ../../conf/bleedingEdge.neon
2 changes: 2 additions & 0 deletions e2e/composer-min-max-version/phpstan.neon
@@ -0,0 +1,2 @@
includes:
- ../../conf/bleedingEdge.neon
2 changes: 2 additions & 0 deletions e2e/composer-min-open-end-version/phpstan.neon
@@ -0,0 +1,2 @@
includes:
- ../../conf/bleedingEdge.neon
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"
}
}
4 changes: 4 additions & 0 deletions e2e/composer-min-version-bc/test.php
@@ -0,0 +1,4 @@
<?php

// no bleeding edge enabled
\PHPStan\Testing\assertType('int<50207, max>', PHP_VERSION_ID);
2 changes: 2 additions & 0 deletions e2e/composer-min-version/phpstan.neon
@@ -0,0 +1,2 @@
includes:
- ../../conf/bleedingEdge.neon
6 changes: 3 additions & 3 deletions e2e/composer-version-config/phpstan.neon
@@ -1,4 +1,4 @@
parameters:
level: 0
minPhpVersion: 80103
maxPhpVersion: 80304
phpVersion:
min: 80103
max: 80304
28 changes: 20 additions & 8 deletions src/Php/ComposerPhpVersionFactory.php
Expand Up @@ -8,9 +8,12 @@
use Nette\Utils\Strings;
use PHPStan\File\CouldNotReadFileException;
use PHPStan\File\FileReader;
use PHPStan\ShouldNotHappenException;
use function count;
use function end;
use function is_array;
use function is_file;
use function is_int;
use function is_string;
use function sprintf;

Expand All @@ -23,22 +26,31 @@ class ComposerPhpVersionFactory

/**
* @param string[] $composerAutoloaderProjectPaths
* @param int|array{min: int, max: int}|null $phpVersion
*/
public function __construct(
private array $composerAutoloaderProjectPaths,
?int $minVersion,
?int $maxVersion,
int|array|null $phpVersion,
bool $bleedingEdge,
)
{
if ($minVersion !== null) {
$this->minVersion = new PhpVersion($minVersion);
if (is_int($phpVersion)) {
return;
}
if ($maxVersion !== null) {
$this->maxVersion = new PhpVersion($maxVersion);

if (is_array($phpVersion)) {
if ($phpVersion['max'] < $phpVersion['min']) {
throw new ShouldNotHappenException('Invalid PHP version range: phpVersion.max should be great or equals to phpVersion.min.');
}

$this->minVersion = new PhpVersion($phpVersion['min']);
$this->maxVersion = new PhpVersion($phpVersion['max']);

return;
}

if ($minVersion !== null && $maxVersion !== null) {
return; // use values from config files
if (!$bleedingEdge) {
return;
}

// fallback to composer.json based php-version constraint
Expand Down
23 changes: 21 additions & 2 deletions src/Php/PhpVersionFactoryFactory.php
Expand Up @@ -6,20 +6,26 @@
use Nette\Utils\JsonException;
use PHPStan\File\CouldNotReadFileException;
use PHPStan\File\FileReader;
use PHPStan\ShouldNotHappenException;
use function array_key_exists;
use function count;
use function end;
use function is_array;
use function is_file;
use function is_int;
use function is_string;

class PhpVersionFactoryFactory
{

/**
* @param int|array{min: int, max: int}|null $phpVersion
* @param string[] $composerAutoloaderProjectPaths
*/
public function __construct(
private ?int $versionId,
private int|array|null $phpVersion,
private array $composerAutoloaderProjectPaths,
private bool $bleedingEdge,
)
{
}
Expand All @@ -43,7 +49,20 @@ public function create(): PhpVersionFactory
}
}

return new PhpVersionFactory($this->versionId, $composerPhpVersion);
$versionId = null;

if (is_int($this->phpVersion)) {
$versionId = $this->phpVersion;
}

if ($this->bleedingEdge && is_array($this->phpVersion)) {
if (!array_key_exists('min', $this->phpVersion)) {
throw new ShouldNotHappenException();
}
$versionId = $this->phpVersion['min'];
}

return new PhpVersionFactory($versionId, $composerPhpVersion);
}

}

0 comments on commit 193f88d

Please sign in to comment.