Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcbfa60e

Browse files
authored
Add PHPStan (#6851)
1 parente6ddcb0 commitcbfa60e

File tree

18 files changed

+189
-117
lines changed

18 files changed

+189
-117
lines changed

‎.github/workflows/build.yml‎

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,66 @@
11
on:
22
pull_request:
3-
branches-ignore:gh-pages
3+
branches-ignore:
4+
-gh-pages
45
push:
56
branches:
67
-main
78

89
name:build
910

11+
concurrency:
12+
group:build-${{ github.ref }}
13+
cancel-in-progress:true
14+
1015
permissions:
1116
contents:read
17+
actions:write
18+
19+
env:
20+
PHP_INI_VALUES:memory_limit=-1,date.timezone=UTC
21+
COMPOSER_ROOT_VERSION:5.0.99
22+
SYMFONY_DEPRECATIONS_HELPER:weak
1223

1324
jobs:
1425
phpcs:
15-
name:Code style
26+
name:Code style & Static Analysis
1627
runs-on:ubuntu-latest
1728
steps:
1829
-name:Checkout
1930
uses:actions/checkout@v3
2031

21-
-name:Install PHP
32+
-name:Install PHP & tools
2233
uses:shivammathur/setup-php@v2
2334
with:
2435
php-version:'8.2'
25-
ini-values:memory_limit=-1, date.timezone='UTC'
26-
tools:phpcs
36+
ini-values:${{ env.PHP_INI_VALUES }}
37+
tools:phpcs, composer:v2, phpstan
38+
39+
-name:Install dependencies
40+
run:composer install --no-interaction --no-progress --ansi
2741

2842
-name:Check production code style
2943
run:composer cs-prod
3044

3145
-name:Check test code style
3246
run:composer cs-tests
3347

34-
linux:
35-
name:PHP ${{ matrix.php }}-${{ matrix.os }}-${{ matrix.mode }}
48+
-name:PHPStan
49+
run:phpstan analyse src
3650

51+
linux:
52+
name:PHP ${{ matrix.php }}–${{ matrix.os }}–${{ matrix.mode }}
53+
runs-on:${{ matrix.os }}
3754
env:
38-
extensions:curl, mbstring, openssl, pdo, pdo_sqlite
39-
SYMFONY_DEPRECATIONS_HELPER:weak
40-
COMPOSER_ROOT_VERSION:5.0.99
55+
extensions:curl, mbstring, openssl, pdo, pdo_sqlite, zip
4156
COLUMNS:120
42-
43-
runs-on:${{ matrix.os }}
44-
4557
strategy:
4658
fail-fast:false
4759
matrix:
4860
os:[ubuntu-latest]
4961
php:['8.2', '8.3', '8.4']
5062
mode:['stable', 'experimental']
5163
exclude:
52-
-php:'8.2'
53-
mode:'experimental'
5464
-php:'8.3'
5565
mode:'experimental'
5666
-php:'8.4'
@@ -60,12 +70,12 @@ jobs:
6070
-name:Checkout
6171
uses:actions/checkout@v3
6272

63-
-name:Install PHP
73+
-name:Install PHP & Composer
6474
uses:shivammathur/setup-php@v2
6575
with:
6676
php-version:${{ matrix.php }}
6777
extensions:${{ env.extensions }}
68-
ini-values:memory_limit=-1, date.timezone='UTC'
78+
ini-values:${{ env.PHP_INI_VALUES }}
6979
coverage:xdebug
7080
tools:composer:v2
7181

@@ -84,18 +94,22 @@ jobs:
8494
run:composer self-update
8595

8696
-name:Validate composer.json
87-
run:composer validate
88-
89-
-name:Install latest versions of dependencies in stable mode
90-
if:matrix.mode == 'stable'
91-
run:composer update --no-interaction --no-progress --optimize-autoloader --ansi
97+
run:composer validate --strict
9298

93-
-name:Composer install lowest versions of dependencies on PHP 8.2 in experimental mode
94-
if:matrix.php == '8.2' && matrix.mode == 'experimental'
95-
run:composer update --prefer-lowest --no-interaction --no-progress --optimize-autoloader --ansi
99+
-name:Install / Update Dependencies
100+
run:|
101+
if [ "${{ matrix.mode }}" = "stable" ]; then
102+
composer update --no-interaction --no-progress --optimize-autoloader --ansi
103+
else
104+
composer update --prefer-lowest --no-interaction --no-progress --optimize-autoloader --ansi
105+
fi
96106
97107
-name:Test that failing test really fails
98-
run:if php codecept run -c tests/data/claypit/ scenario FailedCept -vvv; then echo "Test hasn't failed"; false; fi;
108+
run:|
109+
if php codecept run -c tests/data/claypit/ scenario FailedCept -vvv; then
110+
echo "Test hasn't failed"
111+
false
112+
fi
99113
100114
# - name: Run tests without code coverage on PHP 8.2
101115
# if: matrix.php == '8.2'
@@ -127,15 +141,12 @@ jobs:
127141
php ../../../codecept run tests/unit/Codeception/Module/PhpBrowserTest.php
128142
129143
windows-latest:
130-
name:PHP ${{ matrix.php }}-${{ matrix.os }}
131-
144+
name:PHP ${{ matrix.php }}${{ matrix.os }}
145+
runs-on:${{ matrix.os }}
132146
env:
133-
extensions:curl, mbstring, openssl, pdo, pdo_sqlite
147+
extensions:curl, mbstring, openssl, pdo, pdo_sqlite, zip
134148
SYMFONY_DEPRECATIONS_HELPER:weak
135149
COMPOSER_ROOT_VERSION:5.0.99
136-
137-
runs-on:${{ matrix.os }}
138-
139150
strategy:
140151
fail-fast:false
141152
matrix:
@@ -146,16 +157,17 @@ jobs:
146157
-name:Checkout
147158
uses:actions/checkout@v3
148159

149-
-name:Install PHP
160+
-name:Install PHP & Composer
150161
uses:shivammathur/setup-php@v2
151162
with:
152163
php-version:${{ matrix.php }}
153164
extensions:${{ env.extensions }}
154-
ini-values:memory_limit=-1, date.timezone='UTC'
165+
ini-values:${{ env.PHP_INI_VALUES }}
155166
tools:composer:v2
156167

157168
-name:Determine composer cache directory
158-
run:echo "COMPOSER_CACHE_DIR=~\\AppData\\Local\\Composer" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
169+
run:|
170+
echo "COMPOSER_CACHE_DIR=~\\AppData\\Local\\Composer" >> $GITHUB_ENV
159171
160172
-name:Cache dependencies installed with composer
161173
uses:actions/cache@v3
@@ -169,7 +181,7 @@ jobs:
169181
run:composer self-update
170182

171183
-name:Validate composer.json
172-
run:composer validate
184+
run:composer validate --strict
173185

174186
-name:Install dependencies
175187
run:composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

‎composer.json‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@
2222
"behat/gherkin":"^4.12",
2323
"codeception/lib-asserts":"^2.2",
2424
"codeception/stub":"^4.1",
25-
"phpunit/phpunit":"^9.5.20 || ^10.0 || ^11.0 || ^12.0",
26-
"phpunit/php-code-coverage":"^9.2 || ^10.0 || ^11.0 || ^12.0",
27-
"phpunit/php-text-template":"^2.0 || ^3.0 || ^4.0 || ^5.0",
28-
"phpunit/php-timer":"^5.0.3 || ^6.0 || ^7.0 || ^8.0",
29-
"sebastian/comparator":"^4.0.5 || ^5.0 || ^6.0 || ^7.0",
30-
"sebastian/diff":"^4.0.3 || ^5.0 || ^6.0 || ^7.0",
25+
"phpunit/php-code-coverage":"^9.2 | ^10.0 | ^11.0 | ^12.0",
26+
"phpunit/php-text-template":"^2.0 | ^3.0 | ^4.0 | ^5.0",
27+
"phpunit/php-timer":"^5.0.3 | ^6.0 | ^7.0 | ^8.0",
28+
"phpunit/phpunit":"^9.5.20 | ^10.0 | ^11.0 | ^12.0",
29+
"psy/psysh":"^0.11.2 | ^0.12",
30+
"sebastian/comparator":"^4.0.5 | ^5.0 | ^6.0 | ^7.0",
31+
"sebastian/diff":"^4.0.3 | ^5.0 | ^6.0 | ^7.0",
3132
"symfony/console":">=5.4.24 <8.0",
3233
"symfony/css-selector":">=5.4.24 <8.0",
3334
"symfony/event-dispatcher":">=5.4.24 <8.0",
3435
"symfony/finder":">=5.4.24 <8.0",
35-
"symfony/yaml":">=5.4.24 <8.0",
3636
"symfony/var-dumper":">=5.4.24 <8.0",
37-
"psy/psysh":"^0.11.2 || ^0.12"
37+
"symfony/yaml":">=5.4.24 <8.0"
3838
},
3939
"require-dev": {
4040
"ext-simplexml":"*",
@@ -45,11 +45,17 @@
4545
"codeception/module-db":"*@dev",
4646
"codeception/module-filesystem":"*@dev",
4747
"codeception/module-phpbrowser":"*@dev",
48+
"codeception/module-webdriver":"*@dev",
4849
"codeception/util-universalframework":"*@dev",
49-
"symfony/process":">=5.4.24 <8.0",
50+
"doctrine/orm":"^3.3",
51+
"jetbrains/phpstorm-attributes":"^1.0",
52+
"laravel-zero/phar-updater":"^1.4",
53+
"php-webdriver/webdriver":"^1.15",
54+
"stecman/symfony-console-completion":"^0.14",
5055
"symfony/dotenv":">=5.4.24 <8.0",
51-
"vlucas/phpdotenv":"^5.1",
52-
"jetbrains/phpstorm-attributes":"^1.0"
56+
"symfony/error-handler":">=5.4.24 <8.0",
57+
"symfony/process":">=5.4.24 <8.0",
58+
"vlucas/phpdotenv":"^5.1"
5359
},
5460
"conflict": {
5561
"codeception/lib-innerbrowser":"<3.1.3",

‎ext/SuiteInitSubscriberTrait.php‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespaceCodeception\Extension;
6+
7+
useCodeception\Events;
8+
9+
usefunctionis_array;
10+
11+
trait SuiteInitSubscriberTrait
12+
{
13+
publicstaticfunctiongetSubscribedEvents():array
14+
{
15+
$events =property_exists(static::class,'events') &&is_array(static::$events)
16+
?static::$events
17+
: [];
18+
19+
$suiteInit = (array) ($events[Events::SUITE_INIT] ?? []);
20+
$suiteInit[] ='receiveModuleContainer';
21+
$events[Events::SUITE_INIT] =$suiteInit;
22+
23+
return$events;
24+
}
25+
}

‎phpstan.neon‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
parameters:
2+
level:1
3+
4+
paths:
5+
- src
6+
7+
excludePaths:
8+
analyseAndScan:
9+
- src/Codeception/Test/Cest.php
10+
- src/Codeception/Test/Test.php
11+
- src/Codeception/Test/Unit.php
12+
- src/Codeception/Coverage/Subscriber/Printer.php
13+
- src/PHPUnit/Wrapper/PhpUnit9/Test.php
14+
15+
parallel:
16+
maximumNumberOfProcesses:8
17+
minimumNumberOfJobsPerProcess:2
18+
jobSize:20

‎src/Codeception/Application.php‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,14 @@ public function registerCustomCommands(): void
3434
if ($e->getCode() ===404) {
3535
return;
3636
}
37-
$this->renderExceptionWrapper($e,$output);
37+
parent::renderThrowable($e,$output);
3838
exit(1);
3939
}catch (Exception$e) {
40-
$this->renderExceptionWrapper($e,$output);
40+
parent::renderThrowable($e,$output);
4141
exit(1);
4242
}
4343
}
4444

