diff options
author | Laria Carolin Chabowski <laria@laria.me> | 2020-05-01 17:33:13 +0200 |
---|---|---|
committer | Laria Carolin Chabowski <laria@laria.me> | 2020-05-01 17:33:13 +0200 |
commit | 7449faaa76a5b4008fd51a6562cca2e0a852ea6b (patch) | |
tree | 9e6bc34afe9e4e7d49b1a26f0b67485869b0a9de /src/ste/Scope.php | |
parent | b0c9a4aeb61aff8a8fa60746cd566e6dbe05a3b5 (diff) | |
download | ste-7449faaa76a5b4008fd51a6562cca2e0a852ea6b.tar.gz ste-7449faaa76a5b4008fd51a6562cca2e0a852ea6b.tar.bz2 ste-7449faaa76a5b4008fd51a6562cca2e0a852ea6b.zip |
Clean up code and improve documentation
This switches the code documentation genarator (we're now using phpdoc
instead of NaturalDoc).
Also various small code cleanup tasks:
- Remove unused code
- Get rid of `and` / `or`, we're using `&&` / `||` now
- Adding missing return values
- Helping PhpStorm to detect some dynamically called functions
(mark_builtin_callable in Transcompiler)
- Reword transcompiling => compiling in documentation
Diffstat (limited to 'src/ste/Scope.php')
-rw-r--r-- | src/ste/Scope.php | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/ste/Scope.php b/src/ste/Scope.php index e312876..afb2bfc 100644 --- a/src/ste/Scope.php +++ b/src/ste/Scope.php @@ -4,9 +4,17 @@ namespace kch42\ste; class Scope implements \ArrayAccess { + /** @var self|null */ private $parent = null; + + /** @var array */ public $vars = array(); + /** + * @param string $name + * @return string[] + * @throws RuntimeError + */ private static function parse_name($name) { $remain = $name; @@ -44,6 +52,12 @@ class Scope implements \ArrayAccess return $fields; } + /** + * @param string $name + * @param bool $localonly + * @return mixed A reference to the resolved variable + * @throws VarNotInScope + */ private function &get_topvar_reference($name, $localonly) { if (array_key_exists($name, $this->vars)) { @@ -59,6 +73,13 @@ class Scope implements \ArrayAccess throw new VarNotInScope(); } + /** + * @param string $name + * @param bool $create_if_not_exist + * @param bool $localonly + * @return mixed A reference to the resolved variable + * @throws RuntimeError + */ public function &get_var_reference($name, $create_if_not_exist, $localonly=false) { $nullref = null; @@ -107,24 +128,42 @@ class Scope implements \ArrayAccess return $ref; } + /** + * @param string $name + * @param mixed $val + * @throws RuntimeError + */ public function set_var_by_name($name, $val) { $ref = &$this->get_var_reference($name, true); $ref = $val; } + /** + * @param string $name + * @param mixed $val + * @throws RuntimeError + */ public function set_local_var($name, $val) { $ref = &$this->get_var_reference($name, true, true); $ref = $val; } + /** + * @param string $name + * @return mixed Returns an empty string, if not found or unset + * @throws RuntimeError + */ public function get_var_by_name($name) { $ref = $this->get_var_reference($name, false); return $ref === null ? "" : $ref; } + /** + * @return self + */ public function new_subscope() { $o = new self(); |