Ejemplo n.º 1
0
 /**
  * @param PhpMethodElement $method
  * @return PhpInterface
  */
 public function addMethodElement(PhpMethodElement $method)
 {
     if ($method->getHasBody()) {
         $method->setHasBody(false);
     }
     return parent::addMethodElement($method);
 }
Ejemplo n.º 2
0
 /**
  * @return PhpMethod
  */
 protected function getEnumMethodGetValidValues()
 {
     $method = new PhpMethod(self::METHOD_GET_VALID_VALUES, array(), PhpMethod::ACCESS_PUBLIC, false, true);
     $validValues = $this->getEnumMethodValues();
     $method->addChild('return array(');
     foreach ($validValues as $validValue) {
         $method->addChild(sprintf('%s,', $method->getIndentedString($validValue, 1)));
     }
     $method->addChild(');');
     return $method;
 }
Ejemplo n.º 3
0
 public function testPublicWithBodyToString()
 {
     $method = new PhpMethod('foo', array('bar', array('name' => 'demo', 'value' => 1), array('name' => 'sample', 'value' => null), new PhpFunctionParameter('deamon', true)));
     $method->addChild(new PhpVariable('bar', 1))->addChild('return $bar;');
     $this->assertSame("public function foo(\$bar, \$demo = 1, \$sample = null, \$deamon = true)\n{\n    \$bar = 1;\n    return \$bar;\n}", $method->toString());
 }
Ejemplo n.º 4
0
 /**
  * @param PhpMethod $phpMethod
  * @param MethodModel $methodModel
  * @return Service
  */
 protected function setModelFromMethod(PhpMethod $phpMethod, MethodModel $methodModel)
 {
     $this->methods[$phpMethod->getName()] = $methodModel;
     return $this;
 }
Ejemplo n.º 5
0
 public function testSimpleClassPublicMethodToString()
 {
     $class = new PhpClass('Foo');
     $method = new PhpMethod('bar', array('bar', 'foo', 'sample'), PhpMethod::ACCESS_PRIVATE);
     $method->addChild(new PhpVariable('foo', 1));
     $class->addChild($method);
     $this->assertSame("class Foo\n{\n    private function bar(\$bar, \$foo, \$sample)\n    {\n        \$foo = 1;\n    }\n}", $class->toString());
 }
Ejemplo n.º 6
0
 /**
  * @param PhpMethod $method
  * @return PhpAnnotationBlock|null
  */
 protected function getStructMethodAnnotationBlock(PhpMethod $method)
 {
     switch ($method->getName()) {
         case self::METHOD_CONSTRUCT:
             $annotationBlock = $this->getStructMethodConstructAnnotationBlock();
             break;
         case self::METHOD_SET_STATE:
             $annotationBlock = $this->getStructMethodSetStateAnnotationBlock();
             break;
         case self::METHOD_GET_ATTRIBUTE_NAME:
             $annotationBlock = $this->getArrayMethodGetAttributeNameAnnotationBlock();
             break;
         case self::METHOD_CURRENT:
             $annotationBlock = $this->getArrayMethodCurrentAnnotationBlock();
             break;
         case self::METHOD_FIRST:
             $annotationBlock = $this->getArrayMethodFirstAnnotationBlock();
             break;
         case self::METHOD_ITEM:
             $annotationBlock = $this->getArrayMethodItemAnnotationBlock();
             break;
         case self::METHOD_LAST:
             $annotationBlock = $this->getArrayMethodLastAnnotationBlock();
             break;
         case self::METHOD_OFFSET_GET:
             $annotationBlock = $this->getArrayMethodOffsetGetAnnotationBlock();
             break;
         case self::METHOD_ADD:
             $annotationBlock = $this->getArrayMethodAddAnnotationBlock();
             break;
         default:
             $annotationBlock = parent::getStructMethodAnnotationBlock($method);
             break;
     }
     return $annotationBlock;
 }
Ejemplo n.º 7
0
 /**
  * @return PhpMethod
  */
 protected function getToStringMethod()
 {
     $method = new PhpMethod('__toString');
     $method->addChild('return __CLASS__;');
     return $method;
 }
Ejemplo n.º 8
0
 /**
  * @param PhpMethod $method
  * @param StructModel $struct
  * @return ClassMap
  */
 protected function addStructToClassMapList(PhpMethod $method, StructModel $struct)
 {
     if ($struct->getIsStruct() && !$struct->getIsRestriction()) {
         $method->addChild($method->getIndentedString(sprintf('\'%s\' => \'%s\',', $struct->getName(), $this->getStructName($struct)), 1));
     }
     return $this;
 }
Ejemplo n.º 9
0
 /**
  * @param PhpMethod $method
  * @return PhpAnnotationBlock
  */
 protected function getStructMethodsAddToAnnotationBlock(PhpMethod $method)
 {
     $attributeName = str_replace('addTo', '', $method->getName());
     $attribute = $this->getModel()->getAttribute($attributeName);
     if (!$attribute instanceof StructAttributeModel) {
         $attribute = $this->getModel()->getAttribute(lcfirst($attributeName));
     }
     $model = $this->getRestrictionFromStructAttribute($attribute);
     $annotationBlock = new PhpAnnotationBlock();
     if ($attribute instanceof StructAttributeModel) {
         $annotationBlock->addChild(sprintf('Add item to %s value', $attribute->getCleanName()));
         if ($model instanceof StructModel) {
             $annotationBlock->addChild(new PhpAnnotation(self::ANNOTATION_USES, sprintf('%s::%s()', $model->getPackagedName(true), StructEnum::METHOD_VALUE_IS_VALID)))->addChild(new PhpAnnotation(self::ANNOTATION_USES, sprintf('%s::%s()', $model->getPackagedName(true), StructEnum::METHOD_GET_VALID_VALUES)));
         }
         $annotationBlock->addChild(new PhpAnnotation(self::ANNOTATION_THROWS, '\\InvalidArgumentException'))->addChild(new PhpAnnotation(self::ANNOTATION_PARAM, sprintf('%s $item', $this->getStructAttributeTypeSetAnnotation($attribute, false))))->addChild(new PhpAnnotation(self::ANNOTATION_RETURN, $this->getModel()->getPackagedName(true)));
     }
     return $annotationBlock;
 }
Ejemplo n.º 10
0
 /**
  * @param PhpFunctionParameter $parameter
  * @param PhpMethod $method
  * @return string
  */
 protected function getOperationCallParameterName(PhpFunctionParameter $parameter, PhpMethod $method)
 {
     $cloneParameter = clone $parameter;
     $cloneParameter->setType(null);
     if ($this->getMethod()->nameIsClean() === false) {
         return sprintf('%s%s', PhpMethod::BREAK_LINE_CHAR, $method->getIndentedString(sprintf('%s,', $cloneParameter->getPhpDeclaration()), 1));
     } else {
         return $cloneParameter->getPhpDeclaration();
     }
 }