Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ extensions:
validateIgnoredErrors: PHPStan\DependencyInjection\ValidateIgnoredErrorsExtension
validateExcludePaths: PHPStan\DependencyInjection\ValidateExcludePathsExtension
autowiredAttributeServices: PHPStan\DependencyInjection\AutowiredAttributeServicesExtension
autowiredExtensions: PHPStan\DependencyInjection\AutowiredExtensionsExtension
validateServiceTags: PHPStan\DependencyInjection\ValidateServiceTagsExtension
fnsr: PHPStan\DependencyInjection\FnsrExtension

Expand Down
14 changes: 10 additions & 4 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ parameters:
path: src/Collectors/Collector.php

-
rawMessage: 'Method PHPStan\Collectors\Registry::__construct() has parameter $collectors with generic interface PHPStan\Collectors\Collector but does not specify its types: TNodeType, TValue'
rawMessage: 'Method PHPStan\Collectors\Registry::getCollectorsByNodeType() return type with generic interface PHPStan\Collectors\Collector does not specify its types: TNodeType, TValue'
identifier: missingType.generics
count: 1
path: src/Collectors/Registry.php
Expand All @@ -145,7 +145,7 @@ parameters:
path: src/Collectors/Registry.php

-
rawMessage: 'Property PHPStan\Collectors\Registry::$collectors with generic interface PHPStan\Collectors\Collector does not specify its types: TNodeType, TValue'
rawMessage: 'Property PHPStan\Collectors\Registry::$collectorsByNodeType with generic interface PHPStan\Collectors\Collector does not specify its types: TNodeType, TValue'
identifier: missingType.generics
count: 1
path: src/Collectors/Registry.php
Expand Down Expand Up @@ -688,7 +688,13 @@ parameters:
path: src/Rules/LazyRegistry.php

-
rawMessage: 'Method PHPStan\Rules\LazyRegistry::getRulesFromContainer() return type with generic interface PHPStan\Rules\Rule does not specify its types: TNodeType'
rawMessage: 'Method PHPStan\Rules\LazyRegistry::__construct() has parameter $rules with generic interface PHPStan\Rules\Rule but does not specify its types: TNodeType'
identifier: missingType.generics
count: 1
path: src/Rules/LazyRegistry.php

-
rawMessage: 'Method PHPStan\Rules\LazyRegistry::getRulesByNodeType() return type with generic interface PHPStan\Rules\Rule does not specify its types: TNodeType'
identifier: missingType.generics
count: 1
path: src/Rules/LazyRegistry.php
Expand All @@ -700,7 +706,7 @@ parameters:
path: src/Rules/LazyRegistry.php

