From a1900d7e23adcc710b76cdeacba6f1fc0d53f1b5 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Wed, 16 Aug 2023 14:18:21 +0300 Subject: [PATCH] Making PHPStan happy --- src/codegen.inc.php | 4 ++-- tpl/macro.twig | 13 +++++-------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/codegen.inc.php b/src/codegen.inc.php index 368671d..b87c96f 100644 --- a/src/codegen.inc.php +++ b/src/codegen.inc.php @@ -221,7 +221,7 @@ function data2value($name, \mtgType $type, $buf, $prefix = '', $tokens = array() $str .= $cond_indent."{$pname} = \metagen_php\\val_enum('$type', {$tmp_val}, false);\n"; } else - throw new Exception("Unknown type '{$type}'"); + throw new Exception("Unknown type '{$type->getName()}'"); if($postfix) $str .= $cond_indent.$postfix."\n"; @@ -286,7 +286,7 @@ function value2data($name, \mtgType $type, $buf, $prefix = '', $tokens = array() $str .= $indent."\metagen_php\array_set_value({$buf}, \$assoc, '$name', \$arr_tmp__);\n"; } else - throw new Exception("Unknown type '{$type}'"); + throw new Exception("Unknown type '{$type->getName()}'"); return $str; } diff --git a/tpl/macro.twig b/tpl/macro.twig index b444d32..161daa1 100644 --- a/tpl/macro.twig +++ b/tpl/macro.twig @@ -76,13 +76,8 @@ class {{o.name}} {{o.parent ? 'extends ' ~ o.parent.name}} } catch(Exception $e) { - if($IDX > -1) - { - $FIELDS = self::CLASS_FIELDS(); - throw new Exception($e->getMessage() . " < {$FIELDS[$IDX]}"); - } - else - throw $e; + $FIELDS = self::CLASS_FIELDS(); + throw new Exception($e->getMessage() . " < {$FIELDS[$IDX]}"); } if($root && $assoc && sizeof($data) > 0) throw new Exception("Junk fields: " . implode(',', array_keys($data))); @@ -128,7 +123,9 @@ class {{o.name}} {{o.parent ? 'extends ' ~ o.parent.name}} {% endmacro %} {% macro decl_struct_field(o, f) ~%} - /** @var {{f.type}}*/ + {%- if f.type is instanceof('\\mtgMetaStruct') ~%} + /** @var {{f.type}}|null*/ + {%- endif -%} {%- if f.type is instanceof('\\mtgBuiltinType') and f.type.isstring ~%} public ${{f.name}} = ''; {%- elseif f.type is instanceof('\\mtgArrType') ~%}