Skip to content

Commit cc77b6f

Browse files
gen_stub: move constructors above other methods
In preparation for using constructor property promotion
1 parent 0b70abc commit cc77b6f

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

build/gen_stub.php

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,6 @@ class ArrayType extends SimpleType {
231231
private readonly Type $keyType;
232232
private readonly Type $valueType;
233233

234-
public static function createGenericArray(): self
235-
{
236-
return new ArrayType(Type::fromString("int|string"), Type::fromString("mixed|ref"));
237-
}
238-
239234
public function __construct(Type $keyType, Type $valueType)
240235
{
241236
parent::__construct("array", true);
@@ -244,6 +239,11 @@ public function __construct(Type $keyType, Type $valueType)
244239
$this->valueType = $valueType;
245240
}
246241

242+
public static function createGenericArray(): self
243+
{
244+
return new ArrayType(Type::fromString("int|string"), Type::fromString("mixed|ref"));
245+
}
246+
247247
public function toOptimizerTypeMask(): string {
248248
$typeMasks = [
249249
parent::toOptimizerTypeMask(),
@@ -270,6 +270,11 @@ class SimpleType {
270270
public readonly string $name;
271271
public readonly bool $isBuiltin;
272272

273+
protected function __construct(string $name, bool $isBuiltin) {
274+
$this->name = $name;
275+
$this->isBuiltin = $isBuiltin;
276+
}
277+
273278
public static function fromNode(Node $node): SimpleType {
274279
if ($node instanceof Node\Name) {
275280
if ($node->toLowerString() === 'static') {
@@ -364,11 +369,6 @@ public static function null(): SimpleType
364369
return new SimpleType("null", true);
365370
}
366371

367-
protected function __construct(string $name, bool $isBuiltin) {
368-
$this->name = $name;
369-
$this->isBuiltin = $isBuiltin;
370-
}
371-
372372
public function isScalar(): bool {
373373
return $this->isBuiltin && in_array($this->name, ["null", "false", "true", "bool", "int", "float"], true);
374374
}
@@ -502,6 +502,14 @@ class Type {
502502
public readonly array $types;
503503
public readonly bool $isIntersection;
504504

505+
/**
506+
* @param SimpleType[] $types
507+
*/
508+
private function __construct(array $types, bool $isIntersection) {
509+
$this->types = $types;
510+
$this->isIntersection = $isIntersection;
511+
}
512+
505513
public static function fromNode(Node $node): Type {
506514
if ($node instanceof Node\UnionType || $node instanceof Node\IntersectionType) {
507515
$nestedTypeObjects = array_map(Type::fromNode(...), $node->types);
@@ -573,14 +581,6 @@ public static function fromString(string $typeString): self {
573581
return new Type($simpleTypes, $isIntersection);
574582
}
575583

576-
/**
577-
* @param SimpleType[] $types
578-
*/
579-
private function __construct(array $types, bool $isIntersection) {
580-
$this->types = $types;
581-
$this->isIntersection = $isIntersection;
582-
}
583-
584584
public function isScalar(): bool {
585585
return !array_any($this->types, static fn (SimpleType $type): bool => !$type->isScalar());
586586
}
@@ -2216,6 +2216,19 @@ class EvaluatedValue
22162216
/** @var ConstInfo[] */
22172217
public array $originatingConsts;
22182218

2219+
/**
2220+
* @param mixed $value
2221+
* @param ConstInfo[] $originatingConsts
2222+
*/
2223+
private function __construct($value, SimpleType $type, Expr $expr, array $originatingConsts, bool $isUnknownConstValue)
2224+
{
2225+
$this->value = $value;
2226+
$this->type = $type;
2227+
$this->expr = $expr;
2228+
$this->originatingConsts = $originatingConsts;
2229+
$this->isUnknownConstValue = $isUnknownConstValue;
2230+
}
2231+
22192232
/**
22202233
* @param array<string, ConstInfo> $allConstInfos
22212234
*/
@@ -2322,19 +2335,6 @@ public static function null(): EvaluatedValue
23222335
return new self(null, SimpleType::null(), new Expr\ConstFetch(new Node\Name('null')), [], false);
23232336
}
23242337

2325-
/**
2326-
* @param mixed $value
2327-
* @param ConstInfo[] $originatingConsts
2328-
*/
2329-
private function __construct($value, SimpleType $type, Expr $expr, array $originatingConsts, bool $isUnknownConstValue)
2330-
{
2331-
$this->value = $value;
2332-
$this->type = $type;
2333-
$this->expr = $expr;
2334-
$this->originatingConsts = $originatingConsts;
2335-
$this->isUnknownConstValue = $isUnknownConstValue;
2336-
}
2337-
23382338
public function initializeZval(string $zvalName, bool $alreadyExists = false, string $forStringDef = ''): string
23392339
{
23402340
$cExpr = $this->getCExpr();

0 commit comments

Comments
 (0)