/** * Removes tags by name. * * @param string|array|Argument $argumentName * * @return \ClassGeneration\ArgumentCollection */ public function removeByName($argumentName) { $removedList = new self(); $list = $this->getIterator(); foreach ($list as $index => $argument) { if ($argumentName instanceof Argument && $argumentName->getName() != $argument->getName() || is_string($argumentName) && $argument->getName() !== $argumentName) { continue; } $removedList->add(clone $argument); $this->remove($index); } return $removedList; }
public function testRemoveByName() { $arg1 = new Argument(); $arg1->setName('arg1'); $arg2 = clone $arg1; $arg2->setName('arg2'); $arg3 = clone $arg1; $arg3->setName('arg3'); $arg4 = clone $arg1; $arg4->setName('arg4'); $collection = new ArgumentCollection(array($arg1, $arg2, $arg3, $arg4)); $this->assertCount(4, $collection); $removed = $collection->removeByName('arg2'); $this->assertCount(1, $removed); $this->assertCount(3, $collection); $removed = $collection->removeByName($arg1); $this->assertCount(1, $removed); $this->assertCount(2, $collection); $removed = $collection->removeByName('test'); $this->assertCount(0, $removed); $this->assertCount(2, $collection); }
public function testParseArgumentWithTypeAndOptionalToString() { $argument = new Argument(); $argument->setType('\\ClassGeneration')->setIsOptional()->setName('arg'); $this->assertEquals('\\ClassGeneration $arg = NULL', $argument->toString()); }
/** * Creates a method from Reflection Method. * * @param \ReflectionMethod $reflected * * @return Method */ public static function createFromReflection(\ReflectionMethod $reflected) { $method = new self(); $method->setName($reflected->getName()); foreach ($reflected->getParameters() as $parameterReflected) { $argument = new Argument(); $argument->setName($parameterReflected->getName()); $method->addArgument($argument); } return $method; }