Skip to content

Commit dbda484

Browse files
committed
Update phpstan and call it with PHP 7.4 and 8.0
1 parent 343b81c commit dbda484

File tree

18 files changed

+154
-39
lines changed

18 files changed

+154
-39
lines changed

bin/ci/phpstan

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,33 @@ readonly ROOT_DIR="$(realpath "$(dirname "$(realpath "$0")")/../..")"
66

77
source "${ROOT_DIR}"/bin/ci/dockerise.inc.bash
88

9-
phpstan \
10-
analyse \
11-
--ansi \
12-
--configuration config/ci/phpstan.neon
9+
phpVersion=
10+
phpstanParameters=
11+
clearCache=false
12+
for arg in "${@}"; do
13+
if [ "${arg:0:6}" == "--php=" ]; then
14+
phpVersion="${arg:6}"
15+
elif [ "${arg}" == "--clear-cache" ]; then
16+
clearCache=true
17+
else
18+
phpstanParameters="${phpstanParameters} ${arg}"
19+
fi
20+
done
21+
22+
if [ "${clearCache}" == true ] && [ -d "${ROOT_DIR}"/var/ci/phpstan ]; then
23+
echo "Clear cache"
24+
rm -rf "${ROOT_DIR}"/var/ci/phpstan
25+
fi
26+
27+
if [ "${phpVersion}" == "" ]; then
28+
php8.0 "${ROOT_DIR}"/bin/ci/phpstan.php ${phpstanParameters}
29+
else
30+
echo "PHP ${phpVersion}"
31+
32+
"php${phpVersion}" \
33+
"${PHPSTAN_BIN_PATH}" \
34+
analyse \
35+
--ansi \
36+
--configuration config/ci/phpstan.php-"${phpVersion}".neon \
37+
${phpstanParameters}
38+
fi

bin/ci/phpstan.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Steevanb\ParallelProcess\{
6+
Console\Application\ParallelProcessesApplication,
7+
Process\Process,
8+
Process\ProcessArray
9+
};
10+
use steevanb\PhpTypedArray\ScalarArray\StringArray;
11+
use Symfony\Component\Console\Input\ArgvInput;
12+
13+
require $_SERVER['COMPOSER_HOME'] . '/vendor/autoload.php';
14+
require dirname(__DIR__, 2) . '/vendor/autoload.php';
15+
16+
function createPhpstanProcesses(): ProcessArray
17+
{
18+
$phpVersions = new StringArray(['7.4', '8.0']);
19+
20+
$return = new ProcessArray();
21+
foreach ($phpVersions as $loopPhpVersion) {
22+
$return[] = createPhpstanProcess($loopPhpVersion);
23+
}
24+
25+
return $return;
26+
}
27+
28+
function createPhpstanProcess(string $phpVersion): Process
29+
{
30+
return (new Process([__DIR__ . '/phpstan', '--php=' . $phpVersion]))
31+
->setName('phpstan --php=' . $phpVersion);
32+
}
33+
34+
(new ParallelProcessesApplication())
35+
->addProcesses(createPhpstanProcesses())
36+
->run(new ArgvInput($argv));

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Create configurations for Docker images name
77
- Create configuration for repository version
88
- Create configuration for Composer version
9+
- Rework bin/ci/shellcheck to find files to check instead of having a list
910

1011
### [0.2.1](../../compare/0.2.0...0.2.1) - 2022-01-08
1112

