From 69ff948d39fc917cb5069b52139b7b816dfe34b4 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Mon, 7 Oct 2024 19:35:16 -0700 Subject: [PATCH] gen_stub: document a bunch of properties as read-only In the hopes that it will be clearer that some of the custom clone handling can be removed the way it was for `ExposedDocComment`, instances of which were immutable, document a bunch of properties of other classes as read-only. --- build/gen_stub.php | 126 ++++++++++++++++++++++----------------------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index 20f9ec8fd8067..5661f82c9e1d9 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -183,8 +183,8 @@ class Context { } class ArrayType extends SimpleType { - public Type $keyType; - public Type $valueType; + public /* readonly */ Type $keyType; + public /* readonly */ Type $valueType; public static function createGenericArray(): self { @@ -222,8 +222,8 @@ public function equals(SimpleType $other): bool { } class SimpleType { - public string $name; - public bool $isBuiltin; + public /* readonly */ string $name; + public /* readonly */ bool $isBuiltin; public static function fromNode(Node $node): SimpleType { if ($node instanceof Node\Name) { @@ -524,8 +524,8 @@ public function equals(SimpleType $other): bool { class Type { /** @var SimpleType[] */ - public array $types; - public bool $isIntersection; + public /* readonly */ array $types; + public /* readonly */ bool $isIntersection; public static function fromNode(Node $node): Type { if ($node instanceof Node\UnionType || $node instanceof Node\IntersectionType) { @@ -736,9 +736,9 @@ function ($type) { return $type->name; }, class ArginfoType { /** @var SimpleType[] $classTypes */ - public array $classTypes; + public /* readonly */ array $classTypes; /** @var SimpleType[] $builtinTypes */ - private array $builtinTypes; + private /* readonly */ array $builtinTypes; /** * @param SimpleType[] $classTypes @@ -774,11 +774,11 @@ class ArgInfo { const SEND_BY_REF = "1"; const SEND_PREFER_REF = "ZEND_SEND_PREFER_REF"; - public string $name; - public string $sendBy; - public bool $isVariadic; + public /* readonly */ string $name; + public /* readonly */ string $sendBy; + public /* readonly */ bool $isVariadic; public ?Type $type; - public ?Type $phpDocType; + public /* readonly */ ?Type $phpDocType; public ?string $defaultValue; /** @var AttributeInfo[] */ public array $attributes; @@ -879,7 +879,7 @@ public function isUnknown(): bool } class ConstName extends AbstractConstName { - public string $const; + public /* readonly */ string $const; public function __construct(?Name $namespace, string $const) { @@ -915,8 +915,8 @@ public function getDeclarationName(): string } class ClassConstName extends AbstractConstName { - public Name $class; - public string $const; + public /* readonly */ Name $class; + public /* readonly */ string $const; public function __construct(Name $class, string $const) { @@ -941,8 +941,8 @@ public function getDeclarationName(): string } class PropertyName implements VariableLikeName { - public Name $class; - public string $property; + public /* readonly */ Name $class; + public /* readonly */ string $property; public function __construct(Name $class, string $property) { @@ -973,7 +973,7 @@ public function isDestructor(): bool; } class FunctionName implements FunctionOrMethodName { - private Name $name; + private /* readonly */ Name $name; public function __construct(Name $name) { $this->name = $name; @@ -1041,8 +1041,8 @@ public function isDestructor(): bool { } class MethodName implements FunctionOrMethodName { - public Name $className; - public string $methodName; + public /* readonly */ Name $className; + public /* readonly */ string $methodName; public function __construct(Name $className, string $methodName) { $this->className = $className; @@ -1099,11 +1099,12 @@ class ReturnInfo { self::REFCOUNT_N, ]; - public bool $byRef; + public /* readonly */ bool $byRef; + // NOT readonly - gets removed when discarding info for older PHP versions public ?Type $type; - public ?Type $phpDocType; - public bool $tentativeReturnType; - public string $refcount; + public /* readonly */ ?Type $phpDocType; + public /* readonly */ bool $tentativeReturnType; + public /* readonly */ string $refcount; public function __construct(bool $byRef, ?Type $type, ?Type $phpDocType, bool $tentativeReturnType, ?string $refcount) { $this->byRef = $byRef; @@ -1148,19 +1149,19 @@ private function setRefcount(?string $refcount): void } class FuncInfo { - public FunctionOrMethodName $name; - public int $classFlags; + public /* readonly */ FunctionOrMethodName $name; + public /* readonly */ int $classFlags; public int $flags; - public ?string $aliasType; + public /* readonly */ ?string $aliasType; public ?FunctionOrMethodName $alias; - public bool $isDeprecated; + public /* readonly */ bool $isDeprecated; public bool $supportsCompileTimeEval; - public bool $verify; + public /* readonly */ bool $verify; /** @var ArgInfo[] */ - public array $args; - public ReturnInfo $return; - public int $numRequiredArgs; - public ?string $cond; + public /* readonly */ array $args; + public /* readonly */ ReturnInfo $return; + public /* readonly */ int $numRequiredArgs; + public /* readonly */ ?string $cond; public bool $isUndocumentable; public ?int $minimumPhpVersionIdCompatibility; /** @var AttributeInfo[] */ @@ -2100,8 +2101,7 @@ public function __clone() class EvaluatedValue { - /** @var mixed */ - public $value; + public /* readonly */ mixed $value; public SimpleType $type; public Expr $expr; public bool $isUnknownConstValue; @@ -2284,12 +2284,12 @@ abstract class VariableLike { public int $flags; public ?Type $type; - public ?Type $phpDocType; - public ?string $link; + public /* readonly */ ?Type $phpDocType; + public /* readonly */ ?string $link; public ?int $phpVersionIdMinimumCompatibility; /** @var AttributeInfo[] */ public array $attributes; - public ?ExposedDocComment $exposedDocComment; + public /* readonly */ ?ExposedDocComment $exposedDocComment; /** * @var AttributeInfo[] $attributes @@ -2464,11 +2464,11 @@ protected function addFlagForVersionsAbove(array $flags, string $flag, int $mini class ConstInfo extends VariableLike { - public ConstOrClassConstName $name; - public Expr $value; + public /* readonly */ ConstOrClassConstName $name; + public /* readonly */ Expr $value; public bool $isDeprecated; public ?string $valueString; - public ?string $cond; + public /* readonly */ ?string $cond; public ?string $cValue; public bool $isUndocumentable; public bool $isFileCacheAllowed; @@ -2824,12 +2824,12 @@ protected function addModifiersToFieldSynopsis(DOMDocument $doc, DOMElement $fie class PropertyInfo extends VariableLike { - public int $classFlags; - public PropertyName $name; - public ?Expr $defaultValue; - public ?string $defaultValueString; - public bool $isDocReadonly; - public bool $isVirtual; + public /* readonly */ int $classFlags; + public /* readonly */ PropertyName $name; + public /* readonly */ ?Expr $defaultValue; + public /* readonly */ ?string $defaultValueString; + public /* readonly */ bool $isDocReadonly; + public /* readonly */ bool $isVirtual; // Map possible variable names to the known string constant, see // ZEND_KNOWN_STRINGS @@ -3143,8 +3143,8 @@ public function __clone() } class EnumCaseInfo { - public string $name; - public ?Expr $value; + public /* readonly */ string $name; + public /* readonly */ ?Expr $value; public function __construct(string $name, ?Expr $value) { $this->name = $name; @@ -3169,9 +3169,9 @@ public function getDeclaration(array $allConstInfos): string { } class AttributeInfo { - public string $class; + public /* readonly */ string $class; /** @var \PhpParser\Node\Arg[] */ - public array $args; + public /* readonly */ array $args; /** @param \PhpParser\Node\Arg[] $args */ public function __construct(string $class, array $args) { @@ -3222,30 +3222,30 @@ public function generateCode(string $invocation, string $nameSuffix, array $allC } class ClassInfo { - public Name $name; + public /* readonly */ Name $name; public int $flags; public string $type; - public ?string $alias; - public ?SimpleType $enumBackingType; - public bool $isDeprecated; + public /* readonly */ ?string $alias; + public /* readonly */ ?SimpleType $enumBackingType; + public /* readonly */ bool $isDeprecated; public bool $isStrictProperties; /** @var AttributeInfo[] */ public array $attributes; public ?ExposedDocComment $exposedDocComment; public bool $isNotSerializable; /** @var Name[] */ - public array $extends; + public /* readonly */ array $extends; /** @var Name[] */ - public array $implements; + public /* readonly */ array $implements; /** @var ConstInfo[] */ - public array $constInfos; + public /* readonly */ array $constInfos; /** @var PropertyInfo[] */ - public array $propertyInfos; + public /* readonly */ array $propertyInfos; /** @var FuncInfo[] */ public array $funcInfos; /** @var EnumCaseInfo[] */ - public array $enumCaseInfos; - public ?string $cond; + public /* readonly */ array $enumCaseInfos; + public /* readonly */ ?string $cond; public ?int $phpVersionIdMinimumCompatibility; public bool $isUndocumentable; @@ -4119,8 +4119,8 @@ public function shouldGenerateLegacyArginfo(): bool { } class DocCommentTag { - public string $name; - public ?string $value; + public /* readonly */ string $name; + public /* readonly */ ?string $value; public function __construct(string $name, ?string $value) { $this->name = $name;