diff --git a/.gitignore b/.gitignore index 15e773a..a7f5e5b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ build .idea +atlassian-ide-plugin.xml vendor composer.lock phpunit.xml diff --git a/src/League/Di/Container.php b/src/League/Di/Container.php index 0b3f541..0e9e587 100644 --- a/src/League/Di/Container.php +++ b/src/League/Di/Container.php @@ -34,7 +34,7 @@ class Container /** * Constructor * - * @param object $parent Container + * @param Container $parent Container */ public function __construct(Container $parent = null) { @@ -55,11 +55,10 @@ public function createChild() /** * Method to bind a concrete class to an abstract class or interface. * - * @param string $abstract Class to bind. - * @param mixed $concrete Concrete definition to bind to $abstract. - * Can be a \Closure or a string. + * @param string $abstract Class to bind. + * @param \Closure|string $concrete Concrete definition to bind to $abstract. * - * @return mixed The concrete class for adding method calls / constructor arguments if desired. + * @return Definition|\Closure The concrete class for adding method calls / constructor arguments if desired. */ public function bind($abstract, $concrete = null) { @@ -82,6 +81,7 @@ public function bind($abstract, $concrete = null) * parent Container's until it finds the $binding. * * @param string $binding The binding to check. + * @return bool */ public function bound($binding) { @@ -94,6 +94,7 @@ public function bound($binding) * @param string $concrete The name of the class to buld. * * @return mixed The instantiated class. + * @throws \InvalidArgumentException */ public function build($concrete) { @@ -118,9 +119,10 @@ public function build($concrete) * Extend an existing binding. * * @param string $binding The name of the binding to extend. - * @param Closure $closure The function to use to extend the existing binding. + * @param \Closure $closure The function to use to extend the existing binding. * * @return void + * @throws \InvalidArgumentException */ public function extend($binding, \Closure $closure) { @@ -141,6 +143,7 @@ public function extend($binding, \Closure $closure) * @param \ReflectionMethod $method The method for which to obtain dependencies. * * @return array An array containing the method dependencies. + * @throws \InvalidArgumentException */ protected function getDependencies(\ReflectionMethod $method) { @@ -170,7 +173,7 @@ protected function getDependencies(\ReflectionMethod $method) * * @param string $binding The $binding key to get the raw value from. * - * @return mixed Value of the $binding. + * @return Definition|\Closure Value of the $binding. */ public function getRaw($binding) { diff --git a/src/League/Di/Definition.php b/src/League/Di/Definition.php index 710fd48..1532137 100644 --- a/src/League/Di/Definition.php +++ b/src/League/Di/Definition.php @@ -122,6 +122,18 @@ public function addArgs(array $args) return $this; } + /** + * Remove all available arguments + * + * @return Definition + */ + public function cleanArgs() + { + $this->arguments = array(); + + return $this; + } + /** * Adds a method call to be executed after instantiating. * @@ -142,7 +154,7 @@ public function withMethod($method, array $args = array()) * * @param object $object The instatiated $class on which to call the methods. * - * @return The created object + * @return mixed The created object */ protected function callMethods($object) { diff --git a/test/League/Di/Test/DefinitionTest.php b/test/League/Di/Test/DefinitionTest.php index ce12b78..468f497 100644 --- a/test/League/Di/Test/DefinitionTest.php +++ b/test/League/Di/Test/DefinitionTest.php @@ -224,6 +224,27 @@ public function testAddArgs() ); } + /** + * Tests removing arguments from a Defintion. + * + * @return void + */ + public function testCleanArgs() + { + $definition = new Definition($this->container, 'League\\Di\\Stub\\Foo'); + + $definition->addArgs(array('foo', 'bar')); + + $definition->cleanArgs(); + + $this->assertAttributeEquals( + array(), + 'arguments', + $definition, + 'All arguments should be removed from the arguments array.' + ); + } + public function testWithMethod() { $definition = new Definition($this->container, 'League\\Di\\Stub\\Qux');