config/ci/phpstan.neon

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
parameters:
22
level: 8
3-
tmpDir: ../../var/ci/phpstan
43
paths:
54
- ../../src
5+
- ../../tests
66
ignoreErrors:
7+
# I can't remove this phpstan error because of the bad typehint of Symfony
78
- '#Method Steevanb\\ParallelProcess\\Console\\Output\\ConsoleBufferedOutput\:\:write\(\) has parameter \$messages with no value type specified in iterable type iterable.#'
8-
- '#Parameter \#2 \$env \(array\<string\>\) of method Steevanb\\ParallelProcess\\Process\\Process\:\:start\(\) should be contravariant with parameter \$env \(array\) of method Symfony\\Component\\Process\\Process\:\:start\(\)#'
9+
# I can't remove this phpstan error because of the bad typehint of Symfony
10+
- '#Method Steevanb\\ParallelProcess\\Tests\\Console\\Output\\TestOutput::write\(\) has parameter \$messages with no value type specified in iterable type iterable.#'
11+
# I can't remove this phpstan error because of the bad typehint of Symfony
12+
- '#Method Steevanb\\ParallelProcess\\Tests\\Console\\Output\\TestOutput::writeln\(\) has parameter \$messages with no value type specified in iterable type iterable.#'
913
includes:
14+
- ../../vendor/steevanb/php-typed-array/bridge/Phpstan/rules.neon
1015
- /composer/common/vendor/phpstan/phpstan-deprecation-rules/rules.neon
16+
- /composer/common/vendor/phpstan/phpstan-phpunit/rules.neon
1117
- /composer/common/vendor/phpstan/phpstan-strict-rules/rules.neon
12-
- ../../vendor/steevanb/php-typed-array/bridge/Phpstan/rules.neon
18+
- /composer/common/vendor/spaze/phpstan-disallowed-calls/extension.neon
19+
- /composer/common/vendor/spaze/phpstan-disallowed-calls/disallowed-dangerous-calls.neon
20+
- /composer/common/vendor/spaze/phpstan-disallowed-calls/disallowed-execution-calls.neon
21+
- /composer/common/vendor/spaze/phpstan-disallowed-calls/disallowed-insecure-calls.neon
22+
- /composer/common/vendor/spaze/phpstan-disallowed-calls/disallowed-loose-calls.neon
23+
rules:
24+
- Ergebnis\PHPStan\Rules\Classes\PHPUnit\Framework\TestCaseWithSuffixRule
25+
- Ergebnis\PHPStan\Rules\Expressions\NoErrorSuppressionRule
26+
- Ergebnis\PHPStan\Rules\Expressions\NoIssetRule
27+
- Ergebnis\PHPStan\Rules\Files\DeclareStrictTypesRule

config/ci/phpstan.php-7.4.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
includes:
2+
- phpstan.neon
3+
parameters:
4+
tmpDir: ../../var/ci/phpstan/php-7-4

config/ci/phpstan.php-8.0.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
includes:
2+
- phpstan.neon
3+
parameters:
4+
tmpDir: ../../var/ci/phpstan/php-8-0

docker/ci/Dockerfile

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ ENV COMPOSER_HOME_SYMFONY_5_1=/composer/symfony-5-1
1212
ENV COMPOSER_HOME_SYMFONY_5_2=/composer/symfony-5-2
1313
ENV COMPOSER_HOME_SYMFONY_5_3=/composer/symfony-5-3
1414

15+
ENV PHPSTAN_BIN_PATH=/usr/local/bin/phpstan
16+
1517
COPY docker/ci/global.composer.json ${COMPOSER_HOME}/composer.json
1618

1719
RUN \
@@ -34,12 +36,14 @@ RUN \
3436
php8.0-xdebug \
3537

3638
# Install CI tools
37-
&& composer global require \
38-
phpstan/phpstan:0.12.* \
39-
phpstan/phpstan-deprecation-rules:0.12.* \
40-
phpstan/phpstan-phpunit:0.12.* \
41-
phpstan/phpstan-strict-rules:0.12.* \
42-
phpstan/phpstan-symfony:0.12.* \
39+
&& php7.4 /usr/local/bin/composer global require \
40+
phpstan/phpstan:1.2.* \
41+
phpstan/phpstan-deprecation-rules:1.0.* \
42+
phpstan/phpstan-strict-rules:1.1. \
43+
phpstan/phpstan-phpunit:1.0.* \
44+
phpstan/phpstan-symfony:1.0.* \
45+
spaze/phpstan-disallowed-calls:2.2.* \
46+
ergebnis/phpstan-rules:1.0.* \
4347
maglnet/composer-require-checker:3.3.* \
4448
wapmorgan/php-deprecation-detector:2.0.* \
4549
steevanb/php-code-sniffs:4.2.* \
@@ -49,7 +53,7 @@ RUN \
4953
&& ln -s ${COMPOSER_HOME}/vendor/bin/composer-require-checker /usr/local/bin/composer-require-checker \
5054
&& ln -s ${COMPOSER_HOME}/vendor/bin/phpdd /usr/local/bin/phpdd \
5155
&& ln -s ${COMPOSER_HOME}/vendor/bin/phpcs /usr/local/bin/phpcs \
52-
&& ln -s ${COMPOSER_HOME}/vendor/bin/phpstan /usr/local/bin/phpstan \
56+
&& ln -s ${COMPOSER_HOME}/vendor/bin/phpstan ${PHPSTAN_BIN_PATH} \
5357
&& ln -s ${COMPOSER_HOME}/vendor/bin/unused_scanner /usr/local/bin/unused-scanner \
5458
&& ln -s ${COMPOSER_HOME}/vendor/bin/infection /usr/local/bin/infection \
5559

