Skip to content

Commit e467531

Browse files
committed
More #[AutowiredService]
1 parent 8f3eaf3 commit e467531

13 files changed

+78
-86
lines changed

conf/config.neon

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -415,33 +415,6 @@ services:
415415
autowired:
416416
- PHPStan\Rules\Exceptions\DefaultExceptionTypeResolver
417417

418-
-
419-
class: PHPStan\Rules\Properties\AccessPropertiesCheck
420-
arguments:
421-
reportMagicProperties: %reportMagicProperties%
422-
checkDynamicProperties: %checkDynamicProperties%
423-
424-
-
425-
class: PHPStan\Rules\RuleLevelHelper
426-
arguments:
427-
checkNullables: %checkNullables%
428-
checkThisOnly: %checkThisOnly%
429-
checkUnionTypes: %checkUnionTypes%
430-
checkExplicitMixed: %checkExplicitMixed%
431-
checkImplicitMixed: %checkImplicitMixed%
432-
checkBenevolentUnionTypes: %checkBenevolentUnionTypes%
433-
discoveringSymbolsTip: %tips.discoveringSymbols%
434-
435-
-
436-
class: PHPStan\Rules\UnusedFunctionParametersCheck
437-
arguments:
438-
reportExactLine: %featureToggles.reportPreciseLineForUnusedFunctionParameter%
439-
440-
-
441-
class: PHPStan\Type\FileTypeMapper
442-
arguments:
443-
phpParser: @defaultAnalysisParser
444-
445418
stubFileTypeMapper:
446419
class: PHPStan\Type\FileTypeMapper
447420
arguments:
@@ -458,33 +431,6 @@ services:
458431
class: PHPStan\Type\TypeAliasResolverProvider
459432
factory: PHPStan\Type\LazyTypeAliasResolverProvider
460433

461-
-
462-
class: PHPStan\Type\Php\CompactFunctionReturnTypeExtension
463-
tags:
464-
- phpstan.broker.dynamicFunctionReturnTypeExtension
465-
arguments:
466-
checkMaybeUndefinedVariables: %checkMaybeUndefinedVariables%
467-
468-
-
469-
class: PHPStan\Type\Php\VersionCompareFunctionDynamicReturnTypeExtension
470-
arguments:
471-
configPhpVersion: %phpVersion%
472-
tags:
473-
- phpstan.broker.dynamicFunctionReturnTypeExtension
474-
475-
-
476-
class: PHPStan\Type\Php\TypeSpecifyingFunctionsDynamicReturnTypeExtension
477-
arguments:
478-
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
479-
universalObjectCratesClasses: %universalObjectCratesClasses%
480-
tags:
481-
- phpstan.broker.dynamicFunctionReturnTypeExtension
482-
483-
-
484-
class: PHPStan\Type\ClosureTypeFactory
485-
arguments:
486-
parser: @currentPhpVersionPhpParser
487-
488434
exceptionTypeResolver:
489435
class: PHPStan\Rules\Exceptions\ExceptionTypeResolver
490436
factory: @PHPStan\Rules\Exceptions\DefaultExceptionTypeResolver
@@ -571,19 +517,8 @@ services:
571517
autowired:
572518
- PHPStan\Rules\Registry
573519

574-
stubPhpDocProvider:
575-
class: PHPStan\PhpDoc\StubPhpDocProvider
576-
arguments:
577-
parser: @stubParser
578-
fileTypeMapper: @stubFileTypeMapper
579-
580520
# Reflection providers
581521

582-
reflectionProviderFactory:
583-
class: PHPStan\Reflection\ReflectionProvider\ReflectionProviderFactory
584-
arguments:
585-
staticReflectionProvider: @betterReflectionProvider
586-
587522
reflectionProvider:
588523
factory: @PHPStan\Reflection\ReflectionProvider\ReflectionProviderFactory::create
589524
autowired:
@@ -606,29 +541,11 @@ services:
606541
universalObjectCratesClasses: %universalObjectCratesClasses%
607542
autowired: false
608543