45-
publicfunctionrenderExceptionWrapper(Exception$exception,OutputInterface$output):void
46-
{
47-
if (method_exists(BaseApplication::class,'renderException')) {
48-
//Symfony 5
49-
parent::renderException($exception,$output);
50-
}else {
51-
parent::renderThrowable($exception,$output);
52-
}
53-
}
54-
5545
/**
5646
* Search custom commands and register them.
5747
*

‎src/Codeception/Extension.php‎

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
useCodeception\Event\SuiteEvent;
88
useCodeception\Exception\ModuleRequireException;
9+
useCodeception\Extension\SuiteInitSubscriberTrait;
910
useCodeception\Lib\Console\Output;
1011
useSymfony\Component\EventDispatcher\EventSubscriberInterface;
1112

1213
usefunctionarray_keys;
1314
usefunctionarray_merge;
14-
usefunctionis_array;
1515

1616
/**
1717
* A base class for all Codeception Extensions and GroupObjects
@@ -23,6 +23,8 @@
2323
*/
2424
abstractclass Extensionimplements EventSubscriberInterface
2525
{
26+
use SuiteInitSubscriberTrait;
27+
2628
/**
2729
* @var array<int|string, mixed>
2830
*/
@@ -44,19 +46,6 @@ public function __construct(array $config, protected array $options)
4446
$this->_initialize();
4547
}
4648

