Skip to content

Commit e6d7a26

Browse files
committed
Merge branch 'master' into syde-phpcs
2 parents 94c891d + c1f999e commit e6d7a26

31 files changed

+280
-175
lines changed

.gitattributes

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
* text eol=lf
22

3-
tests export-ignore
4-
.psalm export-ignore
5-
.github export-ignore
6-
.gitattributes export-ignore
7-
.gitignore export-ignore
8-
README.md export-ignore
9-
phpcs.xml.dist export-ignore
10-
phpunit.xml.dist export-ignore
11-
psalm.xml export-ignore
3+
*.php diff=php
4+
5+
/.github/ export-ignore
6+
/docs/ export-ignore
7+
/tests/ export-ignore
8+
/.gitattributes export-ignore
9+
/.gitignore export-ignore
10+
/README.md export-ignore
11+
/phpcs.xml.dist export-ignore
12+
/phpstan.neon.dist export-ignore
13+
/phpunit.xml.dist export-ignore

.github/workflows/php-qa.yml

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ on:
66
- '**workflows/php-qa.yml'
77
- '**.php'
88
- '**phpcs.xml.dist'
9-
- '**psalm.xml'
9+
- '**phpstan.neon.dist'
1010
- '**composer.json'
1111
pull_request:
1212
paths:
1313
- '**workflows/php-qa.yml'
1414
- '**.php'
1515
- '**phpcs.xml.dist'
16-
- '**psalm.xml'
16+
- '**phpstan.neon.dist'
1717
- '**composer.json'
1818
workflow_dispatch:
1919
inputs:
@@ -25,7 +25,7 @@ on:
2525
options:
2626
- 'Run all'
2727
- 'Run PHPCS only'
28-
- 'Run Psalm only'
28+
- 'Run PHPStan only'
2929
- 'Run lint only'
3030

3131
concurrency:
@@ -38,7 +38,7 @@ jobs:
3838
uses: inpsyde/reusable-workflows/.github/workflows/lint-php.yml@main
3939
strategy:
4040
matrix:
41-
php: [ '7.4', '8.0', '8.1', '8.2', '8.3' ]
41+
php: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]
4242
with:
4343
PHP_VERSION: ${{ matrix.php }}
4444
LINT_ARGS: '-e php --colors --show-deprecated ./src'
@@ -50,11 +50,10 @@ jobs:
5050
PHP_VERSION: '8.3'
5151

5252
static-code-analysis:
53-
if: ${{ (github.event_name != 'workflow_dispatch') || ((github.event.inputs.jobs == 'Run all') || (github.event.inputs.jobs == 'Run Psalm only')) }}
53+
if: ${{ (github.event_name != 'workflow_dispatch') || ((github.event.inputs.jobs == 'Run all') || (github.event.inputs.jobs == 'Run PHPStan only')) }}
5454
uses: inpsyde/reusable-workflows/.github/workflows/static-analysis-php.yml@main
5555
strategy:
5656
matrix:
5757
php: [ '7.4', '8.0', '8.1', '8.2', '8.3' ]
5858
with:
5959
PHP_VERSION: ${{ matrix.php }}
60-
PSALM_ARGS: --output-format=github --no-suggestions --no-cache --no-diff --find-unused-psalm-suppress

.github/workflows/php-unit-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050

5151
- name: Setup dependencies for PSR-11 target version
5252
run: |
53-
composer remove inpsyde/php-coding-standards inpsyde/wp-stubs-versions vimeo/psalm --dev --no-update
53+
composer remove inpsyde/php-coding-standards --dev --no-update
5454
composer require "psr/container:${{ matrix.container-versions }}" --no-update
5555
composer config --no-plugins allow-plugins.roots/wordpress-core-installer false
5656

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ When installed for development via Composer, the package also requires:
2525

