From 023f3f8c6948f468f01620eb2dd00cd8dfbcedae Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Wed, 22 Feb 2017 15:41:30 -0500 Subject: [PATCH] Start work toward 2.0 --- build/header_comment.txt | 4 ++-- composer.json | 6 ++++-- src/Enum.php | 16 ++++++++++++---- src/StaticInstance.php | 13 ++++++------- src/functions.php | 29 +++++++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 15 deletions(-) create mode 100644 src/functions.php diff --git a/build/header_comment.txt b/build/header_comment.txt index 485e85a..797fdae 100644 --- a/build/header_comment.txt +++ b/build/header_comment.txt @@ -7,9 +7,9 @@ * * @package Ion * @author Timothy J. Warren - * @copyright 2015 - 2016 Timothy J. Warren + * @copyright 2015 - 2017 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License - * @version 1.0.0 + * @version 2.0.0 * @link https://git.timshomepage.net/timw4mail/ion */ diff --git a/composer.json b/composer.json index e9cac54..b3d18d4 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,9 @@ "henrikbjorn/lurker": "^1.1.0", "nikic/php-parser": "3.0.*@beta", "monolog/monolog": "1.*", - "squizlabs/php_codesniffer": "^3.0.0@RC" + "squizlabs/php_codesniffer": "^3.0.0@RC", + "vimeo/psalm": "^0.3.24", + "phpstan/phpstan": "^0.6.4" }, "scripts": { "coverage": "vendor/bin/phpunit -c build", @@ -47,4 +49,4 @@ "suggest": { "monolog/monolog": "Provides implementation of psr/log" } -} \ No newline at end of file +} diff --git a/src/Enum.php b/src/Enum.php index e122010..4f3029b 100644 --- a/src/Enum.php +++ b/src/Enum.php @@ -33,9 +33,17 @@ abstract class Enum { * * @return array */ - protected function getConstList(): array + protected static function getConstList(): array { - $reflect = new ReflectionClass($this); + static $self; + + if (is_null($self)) + { + $class = \get_called_class(); + $self = new $class; + } + + $reflect = new ReflectionClass($self); return $reflect->getConstants(); } @@ -44,9 +52,9 @@ abstract class Enum { * @param mixed $key * @return boolean */ - protected function isValid($key): bool + protected static function isValid($key): bool { - $values = array_values($this->getConstList()); + $values = array_values(static::getConstList()); return in_array($key, $values); } } diff --git a/src/StaticInstance.php b/src/StaticInstance.php index b5664ce..09233a1 100644 --- a/src/StaticInstance.php +++ b/src/StaticInstance.php @@ -39,10 +39,15 @@ trait StaticInstance { */ public function __call(string $method, array $args) { + $class = \get_called_class(); if (method_exists($this, $method)) { return call_user_func_array([$this, $method], $args); } + else if(method_exists($class, $method)) + { + return static::__callStatic($method, $args); + } } /** @@ -55,13 +60,7 @@ trait StaticInstance { */ public static function __callStatic(string $method, array $args) { - $class = get_called_class(); - if ( ! array_key_exists($class, self::$instance)) - { - self::$instance[$class] = new $class(); - } - - return call_user_func_array([self::$instance[$class], $method], $args); + return call_user_func_array([\get_called_class(), $method], $args); } } // End of StaticInstance.php \ No newline at end of file diff --git a/src/functions.php b/src/functions.php new file mode 100644 index 0000000..d71da70 --- /dev/null +++ b/src/functions.php @@ -0,0 +1,29 @@ + + * @copyright 2015 - 2016 Timothy J. Warren + * @license http://www.opensource.org/licenses/mit-license.html MIT License + * @version 1.0.0 + * @link https://git.timshomepage.net/timw4mail/ion + */ + +namespace Aviat\Ion; + +/** + * Joins paths together. Variadic to take an + * arbitrary number of arguments + * + * @param string[] ...$args + * @return string + */ +function _dir(...$args) +{ + return implode(DIRECTORY_SEPARATOR, $args); +} \ No newline at end of file