609-
-
610-
class: PHPStan\Reflection\BetterReflection\BetterReflectionSourceLocatorFactory
611-
arguments:
612-
parser: @phpParserDecorator
613-
php8Parser: @php8PhpParser
614-
scanFiles: %scanFiles%
615-
scanDirectories: %scanDirectories%
616-
analysedPaths: %analysedPaths%
617-
composerAutoloaderProjectPaths: %composerAutoloaderProjectPaths%
618-
analysedPathsFromConfig: %analysedPathsFromConfig%
619-
playgroundMode: %sourceLocatorPlaygroundMode%
620-
singleReflectionFile: %singleReflectionFile%
621-
622544
-
623545
implement: PHPStan\Reflection\BetterReflection\BetterReflectionProviderFactory
624546
arguments:
625547
universalObjectCratesClasses: %universalObjectCratesClasses%
626548

627-
-
628-
class: PHPStan\Reflection\BetterReflection\SourceStubber\PhpStormStubsSourceStubberFactory
629-
arguments:
630-
phpParser: @php8PhpParser
631-
632549
-
633550
factory: @PHPStan\Reflection\BetterReflection\SourceStubber\PhpStormStubsSourceStubberFactory::create()
634551
autowired:

src/PhpDoc/StubPhpDocProvider.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
use PhpParser\Node\Stmt\Class_;
88
use PhpParser\Node\Stmt\Interface_;
99
use PhpParser\Node\Stmt\Trait_;
10+
use PHPStan\DependencyInjection\AutowiredParameter;
11+
use PHPStan\DependencyInjection\AutowiredService;
1012
use PHPStan\Parser\Parser;
1113
use PHPStan\ShouldNotHappenException;
1214
use PHPStan\Type\FileTypeMapper;
1315
use function array_key_exists;
1416
use function array_map;
1517
use function is_string;
1618

