diff --git a/README.md b/README.md
index 2eb65cdb1..a27da36ce 100644
--- a/README.md
+++ b/README.md
@@ -49,31 +49,30 @@ includes:
-Do you use mocks in your PHPUnit tests? Enable mocking rules with single parameter:
-
-```yaml
-parameters:
- mocks: true
-```
-
-
+### Symfony/Laravel container `->get()`/`->make()` return type extensions
Want sharper type inference? The return type extensions are **disabled by default** — enable the ones that fit your stack:
```yaml
parameters:
- symfonyReturnType: true
- laravelReturnType: true
- pathStrings: true
+ symplify:
+ symfonyReturnType: true
+ laravelReturnType: true
+ pathStrings: true
```
-`symfonyReturnType` resolves `$container->get(SomeService::class)` to `SomeService` and Symfony Finder's `$splFileInfo->getRealPath()` to `string`. `laravelReturnType` does the same for Laravel's `$container->make(SomeService::class)`. `pathStrings` narrows `getcwd()`, `dirname()` and `realpath()` to `string`:
+* `symfonyReturnType` resolves
+ * `$container->get(SomeService::class)` to `SomeService` and
+ * Symfony Finder's `$splFileInfo->getRealPath()` to `string`
```php
$service = $container->get(SomeService::class);
// $service is now known as SomeService, instead of plain object
```
+* `laravelReturnType` does the same for Laravel's `$container->make(SomeService::class)`
+* `pathStrings` narrows `getcwd()`, `dirname()` and `realpath()` to `string`:
+
But at start, make baby steps with one rule at a time:
@@ -90,7 +89,8 @@ Tired of ever growing ignored error count in your `phpstan.neon`? Set hard limit
```yaml
parameters:
- maximumIgnoredErrorCount: 50
+ symplify:
+ maximumIgnoredErrorCount: 50
```
@@ -123,7 +123,8 @@ This rule is disabled by default. Enable it with the `ctor` parameter:
```yaml
parameters:
- ctor: true
+ symplify:
+ ctor: true
```
@@ -2706,7 +2707,8 @@ This set is for you! Enable all mocking rules with single parameter in your `php
```yaml
parameters:
- mocks: true
+ symplify:
+ mocks: true
```
diff --git a/composer.json b/composer.json
index b79fad78e..4679691c2 100644
--- a/composer.json
+++ b/composer.json
@@ -5,17 +5,17 @@
"license": "MIT",
"require": {
"php": "^8.4",
- "webmozart/assert": "^2.0",
+ "webmozart/assert": "^2.4",
"phpstan/phpstan": "^2.2",
"nette/utils": "^4.1",
"phpstan/phpdoc-parser": "^2.3"
},
"require-dev": {
"nikic/php-parser": "^5.7",
- "phpunit/phpunit": "^13.0",
- "symfony/framework-bundle": "^6.2",
- "illuminate/container": "^11.0",
- "symplify/easy-coding-standard": "^13.1",
+ "phpunit/phpunit": "^13.2",
+ "symfony/framework-bundle": "^6.4",
+ "illuminate/container": "^11.51",
+ "symplify/easy-coding-standard": "^13.2",
"tomasvotruba/class-leak": "^2.1",
"rector/rector": "^2.4",
"phpstan/extension-installer": "^1.4",
diff --git a/config/ctor-rules.neon b/config/ctor-rules.neon
index e5bb8715a..d5aecd085 100644
--- a/config/ctor-rules.neon
+++ b/config/ctor-rules.neon
@@ -1,21 +1,14 @@
-parameters:
- # enables NewOverSettersRule, disabled by default
- ctor: false
-
-parametersSchema:
- ctor: bool()
-
services:
-
class: Symplify\PHPStanRules\Collector\NewWithFollowingSettersCollector
tags:
- phpstan.collector
arguments:
- isEnabled: %ctor%
+ isEnabled: %symplify.ctor%
-
class: Symplify\PHPStanRules\Rules\NewOverSettersRule
tags:
- phpstan.rules.rule
arguments:
- isEnabled: %ctor%
+ isEnabled: %symplify.ctor%
diff --git a/config/mock-rules.neon b/config/mock-rules.neon
index 6e3db73d4..bb1b502f3 100644
--- a/config/mock-rules.neon
+++ b/config/mock-rules.neon
@@ -1,40 +1,29 @@
-# PHPUnit mocking rules, enable in your phpstan.neon with:
-#
-# parameters:
-# mocks: true
-
-parameters:
- mocks: false
-
-parametersSchema:
- mocks: bool()
-
conditionalTags:
# mocking
Symplify\PHPStanRules\Rules\PHPUnit\NoMockOnlyTestRule:
- phpstan.rules.rule: %mocks%
+ phpstan.rules.rule: %symplify.mocks%
Symplify\PHPStanRules\Rules\PHPUnit\NoMockObjectAndRealObjectPropertyRule:
- phpstan.rules.rule: %mocks%
+ phpstan.rules.rule: %symplify.mocks%
# overly complicated
Symplify\PHPStanRules\Rules\PHPUnit\NoDoubleConsecutiveTestMockRule:
- phpstan.rules.rule: %mocks%
+ phpstan.rules.rule: %symplify.mocks%
# explicit expects()
Symplify\PHPStanRules\Rules\PHPUnit\ExplicitExpectsMockMethodRule:
- phpstan.rules.rule: %mocks%
+ phpstan.rules.rule: %symplify.mocks%
Symplify\PHPStanRules\Rules\PHPUnit\AvoidAnyExpectsRule:
- phpstan.rules.rule: %mocks%
+ phpstan.rules.rule: %symplify.mocks%
Symplify\PHPStanRules\Rules\PHPUnit\NoWithOnStubRule:
- phpstan.rules.rule: %mocks%
+ phpstan.rules.rule: %symplify.mocks%
Symplify\PHPStanRules\Rules\PHPUnit\RequireAtLeastOneRule:
- phpstan.rules.rule: %mocks%
+ phpstan.rules.rule: %symplify.mocks%
# better alternative than mocks
Symplify\PHPStanRules\Rules\Doctrine\NoDocumentMockingRule:
- phpstan.rules.rule: %mocks%
+ phpstan.rules.rule: %symplify.mocks%
Symplify\PHPStanRules\Rules\Doctrine\NoEntityMockingRule:
- phpstan.rules.rule: %mocks%
+ phpstan.rules.rule: %symplify.mocks%
services:
- Symplify\PHPStanRules\Rules\PHPUnit\NoMockOnlyTestRule
diff --git a/config/phpstan-extensions.neon b/config/phpstan-extensions.neon
index 5a9deab49..1aa8de1e7 100644
--- a/config/phpstan-extensions.neon
+++ b/config/phpstan-extensions.neon
@@ -1,16 +1,27 @@
-# return type extensions are disabled by default; enable in your phpstan.neon with:
-#
-# parameters:
-# symfonyReturnType: true
-# laravelReturnType: true
-# pathStrings: true
-
parameters:
- symfonyReturnType: false
- laravelReturnType: false
- pathStrings: false
+ symplify:
+ mocks: false
+ ctor: false
+ symfonyReturnType: false
+ laravelReturnType: false
+ pathStrings: false
+ maximumIgnoredErrorCount: 0
+
+ # kept flat for backward compatibility, default to the %symplify.*% nested values
+ symfonyReturnType: %symplify.symfonyReturnType%
+ laravelReturnType: %symplify.laravelReturnType%
+ pathStrings: %symplify.pathStrings%
parametersSchema:
+ symplify: structure([
+ mocks: bool()
+ ctor: bool()
+ symfonyReturnType: bool()
+ laravelReturnType: bool()
+ pathStrings: bool()
+ maximumIgnoredErrorCount: int()
+ ])
+
symfonyReturnType: bool()
laravelReturnType: bool()
pathStrings: bool()
@@ -18,16 +29,19 @@ parametersSchema:
conditionalTags:
# Symfony Container::get($1) => $1 type
Symplify\PHPStanRules\ReturnTypeExtension\Symfony\ContainerGetReturnTypeExtension:
- phpstan.broker.dynamicMethodReturnTypeExtension: %symfonyReturnType%
+ phpstan.broker.dynamicMethodReturnTypeExtension: %symplify.symfonyReturnType%
+
# Symfony Finder SplFileInfo::getRealPath() => string type
Symplify\PHPStanRules\ReturnTypeExtension\Symfony\SplFileInfoTolerantReturnTypeExtension:
- phpstan.broker.dynamicMethodReturnTypeExtension: %symfonyReturnType%
+ phpstan.broker.dynamicMethodReturnTypeExtension: %symplify.symfonyReturnType%
+
# Laravel Container::make($1) => $1 type
Symplify\PHPStanRules\ReturnTypeExtension\Laravel\LaravelContainerMakeTypeExtension:
- phpstan.broker.dynamicMethodReturnTypeExtension: %laravelReturnType%
+ phpstan.broker.dynamicMethodReturnTypeExtension: %symplify.laravelReturnType%
+
# getcwd()/dirname()/realpath() => always "string"
Symplify\PHPStanRules\ReturnTypeExtension\NativeFunctionReturnTypeExtension:
- phpstan.broker.dynamicFunctionReturnTypeExtension: %pathStrings%
+ phpstan.broker.dynamicFunctionReturnTypeExtension: %symplify.pathStrings%
services:
# use with "errorFormat: symplify" in CLI/config
diff --git a/config/phpunit-rules.neon b/config/phpunit-rules.neon
index 78da5b9e5..997de3d82 100644
--- a/config/phpunit-rules.neon
+++ b/config/phpunit-rules.neon
@@ -1,8 +1,4 @@
rules:
- Symplify\PHPStanRules\Rules\PHPUnit\PublicStaticDataProviderRule
- Symplify\PHPStanRules\Rules\PHPUnit\NoAssertFuncCallInTestsRule
-
-# mocking rules moved to mock-rules.neon, enable them with:
-#
-# parameters:
-# mocks: true
+ě
diff --git a/config/services/services.neon b/config/services/services.neon
index 504f113a3..3856d4350 100644
--- a/config/services/services.neon
+++ b/config/services/services.neon
@@ -1,6 +1,7 @@
parameters:
# related to MaximumIgnoredErrorCountRule
- maximumIgnoredErrorCount: 0
+ # kept flat for backward compatibility, defaults to %symplify.maximumIgnoredErrorCount%
+ maximumIgnoredErrorCount: %symplify.maximumIgnoredErrorCount%
parametersSchema:
# related to MaximumIgnoredErrorCountRule
diff --git a/tests/ErrorFormatter/SymplifyErrorFormatterTest.php b/tests/ErrorFormatter/SymplifyErrorFormatterTest.php
index 07fd440fa..fd13a66be 100644
--- a/tests/ErrorFormatter/SymplifyErrorFormatterTest.php
+++ b/tests/ErrorFormatter/SymplifyErrorFormatterTest.php
@@ -47,6 +47,8 @@ public static function provideData(): Iterator
#[Override]
public static function getAdditionalConfigFiles(): array
{
- return [__DIR__ . '/../../config/phpstan-extensions.neon'];
+ return [
+ __DIR__ . '/../../config/phpstan-extensions.neon',
+ ];
}
}
diff --git a/tests/Rules/NewOverSettersRule/config/configured_rule.neon b/tests/Rules/NewOverSettersRule/config/configured_rule.neon
index 58a9d47d9..9c61ad4b6 100644
--- a/tests/Rules/NewOverSettersRule/config/configured_rule.neon
+++ b/tests/Rules/NewOverSettersRule/config/configured_rule.neon
@@ -1,5 +1,7 @@
includes:
+ - ../../../../config/phpstan-extensions.neon
- ../../../../config/ctor-rules.neon
parameters:
- ctor: true
+ symplify:
+ ctor: true
diff --git a/tests/Rules/Symfony/ConfigClosure/NoDuplicateArgAutowireByTypeRule/config/configured_rule.neon b/tests/Rules/Symfony/ConfigClosure/NoDuplicateArgAutowireByTypeRule/config/configured_rule.neon
index ea8e56ed4..7ec8916f4 100644
--- a/tests/Rules/Symfony/ConfigClosure/NoDuplicateArgAutowireByTypeRule/config/configured_rule.neon
+++ b/tests/Rules/Symfony/ConfigClosure/NoDuplicateArgAutowireByTypeRule/config/configured_rule.neon
@@ -1,4 +1,5 @@
includes:
+ - ../../../../../../config/phpstan-extensions.neon
- ../../../../../../config/services/services.neon
rules:
diff --git a/tests/Rules/Symfony/ConfigClosure/NoDuplicateArgsAutowireByTypeRule/config/configured_rule.neon b/tests/Rules/Symfony/ConfigClosure/NoDuplicateArgsAutowireByTypeRule/config/configured_rule.neon
index f8eba2f3b..c961e061f 100644
--- a/tests/Rules/Symfony/ConfigClosure/NoDuplicateArgsAutowireByTypeRule/config/configured_rule.neon
+++ b/tests/Rules/Symfony/ConfigClosure/NoDuplicateArgsAutowireByTypeRule/config/configured_rule.neon
@@ -1,4 +1,5 @@
includes:
+ - ../../../../../../config/phpstan-extensions.neon
- ../../../../../../config/services/services.neon
rules:
diff --git a/tests/config/included_services.neon b/tests/config/included_services.neon
index bdcc782cd..641dd7673 100644
--- a/tests/config/included_services.neon
+++ b/tests/config/included_services.neon
@@ -1,2 +1,3 @@
includes:
+ - ../../config/phpstan-extensions.neon
- ../../config/services/services.neon