Skip to content

Commit 69ff948

Browse files
DanielEScherzerkocsismate
authored andcommitted
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.
1 parent 3817a71 commit 69ff948

File tree

1 file changed

+63
-63
lines changed

1 file changed

+63
-63
lines changed

build/gen_stub.php

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ class Context {
183183
}
184184

185185
class ArrayType extends SimpleType {
186-
public Type $keyType;
187-
public Type $valueType;
186+
public /* readonly */ Type $keyType;
187+
public /* readonly */ Type $valueType;
188188

189189
public static function createGenericArray(): self
190190
{
@@ -222,8 +222,8 @@ public function equals(SimpleType $other): bool {
222222
}
223223

224224
class SimpleType {
225-
public string $name;
226-
public bool $isBuiltin;
225+
public /* readonly */ string $name;
226+
public /* readonly */ bool $isBuiltin;
227227

228228
public static function fromNode(Node $node): SimpleType {
229229
if ($node instanceof Node\Name) {
@@ -524,8 +524,8 @@ public function equals(SimpleType $other): bool {
524524

525525
class Type {
526526
/** @var SimpleType[] */
527-
public array $types;
528-
public bool $isIntersection;
527+
public /* readonly */ array $types;
528+
public /* readonly */ bool $isIntersection;
529529

530530
public static function fromNode(Node $node): Type {
531531
if ($node instanceof Node\UnionType || $node instanceof Node\IntersectionType) {
@@ -736,9 +736,9 @@ function ($type) { return $type->name; },
736736

737737
class ArginfoType {
738738
/** @var SimpleType[] $classTypes */
739-
public array $classTypes;
739+
public /* readonly */ array $classTypes;
740740
/** @var SimpleType[] $builtinTypes */
741-
private array $builtinTypes;
741+
private /* readonly */ array $builtinTypes;
742742

743743
/**
744744
* @param SimpleType[] $classTypes
@@ -774,11 +774,11 @@ class ArgInfo {
774774
const SEND_BY_REF = "1";
775775
const SEND_PREFER_REF = "ZEND_SEND_PREFER_REF";
776776

777-
public string $name;
778-
public string $sendBy;
779-
public bool $isVariadic;
777+
public /* readonly */ string $name;
778+
public /* readonly */ string $sendBy;
779+
public /* readonly */ bool $isVariadic;
780780
public ?Type $type;
781-
public ?Type $phpDocType;
781+
public /* readonly */ ?Type $phpDocType;
782782
public ?string $defaultValue;
783783
/** @var AttributeInfo[] */
784784
public array $attributes;
@@ -879,7 +879,7 @@ public function isUnknown(): bool
879879
}
880880

881881
class ConstName extends AbstractConstName {
882-
public string $const;
882+
public /* readonly */ string $const;
883883

884884
public function __construct(?Name $namespace, string $const)
885885
{
@@ -915,8 +915,8 @@ public function getDeclarationName(): string
915915
}
916916

917917
class ClassConstName extends AbstractConstName {
918-
public Name $class;
919-
public string $const;
918+
public /* readonly */ Name $class;
919+
public /* readonly */ string $const;
920920

921921
public function __construct(Name $class, string $const)
922922
{
@@ -941,8 +941,8 @@ public function getDeclarationName(): string
941941
}
942942

943943
class PropertyName implements VariableLikeName {
944-
public Name $class;
945-
public string $property;
944+
public /* readonly */ Name $class;
945+
public /* readonly */ string $property;
946946

947947
public function __construct(Name $class, string $property)
948948
{
@@ -973,7 +973,7 @@ public function isDestructor(): bool;
973973
}
974974

975975
class FunctionName implements FunctionOrMethodName {
976-
private Name $name;
976+
private /* readonly */ Name $name;
977977

978978
public function __construct(Name $name) {
979979
$this->name = $name;
@@ -1041,8 +1041,8 @@ public function isDestructor(): bool {
10411041
}
10421042

10431043
class MethodName implements FunctionOrMethodName {
1044-
public Name $className;
1045-
public string $methodName;
1044+
public /* readonly */ Name $className;
1045+
public /* readonly */ string $methodName;
10461046

10471047
public function __construct(Name $className, string $methodName) {
10481048
$this->className = $className;
@@ -1099,11 +1099,12 @@ class ReturnInfo {
10991099
self::REFCOUNT_N,
11001100
];
11011101

1102-
public bool $byRef;
1102+
public /* readonly */ bool $byRef;
1103+
// NOT readonly - gets removed when discarding info for older PHP versions
11031104
public ?Type $type;
1104-
public ?Type $phpDocType;
1105-
public bool $tentativeReturnType;
1106-
public string $refcount;
1105+
public /* readonly */ ?Type $phpDocType;
1106+
public /* readonly */ bool $tentativeReturnType;
1107+
public /* readonly */ string $refcount;
11071108

11081109
public function __construct(bool $byRef, ?Type $type, ?Type $phpDocType, bool $tentativeReturnType, ?string $refcount) {
11091110
$this->byRef = $byRef;
@@ -1148,19 +1149,19 @@ private function setRefcount(?string $refcount): void
11481149
}
11491150

11501151
class FuncInfo {
1151-
public FunctionOrMethodName $name;
1152-
public int $classFlags;
1152+
public /* readonly */ FunctionOrMethodName $name;
1153+
public /* readonly */ int $classFlags;
11531154
public int $flags;
1154-
public ?string $aliasType;
1155+
public /* readonly */ ?string $aliasType;
11551156
public ?FunctionOrMethodName $alias;
1156-
public bool $isDeprecated;
1157+
public /* readonly */ bool $isDeprecated;
11571158
public bool $supportsCompileTimeEval;
1158-
public bool $verify;
1159+
public /* readonly */ bool $verify;
11591160
/** @var ArgInfo[] */
1160-
public array $args;
1161-
public ReturnInfo $return;
1162-
public int $numRequiredArgs;
1163-
public ?string $cond;
1161+
public /* readonly */ array $args;
1162+
public /* readonly */ ReturnInfo $return;
1163+
public /* readonly */ int $numRequiredArgs;
1164+
public /* readonly */ ?string $cond;
11641165
public bool $isUndocumentable;
11651166
public ?int $minimumPhpVersionIdCompatibility;
11661167
/** @var AttributeInfo[] */
@@ -2100,8 +2101,7 @@ public function __clone()
21002101

21012102
class EvaluatedValue
21022103
{
2103-
/** @var mixed */
2104-
public $value;
2104+
public /* readonly */ mixed $value;
21052105
public SimpleType $type;
21062106
public Expr $expr;
21072107
public bool $isUnknownConstValue;
@@ -2284,12 +2284,12 @@ abstract class VariableLike
22842284
{
22852285
public int $flags;
22862286
public ?Type $type;
2287-
public ?Type $phpDocType;
2288-
public ?string $link;
2287+
public /* readonly */ ?Type $phpDocType;
2288+
public /* readonly */ ?string $link;
22892289
public ?int $phpVersionIdMinimumCompatibility;
22902290
/** @var AttributeInfo[] */
22912291
public array $attributes;
2292-
public ?ExposedDocComment $exposedDocComment;
2292+
public /* readonly */ ?ExposedDocComment $exposedDocComment;
22932293

22942294
/**
22952295
* @var AttributeInfo[] $attributes
@@ -2464,11 +2464,11 @@ protected function addFlagForVersionsAbove(array $flags, string $flag, int $mini
24642464

24652465
class ConstInfo extends VariableLike
24662466
{
2467-
public ConstOrClassConstName $name;
2468-
public Expr $value;
2467+
public /* readonly */ ConstOrClassConstName $name;
2468+
public /* readonly */ Expr $value;
24692469
public bool $isDeprecated;
24702470
public ?string $valueString;
2471-
public ?string $cond;
2471+
public /* readonly */ ?string $cond;
24722472
public ?string $cValue;
24732473
public bool $isUndocumentable;
24742474
public bool $isFileCacheAllowed;
@@ -2824,12 +2824,12 @@ protected function addModifiersToFieldSynopsis(DOMDocument $doc, DOMElement $fie
28242824

28252825
class PropertyInfo extends VariableLike
28262826
{
2827-
public int $classFlags;
2828-
public PropertyName $name;
2829-
public ?Expr $defaultValue;
2830-
public ?string $defaultValueString;
2831-
public bool $isDocReadonly;
2832-
public bool $isVirtual;
2827+
public /* readonly */ int $classFlags;
2828+
public /* readonly */ PropertyName $name;
2829+
public /* readonly */ ?Expr $defaultValue;
2830+
public /* readonly */ ?string $defaultValueString;
2831+
public /* readonly */ bool $isDocReadonly;
2832+
public /* readonly */ bool $isVirtual;
28332833

28342834
// Map possible variable names to the known string constant, see
28352835
// ZEND_KNOWN_STRINGS
@@ -3143,8 +3143,8 @@ public function __clone()
31433143
}
31443144

31453145
class EnumCaseInfo {
3146-
public string $name;
3147-
public ?Expr $value;
3146+
public /* readonly */ string $name;
3147+
public /* readonly */ ?Expr $value;
31483148

31493149
public function __construct(string $name, ?Expr $value) {
31503150
$this->name = $name;
@@ -3169,9 +3169,9 @@ public function getDeclaration(array $allConstInfos): string {
31693169
}
31703170

31713171
class AttributeInfo {
3172-
public string $class;
3172+
public /* readonly */ string $class;
31733173
/** @var \PhpParser\Node\Arg[] */
3174-
public array $args;
3174+
public /* readonly */ array $args;
31753175

31763176
/** @param \PhpParser\Node\Arg[] $args */
31773177
public function __construct(string $class, array $args) {
@@ -3222,30 +3222,30 @@ public function generateCode(string $invocation, string $nameSuffix, array $allC
32223222
}
32233223

32243224
class ClassInfo {
3225-
public Name $name;
3225+
public /* readonly */ Name $name;
32263226
public int $flags;
32273227
public string $type;
3228-
public ?string $alias;
3229-
public ?SimpleType $enumBackingType;
3230-
public bool $isDeprecated;
3228+
public /* readonly */ ?string $alias;
3229+
public /* readonly */ ?SimpleType $enumBackingType;
3230+
public /* readonly */ bool $isDeprecated;
32313231
public bool $isStrictProperties;
32323232
/** @var AttributeInfo[] */
32333233
public array $attributes;
32343234
public ?ExposedDocComment $exposedDocComment;
32353235
public bool $isNotSerializable;
32363236
/** @var Name[] */
3237-
public array $extends;
3237+
public /* readonly */ array $extends;
32383238
/** @var Name[] */
3239-
public array $implements;
3239+
public /* readonly */ array $implements;
32403240
/** @var ConstInfo[] */
3241-
public array $constInfos;
3241+
public /* readonly */ array $constInfos;
32423242
/** @var PropertyInfo[] */
3243-
public array $propertyInfos;
3243+
public /* readonly */ array $propertyInfos;
32443244
/** @var FuncInfo[] */
32453245
public array $funcInfos;
32463246
/** @var EnumCaseInfo[] */
3247-
public array $enumCaseInfos;
3248-
public ?string $cond;
3247+
public /* readonly */ array $enumCaseInfos;
3248+
public /* readonly */ ?string $cond;
32493249
public ?int $phpVersionIdMinimumCompatibility;
32503250
public bool $isUndocumentable;
32513251

@@ -4119,8 +4119,8 @@ public function shouldGenerateLegacyArginfo(): bool {
41194119
}
41204120

41214121
class DocCommentTag {
4122-
public string $name;
4123-
public ?string $value;
4122+
public /* readonly */ string $name;
4123+
public /* readonly */ ?string $value;
41244124

41254125
public function __construct(string $name, ?string $value) {
41264126
$this->name = $name;

0 commit comments

Comments
 (0)