-
rawMessage: 'Property PHPStan\Rules\LazyRegistry::$rules with generic interface PHPStan\Rules\Rule does not specify its types: TNodeType'
rawMessage: 'Property PHPStan\Rules\LazyRegistry::$rulesByNodeType with generic interface PHPStan\Rules\Rule does not specify its types: TNodeType'
identifier: missingType.generics
count: 1
path: src/Rules/LazyRegistry.php
Expand Down
10 changes: 8 additions & 2 deletions src/Analyser/AnalyserResultFinalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
use PHPStan\BetterReflection\NodeCompiler\Exception\UnableToCompileNode;
use PHPStan\BetterReflection\Reflection\Exception\CircularReference;
use PHPStan\BetterReflection\Reflector\Exception\IdentifierNotFound;
use PHPStan\DependencyInjection\AutowiredExtensions;
use PHPStan\DependencyInjection\AutowiredParameter;
use PHPStan\DependencyInjection\AutowiredService;
use PHPStan\DependencyInjection\ExtensionsCollection;
use PHPStan\Node\CollectedDataNode;
use PHPStan\Rules\Registry as RuleRegistry;
use Throwable;
Expand All @@ -20,9 +22,13 @@
final class AnalyserResultFinalizer
{

/**
* @param ExtensionsCollection<IgnoreErrorExtension> $ignoreErrorExtensions
*/
public function __construct(
private RuleRegistry $ruleRegistry,
private IgnoreErrorExtensionProvider $ignoreErrorExtensionProvider,
#[AutowiredExtensions(of: IgnoreErrorExtension::class)]
private ExtensionsCollection $ignoreErrorExtensions,
private RuleErrorTransformer $ruleErrorTransformer,
private ScopeFactory $scopeFactory,
private LocalIgnoresProcessor $localIgnoresProcessor,
Expand Down Expand Up @@ -96,7 +102,7 @@ public function finalize(AnalyserResult $analyserResult, bool $onlyFiles, bool $
$error = $this->ruleErrorTransformer->transform($ruleError, $scope, [], $node);

if ($error->canBeIgnored()) {
foreach ($this->ignoreErrorExtensionProvider->getExtensions() as $ignoreErrorExtension) {
foreach ($this->ignoreErrorExtensions->getAll() as $ignoreErrorExtension) {
if ($ignoreErrorExtension->shouldIgnore($error, $node, $scope)) {
continue 2;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Analyser/DirectInternalScopeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use PhpParser\Node;
use PHPStan\Analyser\Fiber\FiberScope;
use PHPStan\DependencyInjection\Container;
use PHPStan\DependencyInjection\Type\ExpressionTypeResolverExtensionRegistryProvider;
use PHPStan\Node\Printer\ExprPrinter;
use PHPStan\Parser\Parser;
use PHPStan\Php\PhpVersion;
Expand All @@ -15,6 +14,7 @@
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Properties\PropertyReflectionFinder;
use PHPStan\Type\ClosureType;
use PHPStan\Type\ExpressionTypeResolverExtensionRegistry;

final class DirectInternalScopeFactory implements InternalScopeFactory
{
Expand All @@ -27,7 +27,7 @@ public function __construct(
private Container $container,
private ReflectionProvider $reflectionProvider,
private InitializerExprTypeResolver $initializerExprTypeResolver,
private ExpressionTypeResolverExtensionRegistryProvider $expressionTypeResolverExtensionRegistryProvider,
private ExpressionTypeResolverExtensionRegistry $expressionTypeResolverExtensionRegistry,
private ExprPrinter $exprPrinter,
private TypeSpecifier $typeSpecifier,
private PropertyReflectionFinder $propertyReflectionFinder,
Expand Down Expand Up @@ -71,7 +71,7 @@ public function create(
$this,
$this->reflectionProvider,
$this->initializerExprTypeResolver,
$this->expressionTypeResolverExtensionRegistryProvider->getRegistry(),
$this->expressionTypeResolverExtensionRegistry,
$this->exprPrinter,
$this->typeSpecifier,
$this->propertyReflectionFinder,
Expand Down Expand Up @@ -106,7 +106,7 @@ public function toFiberFactory(): InternalScopeFactory
$this->container,
$this->reflectionProvider,
$this->initializerExprTypeResolver,
$this->expressionTypeResolverExtensionRegistryProvider,
$this->expressionTypeResolverExtensionRegistry,
$this->exprPrinter,
$this->typeSpecifier,
$this->propertyReflectionFinder,
Expand All @@ -126,7 +126,7 @@ public function toMutatingFactory(): InternalScopeFactory
$this->container,
$this->reflectionProvider,
$this->initializerExprTypeResolver,
$this->expressionTypeResolverExtensionRegistryProvider,
$this->expressionTypeResolverExtensionRegistry,
$this->exprPrinter,
$this->typeSpecifier,
$this->propertyReflectionFinder,
Expand Down
6 changes: 3 additions & 3 deletions src/Analyser/DirectInternalScopeFactoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

use PhpParser\Node;
use PHPStan\DependencyInjection\Container;
use PHPStan\DependencyInjection\Type\ExpressionTypeResolverExtensionRegistryProvider;
use PHPStan\Node\Printer\ExprPrinter;
use PHPStan\Parser\Parser;
use PHPStan\Php\PhpVersion;
use PHPStan\Reflection\AttributeReflectionFactory;
use PHPStan\Reflection\InitializerExprTypeResolver;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Properties\PropertyReflectionFinder;
use PHPStan\Type\ExpressionTypeResolverExtensionRegistry;

final class DirectInternalScopeFactoryFactory implements InternalScopeFactoryFactory
{
Expand All @@ -23,7 +23,7 @@ public function __construct(
private Container $container,
private ReflectionProvider $reflectionProvider,
private InitializerExprTypeResolver $initializerExprTypeResolver,
private ExpressionTypeResolverExtensionRegistryProvider $expressionTypeResolverExtensionRegistryProvider,
private ExpressionTypeResolverExtensionRegistry $expressionTypeResolverExtensionRegistry,
private ExprPrinter $exprPrinter,
private TypeSpecifier $typeSpecifier,
private PropertyReflectionFinder $propertyReflectionFinder,
Expand All @@ -45,7 +45,7 @@ public function create(?callable $nodeCallback): DirectInternalScopeFactory
$this->container,
$this->reflectionProvider,
$this->initializerExprTypeResolver,
$this->expressionTypeResolverExtensionRegistryProvider,
$this->expressionTypeResolverExtensionRegistry,
$this->exprPrinter,
$this->typeSpecifier,
$this->propertyReflectionFinder,
Expand Down
18 changes: 12 additions & 6 deletions src/Analyser/ExprHandler/FuncCallHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
use PHPStan\Analyser\SpecifiedTypes;
use PHPStan\Analyser\TypeSpecifier;
use PHPStan\Analyser\TypeSpecifierContext;
use PHPStan\DependencyInjection\AutowiredExtensions;
use PHPStan\DependencyInjection\AutowiredParameter;
use PHPStan\DependencyInjection\AutowiredService;
use PHPStan\DependencyInjection\Type\DynamicReturnTypeExtensionRegistryProvider;
use PHPStan\DependencyInjection\Type\DynamicThrowTypeExtensionProvider;
use PHPStan\DependencyInjection\ExtensionsCollection;
use PHPStan\Node\ClosureReturnStatementsNode;
use PHPStan\Node\Expr\NativeTypeExpr;
use PHPStan\Node\Expr\PossiblyImpureCallExpr;
Expand All @@ -53,6 +53,8 @@
use PHPStan\Type\ClosureType;
use PHPStan\Type\Constant\ConstantArrayType;
use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
use PHPStan\Type\DynamicFunctionThrowTypeExtension;
use PHPStan\Type\DynamicReturnTypeExtensionRegistry;
use PHPStan\Type\ErrorType;
use PHPStan\Type\GeneralizePrecision;
use PHPStan\Type\Generic\TemplateTypeHelper;
Expand Down Expand Up @@ -88,10 +90,14 @@
final class FuncCallHandler implements ExprHandler
{

/**
* @param ExtensionsCollection<DynamicFunctionThrowTypeExtension> $dynamicFunctionThrowTypeExtensions
*/
public function __construct(
private ReflectionProvider $reflectionProvider,
private DynamicThrowTypeExtensionProvider $dynamicThrowTypeExtensionProvider,
private DynamicReturnTypeExtensionRegistryProvider $dynamicReturnTypeExtensionRegistryProvider,
#[AutowiredExtensions(of: DynamicFunctionThrowTypeExtension::class)]
private ExtensionsCollection $dynamicFunctionThrowTypeExtensions,
private DynamicReturnTypeExtensionRegistry $dynamicReturnTypeExtensionRegistry,
#[AutowiredParameter(ref: '%exceptions.implicitThrows%')]
private bool $implicitThrows,
#[AutowiredParameter]
Expand Down Expand Up @@ -604,7 +610,7 @@ private function getFunctionThrowPoint(
ExpressionContext $context,
): ?InternalThrowPoint
{
foreach ($this->dynamicThrowTypeExtensionProvider->getDynamicFunctionThrowTypeExtensions() as $extension) {
foreach ($this->dynamicFunctionThrowTypeExtensions->getAll() as $extension) {
if (!$extension->isFunctionSupported($functionReflection)) {
continue;
}
Expand Down Expand Up @@ -1002,7 +1008,7 @@ private function specifyTypesFromCallableCall(TypeSpecifier $typeSpecifier, Type

private function getDynamicFunctionReturnType(MutatingScope $scope, FuncCall $normalizedNode, FunctionReflection $functionReflection): ?Type
{
foreach ($this->dynamicReturnTypeExtensionRegistryProvider->getRegistry()->getDynamicFunctionReturnTypeExtensions($functionReflection) as $dynamicFunctionReturnTypeExtension) {
foreach ($this->dynamicReturnTypeExtensionRegistry->getDynamicFunctionReturnTypeExtensions($functionReflection) as $dynamicFunctionReturnTypeExtension) {
$resolvedType = $dynamicFunctionReturnTypeExtension->getTypeFromFunctionCall(
$functionReflection,
$normalizedNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use PHPStan\Analyser\ArgumentsNormalizer;
use PHPStan\Analyser\MutatingScope;
use PHPStan\DependencyInjection\AutowiredService;
use PHPStan\DependencyInjection\Type\DynamicReturnTypeExtensionRegistryProvider;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Type\DynamicReturnTypeExtensionRegistry;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
Expand All @@ -19,7 +19,7 @@ final class MethodCallReturnTypeHelper
{

public function __construct(
private DynamicReturnTypeExtensionRegistryProvider $dynamicReturnTypeExtensionRegistryProvider,
private DynamicReturnTypeExtensionRegistry $dynamicReturnTypeExtensionRegistry,
)
{
}
Expand Down Expand Up @@ -57,7 +57,7 @@ public function methodCallReturnType(
$handledClassNames = [];
foreach ($allClassNames as $className) {
if ($normalizedMethodCall instanceof MethodCall) {
foreach ($this->dynamicReturnTypeExtensionRegistryProvider->getRegistry()->getDynamicMethodReturnTypeExtensionsForClass($className) as $dynamicMethodReturnTypeExtension) {
foreach ($this->dynamicReturnTypeExtensionRegistry->getDynamicMethodReturnTypeExtensionsForClass($className) as $dynamicMethodReturnTypeExtension) {
if (!$dynamicMethodReturnTypeExtension->isMethodSupported($methodReflection)) {
continue;
}
Expand All @@ -71,7 +71,7 @@ public function methodCallReturnType(
$handledClassNames[] = $className;
}
} else {
foreach ($this->dynamicReturnTypeExtensionRegistryProvider->getRegistry()->getDynamicStaticMethodReturnTypeExtensionsForClass($className) as $dynamicStaticMethodReturnTypeExtension) {
foreach ($this->dynamicReturnTypeExtensionRegistry->getDynamicStaticMethodReturnTypeExtensionsForClass($className) as $dynamicStaticMethodReturnTypeExtension) {
if (!$dynamicStaticMethodReturnTypeExtension->isStaticMethodSupported($methodReflection)) {
continue;
}
Expand Down
18 changes: 14 additions & 4 deletions src/Analyser/ExprHandler/Helper/MethodThrowPointHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
use PHPStan\Analyser\ExpressionContext;
use PHPStan\Analyser\InternalThrowPoint;
use PHPStan\Analyser\MutatingScope;
use PHPStan\DependencyInjection\AutowiredExtensions;
use PHPStan\DependencyInjection\AutowiredParameter;
use PHPStan\DependencyInjection\AutowiredService;
use PHPStan\DependencyInjection\Type\DynamicThrowTypeExtensionProvider;
use PHPStan\DependencyInjection\ExtensionsCollection;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ParametersAcceptor;
use PHPStan\Type\DynamicMethodThrowTypeExtension;
use PHPStan\Type\DynamicStaticMethodThrowTypeExtension;
use PHPStan\Type\NeverType;
use PHPStan\Type\ObjectType;
use ReflectionFunction;
Expand All @@ -23,8 +26,15 @@
final class MethodThrowPointHelper
{

/**
* @param ExtensionsCollection<DynamicMethodThrowTypeExtension> $dynamicMethodThrowTypeExtensions
* @param ExtensionsCollection<DynamicStaticMethodThrowTypeExtension> $dynamicStaticMethodThrowTypeExtensions
*/
public function __construct(
private DynamicThrowTypeExtensionProvider $dynamicThrowTypeExtensionProvider,
#[AutowiredExtensions(of: DynamicMethodThrowTypeExtension::class)]
private ExtensionsCollection $dynamicMethodThrowTypeExtensions,
#[AutowiredExtensions(of: DynamicStaticMethodThrowTypeExtension::class)]
private ExtensionsCollection $dynamicStaticMethodThrowTypeExtensions,
#[AutowiredParameter(ref: '%exceptions.implicitThrows%')]
private bool $implicitThrows,
)
Expand All @@ -40,7 +50,7 @@ public function getThrowPoint(
): ?InternalThrowPoint
{
if ($normalizedMethodCall instanceof MethodCall) {
foreach ($this->dynamicThrowTypeExtensionProvider->getDynamicMethodThrowTypeExtensions() as $extension) {
foreach ($this->dynamicMethodThrowTypeExtensions->getAll() as $extension) {
if (!$extension->isMethodSupported($methodReflection)) {
continue;
}
Expand All @@ -53,7 +63,7 @@ public function getThrowPoint(
return InternalThrowPoint::createExplicit($scope, $throwType, $normalizedMethodCall, false);
}
} else {
foreach ($this->dynamicThrowTypeExtensionProvider->getDynamicStaticMethodThrowTypeExtensions() as $extension) {
foreach ($this->dynamicStaticMethodThrowTypeExtensions->getAll() as $extension) {
if (!$extension->isStaticMethodSupported($methodReflection)) {
continue;
}
Expand Down
18 changes: 12 additions & 6 deletions src/Analyser/ExprHandler/NewHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
use PHPStan\Analyser\Traverser\GenericTypeTemplateTraverser;
use PHPStan\Analyser\TypeSpecifier;
use PHPStan\Analyser\TypeSpecifierContext;
use PHPStan\DependencyInjection\AutowiredExtensions;
use PHPStan\DependencyInjection\AutowiredParameter;
use PHPStan\DependencyInjection\AutowiredService;
use PHPStan\DependencyInjection\Type\DynamicReturnTypeExtensionRegistryProvider;
use PHPStan\DependencyInjection\Type\DynamicThrowTypeExtensionProvider;
use PHPStan\DependencyInjection\ExtensionsCollection;
use PHPStan\Node\MethodReturnStatementsNode;
use PHPStan\Parser\NewAssignedToPropertyVisitor;
use PHPStan\Reflection\Callables\SimpleImpurePoint;
Expand All @@ -42,6 +42,8 @@
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Properties\PropertyReflectionFinder;
use PHPStan\ShouldNotHappenException;
use PHPStan\Type\DynamicReturnTypeExtensionRegistry;
use PHPStan\Type\DynamicStaticMethodThrowTypeExtension;
use PHPStan\Type\ErrorType;
use PHPStan\Type\Generic\GenericObjectType;
use PHPStan\Type\Generic\GenericStaticType;
Expand Down Expand Up @@ -71,10 +73,14 @@
final class NewHandler implements ExprHandler
{

/**
* @param ExtensionsCollection<DynamicStaticMethodThrowTypeExtension> $dynamicStaticMethodThrowTypeExtensions
*/
public function __construct(
private ReflectionProvider $reflectionProvider,
private DynamicThrowTypeExtensionProvider $dynamicThrowTypeExtensionProvider,
private DynamicReturnTypeExtensionRegistryProvider $dynamicReturnTypeExtensionRegistryProvider,
#[AutowiredExtensions(of: DynamicStaticMethodThrowTypeExtension::class)]
private ExtensionsCollection $dynamicStaticMethodThrowTypeExtensions,
private DynamicReturnTypeExtensionRegistry $dynamicReturnTypeExtensionRegistry,
private PropertyReflectionFinder $propertyReflectionFinder,
#[AutowiredParameter(ref: '%exceptions.implicitThrows%')]
private bool $implicitThrows,
Expand Down Expand Up @@ -303,7 +309,7 @@ private function getConstructorThrowPoint(MethodReflection $constructorReflectio
$methodCall = new StaticCall($className, $constructorReflection->getName(), $args);
$normalizedMethodCall = ArgumentsNormalizer::reorderStaticCallArguments($parametersAcceptor, $methodCall);
if ($normalizedMethodCall !== null) {
foreach ($this->dynamicThrowTypeExtensionProvider->getDynamicStaticMethodThrowTypeExtensions() as $extension) {
foreach ($this->dynamicStaticMethodThrowTypeExtensions->getAll() as $extension) {
if (!$extension->isStaticMethodSupported($constructorReflection)) {
continue;
}
Expand Down Expand Up @@ -401,7 +407,7 @@ private function exactInstantiation(MutatingScope $scope, New_ $node, Name $clas
$normalizedMethodCall = ArgumentsNormalizer::reorderStaticCallArguments($parametersAcceptor, $methodCall);

if ($normalizedMethodCall !== null) {
foreach ($this->dynamicReturnTypeExtensionRegistryProvider->getRegistry()->getDynamicStaticMethodReturnTypeExtensionsForClass($classReflection->getName()) as $dynamicStaticMethodReturnTypeExtension) {
foreach ($this->dynamicReturnTypeExtensionRegistry->getDynamicStaticMethodReturnTypeExtensionsForClass($classReflection->getName()) as $dynamicStaticMethodReturnTypeExtension) {
if (!$dynamicStaticMethodReturnTypeExtension->isStaticMethodSupported($constructorMethod)) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Analyser/ExprHandlerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function resolve(Expr $expr, Container $container): ?ExprHandler

$matchedHandler = null;
/** @var ExprHandler<Expr> $exprHandler */
foreach ($container->getServicesByTag(ExprHandler::EXTENSION_TAG) as $exprHandler) {
foreach ($container->getExtensionsCollection(ExprHandler::class)->getAll() as $exprHandler) {
if (!$exprHandler->supports($expr)) {
continue;
}
Expand Down
Loading
Loading