class LegacyPropertyHelper

Reads configuration property declarations and the class attributes that can replace them, for the rules recommending attributes over legacy model and queue properties.

Values are PHP constants, with an enum case held as its PHPStan type.

Methods

__construct(ReflectionProvider $reflectionProvider, InitializerExprTypeResolver $initializerExprTypeResolver, ConstructorParser $constructorParser)

Create a new legacy property helper instance.

array
declarations(ClassReflection $classReflection, ClassLike $class, array $properties, array $setters)

Get the class's own fixed declarations of the given properties, and those of the traits it uses directly.

array|null
inheritedDefault(ClassReflection $classReflection, string $name)

Get the default a property has without the class's own declaration: its parent's, with the class declaring it there and whether it is public. Null when that default is not one constant.

array
attributeLevels(ClassReflection $classReflection, array $attributeClasses, string|null $baseClass)

Get the given attributes on the class and each parent below the base class, nearest first, as the runtime reads them: each class's own, then those of the traits it uses directly, in order.

array|null
nearestAttribute(array $levels, string $attributeClass)

Find the nearest of the levels' attributes of a class: a class's own, then its traits' in order.

void
trackSources(ClassReflection $classReflection, array $attributeClasses, string|null $baseClass, Scope $scope)

Track the files a class's property defaults, constructors and read attribute arguments come from.

bool
same(mixed $first, mixed $second)

Determine whether two values are the same, comparing enum cases by their case.

string
render(mixed $value)

Write a value as PHP code.

string
printExpression(Expr $expression)

Write a declared default as written, when an attribute on the same class takes its value.

Details

at line 44
__construct(ReflectionProvider $reflectionProvider, InitializerExprTypeResolver $initializerExprTypeResolver, ConstructorParser $constructorParser)

Create a new legacy property helper instance.

Parameters

ReflectionProvider $reflectionProvider
InitializerExprTypeResolver $initializerExprTypeResolver
ConstructorParser $constructorParser

at line 66
array declarations(ClassReflection $classReflection, ClassLike $class, array $properties, array $setters)

Get the class's own fixed declarations of the given properties, and those of the traits it uses directly.

A property with no default, one the constructor may change, or one whose default is not a single constant holds per-instance state or cannot move to an attribute, so it is left out. A trait's declaration is included when the class uses that trait directly, no other direct trait declares the property, and its default means the same in the trait, since attribute lookup reads no nested traits and an attribute on the trait reads its arguments there. Its line is in the trait's file.

Parameters

ClassReflection $classReflection
ClassLike $class
array $properties
array $setters

the instance methods changing each property

Return Value

array

at line 131
array|null inheritedDefault(ClassReflection $classReflection, string $name)

Get the default a property has without the class's own declaration: its parent's, with the class declaring it there and whether it is public. Null when that default is not one constant.

Parameters

ClassReflection $classReflection
string $name

Return Value

array|null

at line 165
array attributeLevels(ClassReflection $classReflection, array $attributeClasses, string|null $baseClass)

Get the given attributes on the class and each parent below the base class, nearest first, as the runtime reads them: each class's own, then those of the traits it uses directly, in order.

Each attribute holds its constructor arguments by parameter name, a variadic parameter's as a list. The attributes whose arguments are not all single constants are listed apart, wherever they are.

Parameters

ClassReflection $classReflection
array $attributeClasses
string|null $baseClass

Return Value

array

at line 210
array|null nearestAttribute(array $levels, string $attributeClass)

Find the nearest of the levels' attributes of a class: a class's own, then its traits' in order.

Parameters

array $levels
string $attributeClass

Return Value

array|null

the attribute's arguments and the class the runtime treats as declaring it

at line 231
void trackSources(ClassReflection $classReflection, array $attributeClasses, string|null $baseClass, Scope $scope)

Track the files a class's property defaults, constructors and read attribute arguments come from.

They are not declarations, whose changes alone reanalyze the class's file.

Parameters

ClassReflection $classReflection
array $attributeClasses
string|null $baseClass
Scope $scope

Return Value

void

at line 257
bool same(mixed $first, mixed $second)

Determine whether two values are the same, comparing enum cases by their case.

Parameters

mixed $first
mixed $second

Return Value

bool

at line 269
string render(mixed $value)

Write a value as PHP code.

Parameters

mixed $value

Return Value

string

at line 294
string printExpression(Expr $expression)

Write a declared default as written, when an attribute on the same class takes its value.

Parameters

Expr $expression

Return Value

string