Skip to content

Commit

Permalink
[GENERATED] Downgraded
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Dec 20, 2024
1 parent c375871 commit 8172e0d
Show file tree
Hide file tree
Showing 128 changed files with 1,538 additions and 1,292 deletions.
60 changes: 42 additions & 18 deletions src/BetterReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,55 @@ final class BetterReflection
{
public static int $phpVersion = PHP_VERSION_ID;

private static SourceLocator|null $sharedSourceLocator = null;
/**
* @var \Roave\BetterReflection\SourceLocator\Type\SourceLocator|null
*/
private static $sharedSourceLocator = null;

private SourceLocator|null $sourceLocator = null;
/**
* @var \Roave\BetterReflection\SourceLocator\Type\SourceLocator|null
*/
private $sourceLocator = null;

private static Reflector|null $sharedReflector = null;
/**
* @var \Roave\BetterReflection\Reflector\Reflector|null
*/
private static $sharedReflector = null;

private Reflector|null $reflector = null;
/**
* @var \Roave\BetterReflection\Reflector\Reflector|null
*/
private $reflector = null;

private static Parser|null $sharedPhpParser = null;
/**
* @var \PhpParser\Parser|null
*/
private static $sharedPhpParser = null;

private Parser|null $phpParser = null;
/**
* @var \PhpParser\Parser|null
*/
private $phpParser = null;

private AstLocator|null $astLocator = null;
/**
* @var AstLocator|null
*/
private $astLocator = null;

private FindReflectionOnLine|null $findReflectionOnLine = null;
/**
* @var \Roave\BetterReflection\Util\FindReflectionOnLine|null
*/
private $findReflectionOnLine = null;

private SourceStubber|null $sourceStubber = null;
/**
* @var \Roave\BetterReflection\SourceLocator\SourceStubber\SourceStubber|null
*/
private $sourceStubber = null;

private static SourceStubber|null $sharedSourceStubber = null;
/**
* @var \Roave\BetterReflection\SourceLocator\SourceStubber\SourceStubber|null
*/
private static $sharedSourceStubber = null;

/**
* @var Standard|null
Expand All @@ -58,14 +88,8 @@ final class BetterReflection
*/
private $printer = null;

public static function populate(
int $phpVersion,
SourceLocator $sourceLocator,
Reflector $classReflector,
Parser $phpParser,
SourceStubber $sourceStubber,
Standard $printer,
): void {
public static function populate(int $phpVersion, SourceLocator $sourceLocator, Reflector $classReflector, Parser $phpParser, SourceStubber $sourceStubber, Standard $printer): void
{
self::$phpVersion = $phpVersion;
self::$sharedSourceLocator = $sourceLocator;
self::$sharedReflector = $classReflector;
Expand Down
6 changes: 4 additions & 2 deletions src/Identifier/Identifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@

class Identifier
{
private IdentifierType $type;
public const WILDCARD = '*';

private const VALID_NAME_REGEXP = '/([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)(\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)*/';

private string $name;

/** @throws InvalidIdentifierName */
public function __construct(string $name, private IdentifierType $type)
public function __construct(string $name, IdentifierType $type)
{
$this->type = $type;
if (
$name === self::WILDCARD
|| $name === ReflectionFunction::CLOSURE_NAME
|| str_starts_with($name, ReflectionClass::ANONYMOUS_CLASS_NAME_PREFIX)
|| strncmp($name, ReflectionClass::ANONYMOUS_CLASS_NAME_PREFIX, strlen(ReflectionClass::ANONYMOUS_CLASS_NAME_PREFIX)) === 0
) {
$this->name = $name;

Expand Down
36 changes: 24 additions & 12 deletions src/NodeCompiler/CompileNodeToValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __invoke(Node $node, CompilerContext $context): CompiledValue
$constantName = $this->resolveClassConstantName($node, $context);
}

$constExprEvaluator = new ConstExprEvaluator(function (Node\Expr $node) use ($context, $constantName): mixed {
$constExprEvaluator = new ConstExprEvaluator(function (Node\Expr $node) use ($context, $constantName) {
if ($node instanceof Node\Expr\ConstFetch) {
return $this->getConstantValue($node, $constantName, $context);
}
Expand Down Expand Up @@ -111,7 +111,7 @@ public function __invoke(Node $node, CompilerContext $context): CompiledValue
}

if ($node instanceof Node\Scalar\MagicConst\Function_) {
return $context->getFunction()?->getName() ?? '';
return (($nullsafeVariable1 = $context->getFunction()) ? $nullsafeVariable1->getName() : null) ?? '';
}

if ($node instanceof Node\Scalar\MagicConst\Trait_) {
Expand Down Expand Up @@ -151,7 +151,10 @@ public function __invoke(Node $node, CompilerContext $context): CompiledValue
return new CompiledValue($value, $constantName);
}

private function getEnumPropertyValue(Node\Expr\PropertyFetch $node, CompilerContext $context): mixed
/**
* @return mixed
*/
private function getEnumPropertyValue(Node\Expr\PropertyFetch $node, CompilerContext $context)
{
assert($node->var instanceof Node\Expr\ClassConstFetch);
assert($node->var->class instanceof Node\Name);
Expand All @@ -175,11 +178,14 @@ private function getEnumPropertyValue(Node\Expr\PropertyFetch $node, CompilerCon

assert($node->name instanceof Node\Identifier);

return match ($node->name->toString()) {
'value' => $case->getValue(),
'name' => $case->getName(),
default => throw Exception\UnableToCompileNode::becauseOfInvalidEnumCasePropertyFetch($context, $class, $node),
};
switch ($node->name->toString()) {
case 'value':
return $case->getValue();
case 'name':
return $case->getName();
default:
throw Exception\UnableToCompileNode::becauseOfInvalidEnumCasePropertyFetch($context, $class, $node);
}
}

private function resolveConstantName(Node\Expr\ConstFetch $constNode, CompilerContext $context): string
Expand Down Expand Up @@ -212,12 +218,15 @@ private function constantExists(string $constantName, CompilerContext $context):
$context->getReflector()->reflectConstant($constantName);

return true;
} catch (IdentifierNotFound) {
} catch (IdentifierNotFound $exception) {
return false;
}
}

private function getConstantValue(Node\Expr\ConstFetch $node, string|null $constantName, CompilerContext $context): mixed
/**
* @return mixed
*/
private function getConstantValue(Node\Expr\ConstFetch $node, ?string $constantName, CompilerContext $context)
{
// It's not resolved when constant value is expression
// @infection-ignore-all Assignment, AssignCoalesce: There's no difference, ??= is just optimization
Expand All @@ -240,7 +249,10 @@ private function resolveClassConstantName(Node\Expr\ClassConstFetch $node, Compi
return sprintf('%s::%s', $this->resolveClassName($className, $context), $constantName);
}

private function getClassConstantValue(Node\Expr\ClassConstFetch $node, string|null $classConstantName, CompilerContext $context): mixed
/**
* @return mixed
*/
private function getClassConstantValue(Node\Expr\ClassConstFetch $node, ?string $classConstantName, CompilerContext $context)
{
// It's not resolved when constant value is expression
// @infection-ignore-all Assignment, AssignCoalesce: There's no difference, ??= is just optimization
Expand Down Expand Up @@ -336,7 +348,7 @@ private function compileFileConstant(CompilerContext $context, Node\Scalar\Magic
*/
private function compileClassConstant(CompilerContext $context): string
{
return $context->getClass()?->getName() ?? '';
return (($nullsafeVariable2 = $context->getClass()) ? $nullsafeVariable2->getName() : null) ?? '';
}

private function resolveClassName(string $className, CompilerContext $context): string
Expand Down
15 changes: 14 additions & 1 deletion src/NodeCompiler/CompiledValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@
/** @internal */
class CompiledValue
{
public function __construct(public mixed $value, public string|null $constantName = null)
/**
* @var mixed
*/
public $value;
/**
* @var string|null
*/
public $constantName = null;
/**
* @param mixed $value
*/
public function __construct($value, ?string $constantName = null)
{
$this->value = $value;
$this->constantName = $constantName;
}
}
32 changes: 21 additions & 11 deletions src/NodeCompiler/CompilerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,26 @@
/** @internal */
class CompilerContext
{
public function __construct(
private Reflector $reflector,
private ReflectionClass|ReflectionProperty|ReflectionClassConstant|ReflectionEnumCase|ReflectionMethod|ReflectionFunction|ReflectionParameter|ReflectionConstant $contextReflection,
) {
private Reflector $reflector;
/**
* @var \Roave\BetterReflection\Reflection\ReflectionClass|\Roave\BetterReflection\Reflection\ReflectionProperty|\Roave\BetterReflection\Reflection\ReflectionClassConstant|\Roave\BetterReflection\Reflection\ReflectionEnumCase|\Roave\BetterReflection\Reflection\ReflectionMethod|\Roave\BetterReflection\Reflection\ReflectionFunction|\Roave\BetterReflection\Reflection\ReflectionParameter|\Roave\BetterReflection\Reflection\ReflectionConstant
*/
private $contextReflection;
/**
* @param \Roave\BetterReflection\Reflection\ReflectionClass|\Roave\BetterReflection\Reflection\ReflectionProperty|\Roave\BetterReflection\Reflection\ReflectionClassConstant|\Roave\BetterReflection\Reflection\ReflectionEnumCase|\Roave\BetterReflection\Reflection\ReflectionMethod|\Roave\BetterReflection\Reflection\ReflectionFunction|\Roave\BetterReflection\Reflection\ReflectionParameter|\Roave\BetterReflection\Reflection\ReflectionConstant $contextReflection
*/
public function __construct(Reflector $reflector, $contextReflection)
{
$this->reflector = $reflector;
$this->contextReflection = $contextReflection;
}

public function getReflector(): Reflector
{
return $this->reflector;
}

/** @return non-empty-string|null */
public function getFileName(): string|null
public function getFileName(): ?string
{
if ($this->contextReflection instanceof ReflectionConstant) {
$fileName = $this->contextReflection->getFileName();
Expand All @@ -41,7 +48,7 @@ public function getFileName(): string|null
return $this->realPath($fileName);
}

$fileName = $this->getClass()?->getFileName() ?? $this->getFunction()?->getFileName();
$fileName = (($nullsafeVariable1 = $this->getClass()) ? $nullsafeVariable1->getFileName() : null) ?? (($nullsafeVariable2 = $this->getFunction()) ? $nullsafeVariable2->getFileName() : null);
if ($fileName === null) {
return null;
}
Expand All @@ -54,17 +61,17 @@ private function realPath(string $fileName): string
return FileHelper::normalizePath($fileName, '/');
}

public function getNamespace(): string|null
public function getNamespace(): ?string
{
if ($this->contextReflection instanceof ReflectionConstant) {
return $this->contextReflection->getNamespaceName();
}

// @infection-ignore-all Coalesce: There's no difference
return $this->getClass()?->getNamespaceName() ?? $this->getFunction()?->getNamespaceName();
return (($nullsafeVariable3 = $this->getClass()) ? $nullsafeVariable3->getNamespaceName() : null) ?? (($nullsafeVariable4 = $this->getFunction()) ? $nullsafeVariable4->getNamespaceName() : null);
}

public function getClass(): ReflectionClass|null
public function getClass(): ?\Roave\BetterReflection\Reflection\ReflectionClass
{
if ($this->contextReflection instanceof ReflectionClass) {
return $this->contextReflection;
Expand All @@ -89,7 +96,10 @@ public function getClass(): ReflectionClass|null
return $this->contextReflection->getImplementingClass();
}

public function getFunction(): ReflectionMethod|ReflectionFunction|null
/**
* @return \Roave\BetterReflection\Reflection\ReflectionMethod|\Roave\BetterReflection\Reflection\ReflectionFunction|null
*/
public function getFunction()
{
if ($this->contextReflection instanceof ReflectionMethod) {
return $this->contextReflection;
Expand Down
Loading

0 comments on commit 8172e0d

Please sign in to comment.