19+
#[AutowiredService(name: 'stubPhpDocProvider')]
1720
final class StubPhpDocProvider
1821
{
1922

@@ -58,7 +61,9 @@ final class StubPhpDocProvider
5861
private array $knownFunctionParameterNames = [];
5962

6063
public function __construct(
64+
#[AutowiredParameter(ref: '@stubParser')]
6165
private Parser $parser,
66+
#[AutowiredParameter(ref: '@stubFileTypeMapper')]
6267
private FileTypeMapper $fileTypeMapper,
6368
private StubFilesProvider $stubFilesProvider,
6469
)

src/Reflection/BetterReflection/BetterReflectionSourceLocatorFactory.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use PHPStan\BetterReflection\SourceLocator\Type\MemoizingSourceLocator;
1414
use PHPStan\BetterReflection\SourceLocator\Type\PhpInternalSourceLocator;
1515
use PHPStan\BetterReflection\SourceLocator\Type\SourceLocator;
16+
use PHPStan\DependencyInjection\AutowiredParameter;
17+
use PHPStan\DependencyInjection\AutowiredService;
1618
use PHPStan\Reflection\BetterReflection\SourceLocator\AutoloadFunctionsSourceLocator;
1719
use PHPStan\Reflection\BetterReflection\SourceLocator\AutoloadSourceLocator;
1820
use PHPStan\Reflection\BetterReflection\SourceLocator\ComposerJsonAndInstalledJsonSourceLocatorMaker;
@@ -30,6 +32,7 @@
3032
use function is_dir;
3133
use function is_file;
3234

35+
#[AutowiredService]
3336
final class BetterReflectionSourceLocatorFactory
3437
{
3538

@@ -41,7 +44,9 @@ final class BetterReflectionSourceLocatorFactory
4144
* @param string[] $analysedPathsFromConfig
4245
*/
4346
public function __construct(
47+
#[AutowiredParameter(ref: '@phpParserDecorator')]
4448
private Parser $parser,
49+
#[AutowiredParameter(ref: '@php8PhpParser')]
4550
private Parser $php8Parser,
4651
private PhpStormStubsSourceStubber $phpstormStubsSourceStubber,
4752
private ReflectionSourceStubber $reflectionSourceStubber,
@@ -50,12 +55,19 @@ public function __construct(
5055
private ComposerJsonAndInstalledJsonSourceLocatorMaker $composerJsonAndInstalledJsonSourceLocatorMaker,
5156
private OptimizedPsrAutoloaderLocatorFactory $optimizedPsrAutoloaderLocatorFactory,
5257
private FileNodesFetcher $fileNodesFetcher,
58+
#[AutowiredParameter]
5359
private array $scanFiles,
60+
#[AutowiredParameter]
5461
private array $scanDirectories,
62+
#[AutowiredParameter]
5563
private array $analysedPaths,
64+
#[AutowiredParameter]
5665
private array $composerAutoloaderProjectPaths,
66+
#[AutowiredParameter]
5767
private array $analysedPathsFromConfig,
68+
#[AutowiredParameter(ref: '%sourceLocatorPlaygroundMode%')]
5869
private bool $playgroundMode, // makes all PHPStan classes in the PHAR discoverable with PSR-4
70+
#[AutowiredParameter]
5971
private ?string $singleReflectionFile,
6072
)
6173
{

src/Reflection/BetterReflection/SourceStubber/PhpStormStubsSourceStubberFactory.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@
44

55
use PhpParser\Parser;
66
use PHPStan\BetterReflection\SourceLocator\SourceStubber\PhpStormStubsSourceStubber;
7+
use PHPStan\DependencyInjection\AutowiredParameter;
8+
use PHPStan\DependencyInjection\AutowiredService;
79
use PHPStan\Node\Printer\Printer;
810
use PHPStan\Php\PhpVersion;
911

12+
#[AutowiredService]
1013
final class PhpStormStubsSourceStubberFactory
1114
{
1215

13-
public function __construct(private Parser $phpParser, private Printer $printer, private PhpVersion $phpVersion)
16+
public function __construct(
17+
#[AutowiredParameter(ref: '@php8PhpParser')]
18+
private Parser $phpParser,
19+
private Printer $printer,
20+
private PhpVersion $phpVersion,
21+
)
1422
{
1523
}
1624

src/Reflection/ReflectionProvider/ReflectionProviderFactory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
namespace PHPStan\Reflection\ReflectionProvider;
44

5+
use PHPStan\DependencyInjection\AutowiredParameter;
6+
use PHPStan\DependencyInjection\AutowiredService;
57
use PHPStan\Reflection\ReflectionProvider;
68

9+
#[AutowiredService(name: 'reflectionProviderFactory')]
710
final class ReflectionProviderFactory
811
{
912

1013
public function __construct(
14+
#[AutowiredParameter(ref: '@betterReflectionProvider')]
1115
private ReflectionProvider $staticReflectionProvider,
1216
)
1317
{

src/Rules/Properties/AccessPropertiesCheck.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use PhpParser\Node\Name\FullyQualified;
1111
use PHPStan\Analyser\NullsafeOperatorHelper;
1212
use PHPStan\Analyser\Scope;
13+
use PHPStan\DependencyInjection\AutowiredParameter;
14+
use PHPStan\DependencyInjection\AutowiredService;
1315
use PHPStan\Internal\SprintfHelper;
1416
use PHPStan\Php\PhpVersion;
1517
use PHPStan\Reflection\ReflectionProvider;
@@ -26,14 +28,17 @@
2628
use function count;
2729
use function sprintf;
2830

31+
#[AutowiredService]
2932
final class AccessPropertiesCheck
3033
{
3134

3235
public function __construct(
3336
private ReflectionProvider $reflectionProvider,
3437
private RuleLevelHelper $ruleLevelHelper,
3538
private PhpVersion $phpVersion,
39+
#[AutowiredParameter]
3640
private bool $reportMagicProperties,
41+
#[AutowiredParameter]
3742
private bool $checkDynamicProperties,
3843
)
3944
{

src/Rules/RuleLevelHelper.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use PhpParser\Node\Expr;
66
use PHPStan\Analyser\Scope;
7+
use PHPStan\DependencyInjection\AutowiredParameter;
8+
use PHPStan\DependencyInjection\AutowiredService;
79
use PHPStan\Reflection\ReflectionProvider;
810
use PHPStan\Type\BenevolentUnionType;
911
use PHPStan\Type\CallableType;
@@ -23,17 +25,25 @@
2325
use function count;
2426
use function sprintf;
2527

28+
#[AutowiredService]
2629
final class RuleLevelHelper
2730
{
2831

2932
public function __construct(
3033
private ReflectionProvider $reflectionProvider,
34+
#[AutowiredParameter]
3135
private bool $checkNullables,
36+
#[AutowiredParameter]
3237
private bool $checkThisOnly,
38+
#[AutowiredParameter]
3339
private bool $checkUnionTypes,
40+
#[AutowiredParameter]
3441
private bool $checkExplicitMixed,
42+
#[AutowiredParameter]
3543
private bool $checkImplicitMixed,
44+
#[AutowiredParameter]
3645
private bool $checkBenevolentUnionTypes,
46+
#[AutowiredParameter(ref: '%tips.discoveringSymbols%')]
3747
private bool $discoveringSymbolsTip,
3848
)
3949
{

src/Rules/UnusedFunctionParametersCheck.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use PhpParser\Node;
66
use PhpParser\Node\Expr\Variable;
77
use PHPStan\Analyser\Scope;
8+
use PHPStan\DependencyInjection\AutowiredParameter;
9+
use PHPStan\DependencyInjection\AutowiredService;
810
use PHPStan\Reflection\ReflectionProvider;
911
use PHPStan\ShouldNotHappenException;
1012
use function array_combine;
@@ -14,11 +16,13 @@
1416
use function is_string;
1517
use function sprintf;
1618

19+
#[AutowiredService]
1720
final class UnusedFunctionParametersCheck
1821
{
1922

2023
public function __construct(
2124
private ReflectionProvider $reflectionProvider,
25+
#[AutowiredParameter(ref: '%featureToggles.reportPreciseLineForUnusedFunctionParameter%')]
2226
private bool $reportExactLine,
2327
)
2428
{

src/Type/ClosureTypeFactory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use PHPStan\BetterReflection\SourceLocator\Ast\Strategy\NodeToReflection;
1414
use PHPStan\BetterReflection\SourceLocator\Located\LocatedSource;
1515
use PHPStan\BetterReflection\SourceLocator\SourceStubber\ReflectionSourceStubber;
16+
use PHPStan\DependencyInjection\AutowiredParameter;
17+
use PHPStan\DependencyInjection\AutowiredService;
1618
use PHPStan\Reflection\InitializerExprContext;
1719
use PHPStan\Reflection\InitializerExprTypeResolver;
1820
use PHPStan\Reflection\ParameterReflection;
@@ -26,13 +28,15 @@
2628
/**
2729
* @api
2830
*/
31+
#[AutowiredService]
2932
final class ClosureTypeFactory
3033
{
3134

3235
public function __construct(
3336
private InitializerExprTypeResolver $initializerExprTypeResolver,
3437
private ReflectionSourceStubber $reflectionSourceStubber,
3538
private Reflector $reflector,
39+
#[AutowiredParameter(ref: '@currentPhpVersionPhpParser')]
3640
private Parser $parser,
3741
)
3842
{

src/Type/FileTypeMapper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use PHPStan\Analyser\NameScope;
88
use PHPStan\BetterReflection\Util\GetLastDocComment;
99
use PHPStan\Broker\AnonymousClassNameHelper;
10+
use PHPStan\DependencyInjection\AutowiredParameter;
11+
use PHPStan\DependencyInjection\AutowiredService;
1012
use PHPStan\File\FileHelper;
1113
use PHPStan\Parser\Parser;
1214
use PHPStan\PhpDoc\NameScopeAlreadyBeingCreatedException;
@@ -39,6 +41,7 @@
3941
use function str_contains;
4042
use function strtolower;
4143

44+
#[AutowiredService]
4245
final class FileTypeMapper
4346
{
4447

@@ -60,6 +63,7 @@ final class FileTypeMapper
6063

6164
public function __construct(
6265
private ReflectionProviderProvider $reflectionProviderProvider,
66+
#[AutowiredParameter(ref: '@defaultAnalysisParser')]
6367
private Parser $phpParser,
6468
private PhpDocStringResolver $phpDocStringResolver,
6569
private PhpDocNodeResolver $phpDocNodeResolver,

src/Type/Php/CompactFunctionReturnTypeExtension.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use PhpParser\Node\Expr\FuncCall;
66
use PHPStan\Analyser\Scope;
7+
use PHPStan\DependencyInjection\AutowiredParameter;
8+
use PHPStan\DependencyInjection\AutowiredService;
79
use PHPStan\Reflection\FunctionReflection;
810
use PHPStan\Type\Constant\ConstantArrayType;
911
use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
@@ -13,10 +15,14 @@
1315
use function array_merge;
1416
use function count;
1517

18+
#[AutowiredService]
1619
final class CompactFunctionReturnTypeExtension implements DynamicFunctionReturnTypeExtension
1720
{
1821

19-
public function __construct(private bool $checkMaybeUndefinedVariables)
22+
public function __construct(
23+
#[AutowiredParameter]
24+
private bool $checkMaybeUndefinedVariables,
25+
)
2026
{
2127
}
2228

0 commit comments

Comments
 (0)