Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce isDeprecated to CallableParametersAcceptor #3616

Open
wants to merge 1 commit into
base: 1.12.x
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions src/Reflection/CallableFunctionVariantWithPhpDocs.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function __construct(
?TemplateTypeVarianceMap $callSiteVarianceMap,
private array $throwPoints,
private TrinaryLogic $isPure,
private TrinaryLogic $isDeprecated,
private array $impurePoints,
private array $invalidateExpressions,
private array $usedVariables,
Expand Down Expand Up @@ -60,6 +61,11 @@ public function isPure(): TrinaryLogic
return $this->isPure;
}

public function isDeprecated(): TrinaryLogic
{
return $this->isDeprecated;
}

public function getImpurePoints(): array
{
return $this->impurePoints;
Expand Down
2 changes: 2 additions & 0 deletions src/Reflection/Callables/CallableParametersAcceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public function getThrowPoints(): array;

public function isPure(): TrinaryLogic;

public function isDeprecated(): TrinaryLogic;

public function acceptsNamedArguments(): bool;

/**
Expand Down
5 changes: 5 additions & 0 deletions src/Reflection/Callables/FunctionCallableVariant.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ public function isPure(): TrinaryLogic
return $certainCount > 0 ? TrinaryLogic::createNo() : TrinaryLogic::createMaybe();
}

public function isDeprecated(): TrinaryLogic
{
return $this->function->isDeprecated();
}

public function getImpurePoints(): array
{
if ($this->impurePoints !== null) {
Expand Down
1 change: 1 addition & 0 deletions src/Reflection/GenericParametersAcceptorResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public static function resolve(array $argTypes, ParametersAcceptor $parametersAc
$result,
$originalParametersAcceptor->getThrowPoints(),
$originalParametersAcceptor->isPure(),
$originalParametersAcceptor->isDeprecated(),
$originalParametersAcceptor->getImpurePoints(),
$originalParametersAcceptor->getInvalidateExpressions(),
$originalParametersAcceptor->getUsedVariables(),
Expand Down
5 changes: 5 additions & 0 deletions src/Reflection/InaccessibleMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public function isPure(): TrinaryLogic
return TrinaryLogic::createMaybe();
}

public function isDeprecated(): TrinaryLogic
{
return $this->methodReflection->isDeprecated();
}

public function getImpurePoints(): array
{
return [
Expand Down
4 changes: 4 additions & 0 deletions src/Reflection/ParametersAcceptorSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ public static function combineAcceptors(array $acceptors): ParametersAcceptorWit
$callableOccurred = false;
$throwPoints = [];
$isPure = TrinaryLogic::createNo();
$isDeprecated = TrinaryLogic::createNo();
$impurePoints = [];
$invalidateExpressions = [];
$usedVariables = [];
Expand All @@ -651,6 +652,7 @@ public static function combineAcceptors(array $acceptors): ParametersAcceptorWit
$callableOccurred = true;
$throwPoints = array_merge($throwPoints, $acceptor->getThrowPoints());
$isPure = $isPure->or($acceptor->isPure());
$isDeprecated = $isDeprecated->or($acceptor->isDeprecated());
$impurePoints = array_merge($impurePoints, $acceptor->getImpurePoints());
$invalidateExpressions = array_merge($invalidateExpressions, $acceptor->getInvalidateExpressions());
$usedVariables = array_merge($usedVariables, $acceptor->getUsedVariables());
Expand Down Expand Up @@ -753,6 +755,7 @@ public static function combineAcceptors(array $acceptors): ParametersAcceptorWit
null,
$throwPoints,
$isPure,
$isDeprecated,
$impurePoints,
$invalidateExpressions,
$usedVariables,
Expand Down Expand Up @@ -789,6 +792,7 @@ private static function wrapAcceptor(ParametersAcceptor $acceptor): ParametersAc
TemplateTypeVarianceMap::createEmpty(),
$acceptor->getThrowPoints(),
$acceptor->isPure(),
$acceptor->isDeprecated(),
$acceptor->getImpurePoints(),
$acceptor->getInvalidateExpressions(),
$acceptor->getUsedVariables(),
Expand Down
6 changes: 6 additions & 0 deletions src/Reflection/ResolvedFunctionVariantWithCallable.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function __construct(
private ResolvedFunctionVariant $parametersAcceptor,
private array $throwPoints,
private TrinaryLogic $isPure,
private TrinaryLogic $isDeprecated,
private array $impurePoints,
private array $invalidateExpressions,
private array $usedVariables,
Expand Down Expand Up @@ -97,6 +98,11 @@ public function isPure(): TrinaryLogic
return $this->isPure;
}

public function isDeprecated(): TrinaryLogic
{
return $this->isDeprecated;
}

public function getImpurePoints(): array
{
return $this->impurePoints;
Expand Down
5 changes: 5 additions & 0 deletions src/Reflection/TrivialParametersAcceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public function isPure(): TrinaryLogic
return TrinaryLogic::createMaybe();
}

public function isDeprecated(): TrinaryLogic
{
return TrinaryLogic::createNo();
}

public function getImpurePoints(): array
{
return [
Expand Down
1 change: 1 addition & 0 deletions src/Rules/RuleLevelHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ private function transformAcceptedType(Type $acceptingType, Type $acceptedType):
$acceptedType->getResolvedTemplateTypeMap(),
$acceptedType->getTemplateTags(),
$acceptedType->isPure(),
$acceptedType->isDeprecated(),
);
}

Expand Down
13 changes: 13 additions & 0 deletions src/Type/CallableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class CallableType implements CompoundType, CallableParametersAcceptor

private TrinaryLogic $isPure;

private TrinaryLogic $isDeprecated;

/**
* @api
* @param array<int, ParameterReflection>|null $parameters
Expand All @@ -78,6 +80,7 @@ public function __construct(
?TemplateTypeMap $resolvedTemplateTypeMap = null,
private array $templateTags = [],
?TrinaryLogic $isPure = null,
?TrinaryLogic $isDeprecated = null,
)
{
$this->parameters = $parameters ?? [];
Expand All @@ -86,6 +89,7 @@ public function __construct(
$this->templateTypeMap = $templateTypeMap ?? TemplateTypeMap::createEmpty();
$this->resolvedTemplateTypeMap = $resolvedTemplateTypeMap ?? TemplateTypeMap::createEmpty();
$this->isPure = $isPure ?? TrinaryLogic::createMaybe();
$this->isDeprecated = $isDeprecated ?? TrinaryLogic::createNo();
}

/**
Expand All @@ -101,6 +105,11 @@ public function isPure(): TrinaryLogic
return $this->isPure;
}

public function isDeprecated(): TrinaryLogic
{
return $this->isDeprecated;
}

/**
* @return string[]
*/
Expand Down Expand Up @@ -254,6 +263,7 @@ function (): string {
$this->resolvedTemplateTypeMap,
$this->templateTags,
$this->isPure,
$this->isDeprecated,
);

return $printer->print($selfWithoutParameterNames->toPhpDocNode());
Expand Down Expand Up @@ -468,6 +478,7 @@ public function traverse(callable $cb): Type
$this->resolvedTemplateTypeMap,
$this->templateTags,
$this->isPure,
$this->isDeprecated,
);
}

Expand Down Expand Up @@ -518,6 +529,7 @@ public function traverseSimultaneously(Type $right, callable $cb): Type
$this->resolvedTemplateTypeMap,
$this->templateTags,
$this->isPure,
$this->isDeprecated,
);
}

Expand Down Expand Up @@ -703,6 +715,7 @@ public static function __set_state(array $properties): Type
$properties['resolvedTemplateTypeMap'],
$properties['templateTags'],
$properties['isPure'],
$properties['isDeprecated'],
);
}

Expand Down
5 changes: 5 additions & 0 deletions src/Type/ClosureType.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ public function isPure(): TrinaryLogic
return $certainCount > 0 ? TrinaryLogic::createNo() : TrinaryLogic::createMaybe();
}

public function isDeprecated(): TrinaryLogic
{
return TrinaryLogic::createNo();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the case. First-class callables like Foo::method(...) are resolved to ClosureType so the deprecated-ness should be carried over.

}

public function getClassName(): string
{
return $this->objectType->getClassName();
Expand Down
Loading