2626
* inpsyde/php-coding-standards
2727
* roots/wordpress
28-
* vimeo/psalm
28+
* phpstan/phpstan
2929
* phpunit/phpunit
3030
* brain/monkey
3131
* mikey179/vfsstream
@@ -38,6 +38,7 @@ When installed for development via Composer, the package also requires:
3838
4. [Properties](docs/Properties.md)
3939
5. [Application Flow](docs/Application-flow.md)
4040

41-
## License
41+
## Copyright and License
42+
43+
This package is [free software](https://www.gnu.org/philosophy/free-sw.en.html) distributed under the terms of the GNU General Public License version 2 or (at your option) any later version. For the full license, see [LICENSE](./LICENSE).
4244

43-
This repository is a free software, and is released under the terms of the GNU General Public License version 2 or (at your option) any later version. See [LICENSE](./LICENSE) for complete license.

composer.json

+13-8
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@
2828
"require-dev": {
2929
"brain/monkey": "^2.6.1",
3030
"inpsyde/wp-stubs-versions": "dev-latest",
31-
"roots/wordpress-no-content": "@dev",
3231
"mikey179/vfsstream": "^v1.6.11",
32+
"phpstan/phpstan": "^2.1.1",
33+
"phpstan/phpstan-deprecation-rules": "^2.0.1",
34+
"phpstan/phpstan-mockery": "^2.0.0",
35+
"phpstan/phpstan-phpunit": "^2.0.4",
3336
"phpunit/phpunit": "^9.6.19",
34-
"vimeo/psalm": "^5.24.0",
35-
"syde/phpcs": "^1@dev"
37+
"roots/wordpress-no-content": "@dev",
38+
"swissspidy/phpstan-no-private": "^v1.0.0",
39+
"syde/phpcs": "^1.0.0"
3640
},
3741
"extra": {
3842
"branch-alias": {
@@ -53,13 +57,13 @@
5357
"minimum-stability": "dev",
5458
"prefer-stable": true,
5559
"scripts": {
56-
"cs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs",
57-
"psalm": "@php ./vendor/vimeo/psalm/psalm --no-suggestions --report-show-info=false --find-unused-psalm-suppress --no-diff --no-cache --no-file-cache --output-format=compact",
60+
"phpcs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs",
61+
"phpstan": "@php ./vendor/bin/phpstan analyse --memory-limit=1G",
5862
"tests": "@php ./vendor/phpunit/phpunit/phpunit --no-coverage",
5963
"tests:coverage": "@php ./vendor/phpunit/phpunit/phpunit",
6064
"qa": [
61-
"@cs",
62-
"@psalm",
65+
"@phpcs",
66+
"@phpstan",
6367
"@tests"
6468
]
6569
},
@@ -68,6 +72,7 @@
6872
"composer/*": true,
6973
"inpsyde/*": true,
7074
"dealerdirect/phpcodesniffer-composer-installer": true
71-
}
75+
},
76+
"sort-packages": true
7277
}
7378
}

docs/README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ When installed for development, via Composer, the package also requires:
3030

3131
* inpsyde/php-coding-standards
3232
* roots/wordpress
33-
* vimeo/psalm
33+
* phpstan/phpstan
3434
* phpunit/phpunit
3535
* brain/monkey
3636
* mikey179/vfsstream
3737

3838

3939

