Skip to content

Commit

Permalink
fix error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvsk committed Apr 7, 2023
1 parent 8b45e6f commit abea3db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions example/php7.4/Genre.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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]);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Generator/Builder/EnumLegacyBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('}');

Expand All @@ -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('}')
Expand Down

0 comments on commit abea3db

Please sign in to comment.