@@ -59,7 +63,7 @@ RUN \
5963

6064
# Install Symfony components \
6165
&& COMPOSER_HOME=${COMPOSER_HOME_SYMFONY_5_0} \
62-
composer global require symfony/process:5.0.* symfony/console:5.2.* \
66+
composer global require symfony/process:5.0.* symfony/console:5.2.* \
6367
&& COMPOSER_HOME=${COMPOSER_HOME_SYMFONY_5_1} \
6468
composer global require symfony/process:5.1.* symfony/console:5.2.* \
6569
&& COMPOSER_HOME=${COMPOSER_HOME_SYMFONY_5_2} \

src/Process/Process.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function isSpreadErrorToApplicationExitCode(): bool
171171
return $this->spreadErrorToApplicationExitCode;
172172
}
173173

174-
/** @param array<string> $env */
174+
/** @param array<mixed> $env */
175175
public function start(callable $callback = null, array $env = []): void
176176
{
177177
parent::start($callback, $env);

tests/Console/Application/Theme/DefaultTheme/OutputProcessStateTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
use PHPUnit\Framework\TestCase;
88
use Steevanb\ParallelProcess\{
99
Console\Application\Theme\DefaultTheme,
10-
Process\Process,
1110
Process\ProcessArray,
1211
Tests\Console\Output\TestOutput,
1312
Tests\CreateLsProcessTrait
1413
};
15-
use Symfony\Component\Process\Exception\LogicException;
1614

1715
final class OutputProcessStateTest extends TestCase
1816
{
@@ -31,11 +29,9 @@ public function testEmptyNotStarted(): void
3129

3230
public function testNotStarted(): void
3331
{
34-
$this->expectException(LogicException::class);
35-
3632
(new DefaultTheme())->outputProcessesState(
3733
new TestOutput(),
38-
new ProcessArray($this->createLsProcess())
34+
new ProcessArray([$this->createLsProcess()])
3935
);
4036
}
4137

tests/Console/Application/Theme/DefaultTheme/OutputSummaryTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
use PHPUnit\Framework\TestCase;
88
use Steevanb\ParallelProcess\{
99
Console\Application\Theme\DefaultTheme,
10-
Process\Process,
10+
Exception\ParallelProcessException,
1111
Process\ProcessArray,
1212
Tests\Console\Output\TestOutput,
1313
Tests\CreateLsProcessTrait
1414
};
15-
use Symfony\Component\Process\Exception\LogicException;
1615

1716
final class OutputSummaryTest extends TestCase
1817
{
@@ -31,11 +30,13 @@ public function testEmptyNotStarted(): void
3130

3231
public function testNotStarted(): void
3332
{
34-
$this->expectException(LogicException::class);
33+
$this->expectException(ParallelProcessException::class);
34+
$this->expectExceptionMessage('Unknown process state.');
35+
$this->expectExceptionCode(0);
3536

3637
(new DefaultTheme())->outputSummary(
3738
new TestOutput(),
38-
new ProcessArray($this->createLsProcess())
39+
new ProcessArray([$this->createLsProcess()])
3940
);
4041
}
4142

0 commit comments

Comments
 (0)