From d2220a407bfc9a8a669c859332f950eaebeab67c Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Fri, 4 Oct 2024 18:11:17 -0700 Subject: [PATCH] gen_stub: inline single-use static SimpleType constructors The following one-line methods, only used in `SimpleType::fromValue()`, were inlined: * `SimpleType::bool()` * `SimpleType::int()` * `SimpleType::float()` * `SimpleType::string()` * `SimpleType::array()` * `SimpleType::object()` Doing so removes an unneeded level of indirection and helps simplify the class. --- build/gen_stub.php | 42 ++++++------------------------------------ 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index f49958243cf..a435ed0a9e5 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -306,17 +306,17 @@ class SimpleType { case "NULL": return SimpleType::null(); case "boolean": - return SimpleType::bool(); + return new SimpleType("bool", true); case "integer": - return SimpleType::int(); + return new SimpleType("int", true); case "double": - return SimpleType::float(); + return new SimpleType("float", true); case "string": - return SimpleType::string(); + return new SimpleType("string", true); case "array": - return SimpleType::array(); + return new SimpleType("array", true); case "object": - return SimpleType::object(); + return new SimpleType("object", true); default: throw new Exception("Type \"" . gettype($value) . "\" cannot be inferred based on value"); } @@ -327,36 +327,6 @@ class SimpleType { return new SimpleType("null", true); } - public static function bool(): SimpleType - { - return new SimpleType("bool", true); - } - - public static function int(): SimpleType - { - return new SimpleType("int", true); - } - - public static function float(): SimpleType - { - return new SimpleType("float", true); - } - - public static function string(): SimpleType - { - return new SimpleType("string", true); - } - - public static function array(): SimpleType - { - return new SimpleType("array", true); - } - - public static function object(): SimpleType - { - return new SimpleType("object", true); - } - protected function __construct(string $name, bool $isBuiltin) { $this->name = $name; $this->isBuiltin = $isBuiltin;