From abea3dbac1b684ca5174ba23acc5b3a5941966f4 Mon Sep 17 00:00:00 2001 From: klkvsk Date: Fri, 7 Apr 2023 15:43:50 +0300 Subject: [PATCH] fix error messages --- example/php7.4/Genre.php | 8 ++++---- src/Generator/Builder/EnumLegacyBuilder.php | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/example/php7.4/Genre.php b/example/php7.4/Genre.php index ff920e7..04b3ea9 100644 --- a/example/php7.4/Genre.php +++ b/example/php7.4/Genre.php @@ -54,15 +54,15 @@ public static function cases(): array return [self::ROMANCE(), self::COMEDY(), self::DRAMA(), self::NON_FICTION(), self::SCIENTIFIC_WORK()]; } - public function __get($propertyName) + public function __get($name) { - switch ($propertyName) { + switch ($name) { case "name": return $this->name; case "value": return $this->value; default: - trigger_error("Undefined property: Genre::$propertyName"); + trigger_error("Undefined property: Genre::$name", E_USER_WARNING); return null; } } @@ -72,7 +72,7 @@ public static function __callStatic($name, $args) $instance = self::$instances[$name] ?? null; if ($instance === null) { if (!array_key_exists($name, self::$cases)) { - throw new \ValueError("unknown case '$name'"); + throw new \ValueError("unknown case 'Genre::$name'"); } self::$instances[$name] = $instance = new self($name, self::$cases[$name]); } diff --git a/src/Generator/Builder/EnumLegacyBuilder.php b/src/Generator/Builder/EnumLegacyBuilder.php index a39934a..099923a 100644 --- a/src/Generator/Builder/EnumLegacyBuilder.php +++ b/src/Generator/Builder/EnumLegacyBuilder.php @@ -61,15 +61,15 @@ public function build(Enum $enum, PhpNamespace $ns): EnumType|ClassType $class ->addMethod('__get') - ->setParameters([ new Parameter('propertyName') ]) + ->setParameters([ new Parameter('name') ]) ->setPublic() - ->addBody('switch ($propertyName) {') + ->addBody('switch ($name) {') ->addBody(' case "name":') ->addBody(' return $this->name;') ->addBody(' case "value":') ->addBody(' return $this->value;') ->addBody(' default:') - ->addBody(' trigger_error("Undefined property: ' . $enum->getShortName() . '::$propertyName");') + ->addBody(' trigger_error("Undefined property: ' . $enum->getShortName() . '::$name", E_USER_WARNING);') ->addBody(' return null;') ->addBody('}'); @@ -81,7 +81,7 @@ public function build(Enum $enum, PhpNamespace $ns): EnumType|ClassType ->addBody('$instance = self::$instances[$name] ?? null;') ->addBody('if ($instance === null) {') ->addBody(' if (!array_key_exists($name, self::$cases)) {') - ->addBody(' throw new \ValueError("unknown case \'$name\'");') + ->addBody(' throw new \ValueError("unknown case ?");', [ new Literal("'{$enum->getShortName()}::\$name'") ]) ->addBody(' }') ->addBody(' self::$instances[$name] = $instance = new self($name, self::$cases[$name]);') ->addBody('}')