47-
publicstaticfunctiongetSubscribedEvents():array
48-
{
49-
$events =property_exists(static::class,'events') &&is_array(static::$events)
50-
?static::$events
51-
: [];
52-
53-
$suiteInit = (array) ($events[Events::SUITE_INIT] ?? []);
54-
$suiteInit[] ='receiveModuleContainer';
55-
$events[Events::SUITE_INIT] =$suiteInit;
56-
57-
return$events;
58-
}
59-
6049
publicfunctionreceiveModuleContainer(SuiteEvent$event):void
6150
{
6251
$this->modules =$event->getSuite()->getModules();

‎src/Codeception/Lib/Di.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function instantiate(
8181
$constructorArgs ??=$this->prepareArgs($reflectedClass->getConstructor());
8282

8383
try {
84-
$object =$reflectedClass->newInstanceArgs($constructorArgs ?? []);
84+
$object =$reflectedClass->newInstanceArgs($constructorArgs);
8585
}catch (ReflectionException$e) {
8686
thrownewInjectionException("Failed to create instance of '{$className}'." .$e->getMessage());
8787
}

‎src/Codeception/Lib/ParamsLoader.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static function load(array|string $paramStorage): array
5858
}
5959
}
6060

61-
thrownewConfigurationException("Params can't be loaded from `{$paramFile}`.");
61+
thrownewConfigurationException("Params can't be loaded from `{$paramsFile}`.");
6262
}
6363

6464
/**

‎src/Codeception/Reporter/JUnitReporter.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,10 @@ private function addFault(Test $test, Throwable $t, string $type): void
318318
$buffer ='';
319319
}
320320

321-
if (PHPUnitVersion::series() <10) {
321+
if (
322+
version_compare(PHPUnitVersion::series(),'10.0','<')
323+
&&class_exists(TestFailure::class)
324+
) {
322325
$exceptionString = TestFailure::exceptionToString($t);
323326
}else {
324327
$exceptionString = ThrowableToStringMapper::map($t);

‎src/Codeception/Scenario.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ public function comment(string $comment): void
122122

123123
publicfunctionskip(string$message =''):void
124124
{
125-
if (PHPUnitVersion::series() <10) {
125+
if (
126+
version_compare(PHPUnitVersion::series(),'10.0','<')
127+
&&class_exists(SkippedTestError::class)
128+
) {
126129
thrownewSkippedTestError($message);
127130
}
128131
thrownewSkippedWithMessageException($message);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp