示例#1
0
 public function testParamProducesCorrectDocBlockLine()
 {
     $this->tag->setVariableName('foo');
     $this->tag->setTypes('string|null');
     $this->tag->setDescription('description');
     $this->assertEquals('@param string|null $foo description', $this->tag->generate());
 }
示例#2
0
 private function handleValueMethod(Generator\ClassGenerator $generator, PHPProperty $prop, PHPClass $class, $all = true)
 {
     $type = $prop->getType();
     $docblock = new DocBlockGenerator('Construct');
     $paramTag = new ParamTag("value", "mixed");
     $paramTag->setTypes($type ? $this->getPhpType($type) : "mixed");
     $docblock->setTag($paramTag);
     $param = new ParameterGenerator("value");
     if ($type && !$this->isNativeType($type)) {
         $param->setType($this->getPhpType($type));
     }
     $method = new MethodGenerator("__construct", [$param]);
     $method->setDocBlock($docblock);
     $method->setBody("\$this->value(\$value);");
     $generator->addMethodFromGenerator($method);
     $docblock = new DocBlockGenerator('Gets or sets the inner value');
     $paramTag = new ParamTag("value", "mixed");
     if ($type && $type instanceof PHPClassOf) {
         $paramTag->setTypes($this->getPhpType($type->getArg()->getType()) . "[]");
     } elseif ($type) {
         $paramTag->setTypes($this->getPhpType($prop->getType()));
     }
     $docblock->setTag($paramTag);
     $returnTag = new ReturnTag("mixed");
     if ($type && $type instanceof PHPClassOf) {
         $returnTag->setTypes($this->getPhpType($type->getArg()->getType()) . "[]");
     } elseif ($type) {
         $returnTag->setTypes($this->getPhpType($type));
     }
     $docblock->setTag($returnTag);
     $param = new ParameterGenerator("value");
     $param->setDefaultValue(null);
     if ($type && !$this->isNativeType($type)) {
         $param->setType($this->getPhpType($type));
     }
     $method = new MethodGenerator("value", []);
     $method->setDocBlock($docblock);
     $methodBody = "if (\$args = func_get_args()) {" . PHP_EOL;
     $methodBody .= "    \$this->" . $prop->getName() . " = \$args[0];" . PHP_EOL;
     $methodBody .= "}" . PHP_EOL;
     $methodBody .= "return \$this->" . $prop->getName() . ";" . PHP_EOL;
     $method->setBody($methodBody);
     $generator->addMethodFromGenerator($method);
     $docblock = new DocBlockGenerator('Gets a string value');
     $docblock->setTag(new ReturnTag("string"));
     $method = new MethodGenerator("__toString");
     $method->setDocBlock($docblock);
     $method->setBody("return strval(\$this->" . $prop->getName() . ");");
     $generator->addMethodFromGenerator($method);
 }