diff --git a/.travis.yml b/.travis.yml index def45f3..aea005e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 7.0 - 7.1 - 7.2 - 7.3 @@ -21,6 +20,7 @@ install: script: - vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover + - vendor/bin/phpstan analyse src after_success: - wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e60a261..0c45c52 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -23,7 +23,7 @@ We accept contributions via Pull Requests on [Github](https://github.com/thephpl ## Running Tests ``` bash -$ phpunit +$ composer test ``` **Happy coding**! diff --git a/README.md b/README.md index 9274c65..0e0edd9 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,9 @@ $ composer require league/container The following versions of PHP are supported by this version. -* PHP 7.0 * PHP 7.1 * PHP 7.2 +* PHP 7.3 ## Documentation @@ -40,7 +40,7 @@ Contribute to this documentation in the [gh-pages branch](https://github.com/the ## Testing ``` bash -$ vendor/bin/phpunit +$ composer test ``` ## Contributing diff --git a/composer.json b/composer.json index 224c00c..baf6ede 100644 --- a/composer.json +++ b/composer.json @@ -21,12 +21,13 @@ } ], "require": { - "php": "^7.0", + "php": "^7.1", "psr/container": "^1.0" }, "require-dev": { "phpunit/phpunit" : "^6.0", - "squizlabs/php_codesniffer": "^3.3" + "squizlabs/php_codesniffer": "^3.3", + "phpstan/phpstan": "^0.11.8" }, "provide": { "psr/container-implementation": "^1.0" @@ -50,5 +51,11 @@ "dev-2.x": "2.x-dev", "dev-1.x": "1.x-dev" } + }, + "scripts": { + "test": [ + "phpunit", + "phpstan analyse src/" + ] } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..6b347c0 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,2 @@ +includes: + - vendor/phpstan/phpstan/conf/config.level7.neon diff --git a/src/Definition/Definition.php b/src/Definition/Definition.php index 567713d..9426960 100644 --- a/src/Definition/Definition.php +++ b/src/Definition/Definition.php @@ -259,7 +259,10 @@ protected function invokeMethods($instance) { foreach ($this->methods as $method) { $args = $this->resolveArguments($method['arguments']); - call_user_func_array([$instance, $method['method']], $args); + + /** @var callable $callable */ + $callable = [$instance, $method['method']]; + call_user_func_array($callable, $args); } return $instance; diff --git a/src/Inflector/Inflector.php b/src/Inflector/Inflector.php index 71eb69c..2a9e8be 100644 --- a/src/Inflector/Inflector.php +++ b/src/Inflector/Inflector.php @@ -2,9 +2,9 @@ namespace League\Container\Inflector; -use League\Container\ContainerAwareTrait; use League\Container\Argument\ArgumentResolverInterface; use League\Container\Argument\ArgumentResolverTrait; +use League\Container\ContainerAwareTrait; class Inflector implements ArgumentResolverInterface, InflectorInterface { @@ -17,7 +17,7 @@ class Inflector implements ArgumentResolverInterface, InflectorInterface protected $type; /** - * @var callable + * @var callable|null */ protected $callback; @@ -103,17 +103,20 @@ public function inflect($object) $properties = $this->resolveArguments(array_values($this->properties)); $properties = array_combine(array_keys($this->properties), $properties); - foreach ($properties as $property => $value) { + // array_combine() can technically return false + foreach ($properties ?: [] as $property => $value) { $object->{$property} = $value; } foreach ($this->methods as $method => $args) { $args = $this->resolveArguments($args); - call_user_func_array([$object, $method], $args); + /** @var callable $callable */ + $callable = [$object, $method]; + call_user_func_array($callable, $args); } - if (! is_null($this->callback)) { + if ($this->callback !== null) { call_user_func_array($this->callback, [$object]); } } diff --git a/src/Inflector/InflectorAggregate.php b/src/Inflector/InflectorAggregate.php index 04c9394..a15b806 100644 --- a/src/Inflector/InflectorAggregate.php +++ b/src/Inflector/InflectorAggregate.php @@ -10,7 +10,7 @@ class InflectorAggregate implements InflectorAggregateInterface use ContainerAwareTrait; /** - * @var \League\Container\Inflector[] + * @var \League\Container\Inflector\Inflector[] */ protected $inflectors = []; diff --git a/src/ReflectionContainer.php b/src/ReflectionContainer.php index 33178b7..8984b89 100644 --- a/src/ReflectionContainer.php +++ b/src/ReflectionContainer.php @@ -98,7 +98,7 @@ public function call(callable $callable, array $args = []) return $reflection->invokeArgs($callable, $this->reflectArguments($reflection, $args)); } - $reflection = new ReflectionFunction($callable); + $reflection = new ReflectionFunction(\Closure::fromCallable($callable)); return $reflection->invokeArgs($this->reflectArguments($reflection, $args)); }