40-
## License
41-
This repository is a free software, and is released under the terms of the GNU General Public License version 2 or (at your option) any later version. See [LICENSE](https://github.com/inpsyde/modularity/blob/master/LICENSE) for complete license.
40+
## Copyright and License
41+
42+
This package is [free software](https://www.gnu.org/philosophy/free-sw.en.html) distributed under the terms of the GNU General Public License version 2 or (at your option) any later version. For the full license, see [LICENSE](https://github.com/inpsyde/modularity/blob/HEAD/LICENSE).
43+

phpcs.xml.dist

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
<file>./src</file>
1616
<file>./tests</file>
17+
<exclude-pattern>./tests/unit/stubs.php</exclude-pattern>
1718

1819
<!-- Use colors, and show sniff error codes and progress. -->
1920
<arg name="colors" />

phpstan.neon.dist

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
includes:
2+
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
3+
- vendor/phpstan/phpstan-mockery/extension.neon
4+
- vendor/phpstan/phpstan-phpunit/extension.neon
5+
- vendor/swissspidy/phpstan-no-private/rules.neon
6+
parameters:
7+
level: 8
8+
dynamicConstantNames:
9+
- WP_DEBUG
10+
scanFiles:
11+
- vendor/inpsyde/wp-stubs-versions/latest.php
12+
paths:
13+
- src/
14+
- tests/
15+
treatPhpDocTypesAsCertain: false
16+
ignoreErrors:
17+
-
18+
message: '#Call to static method PHPUnit\\Framework\\Assert::assertInstanceOf\(\) .* will always evaluate to true.#'
19+
path: tests/*

psalm.xml

-32
This file was deleted.

src/Container/ContainerConfigurator.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use Psr\Container\ContainerInterface;
88

99
/**
10-
* @psalm-import-type Service from \Inpsyde\Modularity\Module\ServiceModule
11-
* @psalm-import-type ExtendingService from \Inpsyde\Modularity\Module\ExtendingModule
10+
* @phpstan-import-type Service from \Inpsyde\Modularity\Module\ServiceModule
11+
* @phpstan-import-type ExtendingService from \Inpsyde\Modularity\Module\ExtendingModule
1212
*/
1313
class ContainerConfigurator
1414
{
@@ -113,7 +113,7 @@ public function hasExtension(string $id): bool
113113
/**
114114
* @return ContainerInterface
115115
*
116-
* @psalm-assert ContainerInterface $this->compiledContainer
116+
* @phpstan-assert ContainerInterface $this->compiledContainer
117117
*/
118118
public function createReadOnlyContainer(): ContainerInterface
119119
{

src/Container/PackageProxyContainer.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public function has(string $id): bool
4444
/**
4545
* @return bool
4646
*
47-
* @psalm-assert-if-true ContainerInterface $this->container
48-
* @psalm-assert-if-false null $this->container
47+
* @phpstan-assert-if-true ContainerInterface $this->container
48+
* @phpstan-assert-if-false null $this->container
4949
*/
5050
private function tryContainer(): bool
5151
{
@@ -67,7 +67,7 @@ private function tryContainer(): bool
6767
* @param string $id
6868
* @return void
6969
*
70-
* @psalm-assert ContainerInterface $this->container
70+
* @phpstan-assert ContainerInterface $this->container
7171
*/
7272
private function assertPackageBooted(string $id): void
7373
{

src/Container/ReadOnlyContainer.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
use Psr\Container\NotFoundExceptionInterface;
99

1010
/**
11-
* @psalm-import-type Service from \Inpsyde\Modularity\Module\ServiceModule
12-
* @psalm-import-type ExtendingService from \Inpsyde\Modularity\Module\ExtendingModule
11+
* @phpstan-import-type Service from \Inpsyde\Modularity\Module\ServiceModule
12+
* @phpstan-import-type ExtendingService from \Inpsyde\Modularity\Module\ExtendingModule
1313
*/
1414
class ReadOnlyContainer implements ContainerInterface
1515
{
@@ -26,7 +26,7 @@ class ReadOnlyContainer implements ContainerInterface
2626
/**
2727
* @param array<string, Service> $services
2828
* @param array<string, bool> $factoryIds
29-
* @param ServiceExtensions|array $extensions
29+
* @param ServiceExtensions|array<string, ExtendingService> $extensions
3030
* @param ContainerInterface[] $containers
3131
*/
3232
public function __construct(

src/Container/ServiceExtensions.php

+14-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Psr\Container\ContainerInterface as Container;
88

99
/**
10-
* @psalm-import-type ExtendingService from \Inpsyde\Modularity\Module\ExtendingModule
10+
* @phpstan-import-type ExtendingService from \Inpsyde\Modularity\Module\ExtendingModule
1111
*/
1212
class ServiceExtensions
1313
{
@@ -20,6 +20,7 @@ class ServiceExtensions
2020

2121
/**
2222
* @param string $type
23+
*
2324
* @return string
2425
*/
2526
final public static function typeId(string $type): string
@@ -30,18 +31,22 @@ final public static function typeId(string $type): string
3031
/**
3132
* @param string $extensionId
3233
* @param ExtendingService $extender
34+
*
3335
* @return static
3436
*/
3537
public function add(string $extensionId, callable $extender): ServiceExtensions
3638
{
37-
isset($this->extensions[$extensionId]) or $this->extensions[$extensionId] = [];
39+
if (!isset($this->extensions[$extensionId])) {
40+
$this->extensions[$extensionId] = [];
41+
}
3842
$this->extensions[$extensionId][] = $extender;
3943

4044
return $this;
4145
}
4246

4347
/**
4448
* @param string $extensionId
49+
*
4550
* @return bool
4651
*/
4752
public function has(string $extensionId): bool
@@ -53,6 +58,7 @@ public function has(string $extensionId): bool
5358
* @param mixed $service
5459
* @param string $id
5560
* @param Container $container
61+
*
5662
* @return mixed
5763
*/
5864
final public function resolve($service, string $id, Container $container)
@@ -68,6 +74,7 @@ final public function resolve($service, string $id, Container $container)
6874
* @param string $id
6975
* @param mixed $service
7076
* @param Container $container
77+
*
7178
* @return mixed
7279
*/
7380
protected function resolveById(string $id, $service, Container $container)
@@ -83,7 +90,8 @@ protected function resolveById(string $id, $service, Container $container)
8390
* @param string $className
8491
* @param object $service
8592
* @param Container $container
86-
* @param array $extendedClasses
93+
* @param string[] $extendedClasses
94+
*
8795
* @return mixed
8896
*
8997
* phpcs:disable SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
@@ -110,8 +118,7 @@ protected function resolveByType(
110118
}
111119

112120
// 2nd group of extensions: targeting parent classes
113-
$parents = class_parents($service, false);
114-
($parents === false) and $parents = [];
121+
$parents = class_parents($service, false) ?: [];
115122
foreach ($parents as $parentName) {
116123
$byParent = $this->extensions[self::typeId($parentName)] ?? null;
117124
if (($byParent !== null) && ($byParent !== [])) {
@@ -120,8 +127,7 @@ protected function resolveByType(
120127
}
121128

122129
// 3rd group of extensions: targeting implemented interfaces
123-
$interfaces = class_implements($service, false);
124-
($interfaces === false) and $interfaces = [];
130+
$interfaces = class_implements($service, false) ?: [];
125131
foreach ($interfaces as $interfaceName) {
126132
$byInterface = $this->extensions[self::typeId($interfaceName)] ?? null;
127133
if (($byInterface !== null) && ($byInterface !== [])) {
@@ -163,6 +169,7 @@ protected function resolveByType(
163169
* @param object $service
164170
* @param Container $container
165171
* @param list<ExtendingService> $extenders
172+
*
166173
* @return list{mixed, int}
167174
*/
168175
private function extendByType(

src/Module/ExtendingModule.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Psr\Container\ContainerInterface;
88

99
/**
10-
* @psalm-type ExtendingService = callable(mixed $service, ContainerInterface $container):mixed
10+
* @phpstan-type ExtendingService callable(mixed $service, ContainerInterface $container): mixed
1111
*/
1212
interface ExtendingModule extends Module
1313
{

src/Module/FactoryModule.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Inpsyde\Modularity\Module;
66

77
/**
8-
* @psalm-import-type Service from ServiceModule
8+
* @phpstan-import-type Service from ServiceModule
99
*/
1010
interface FactoryModule extends Module
1111
{

0 commit comments

Comments
 (0)