/**
  * @param  FieldMappingInterface $fieldMapping
  * @return Node[]
  */
 public function getMetadataNodes(FieldMappingInterface $fieldMapping)
 {
     if (!$fieldMapping instanceof One2OneOwningSideMapping) {
         throw new \InvalidArgumentException('Field mapping has to be One2OneOwningSideMapping!');
     }
     if (null === $fieldMapping->getInversedBy()) {
         return array(new MethodCall(new Variable('builder'), 'addOwningOneToOne', array(new Arg(new String_($fieldMapping->getName())), new Arg(new String_($fieldMapping->getTargetModel())))));
     }
     return array(new MethodCall(new Variable('builder'), 'addOwningOneToOne', array(new Arg(new String_($fieldMapping->getName())), new Arg(new String_($fieldMapping->getTargetModel())), new Arg(new String_($fieldMapping->getInversedBy())))));
 }
 /**
  * @param  FieldMappingInterface $fieldMapping
  * @return Node[]
  */
 public function getMetadataNodes(FieldMappingInterface $fieldMapping)
 {
     if (!$fieldMapping instanceof Many2ManyInverseSideMapping) {
         throw new \InvalidArgumentException('Field mapping has to be Many2ManyInverseSideMapping!');
     }
     return array(new MethodCall(new Variable('builder'), 'addInverseManyToMany', array(new Arg(new String_($fieldMapping->getName())), new Arg(new String_($fieldMapping->getTargetModel())), new Arg(new String_($fieldMapping->getMappedBy())))));
 }
 /**
  * @param  FieldMappingInterface $fieldMapping
  * @return Node[]
  */
 public function getPropertyNodes(FieldMappingInterface $fieldMapping)
 {
     if (!$fieldMapping instanceof AbstractRelationMapping) {
         throw new \InvalidArgumentException('Field mapping has to be AbstractRelationMapping!');
     }
     return array(new Property(2, array(new PropertyProperty($fieldMapping->getName())), array('comments' => array(new Comment(new Documentor(array(new VarRow($this->getVarString($fieldMapping)))))))));
 }
 /**
  * @param  FieldMappingInterface $fieldMapping
  * @param  string                $relatedName
  * @param  string                $relatedRemovePrefix
  * @param  string                $relatedAddPrefix
  * @return Node
  */
 protected function getBidiretionalSetterMethodNode(FieldMappingInterface $fieldMapping, $relatedName, $relatedRemovePrefix, $relatedAddPrefix)
 {
     if (!$fieldMapping instanceof AbstractRelationMapping) {
         throw new \InvalidArgumentException('Field mapping has to be AbstractRelationMapping!');
     }
     $name = $fieldMapping->getName();
     $targetModel = $fieldMapping->getTargetModel();
     return new ClassMethod('set' . ucfirst($name), array('type' => 1, 'params' => array(new Param($name, new ConstFetch(new Name('null')), new Name($targetModel)), new Param('stopPropagation', new ConstFetch(new Name('false')))), 'stmts' => array(new If_(new BooleanNot(new Variable('stopPropagation')), array('stmts' => array(new If_(new NotIdentical(new ConstFetch(new Name('null')), new PropertyFetch(new Variable('this'), $name)), array('stmts' => array(new MethodCall(new PropertyFetch(new Variable('this'), $name), $relatedRemovePrefix . ucfirst($relatedName), array(new Arg(new Variable('this')), new Arg(new ConstFetch(new Name('true')))))))), new If_(new NotIdentical(new ConstFetch(new Name('null')), new Variable($name)), array('stmts' => array(new MethodCall(new Variable($name), $relatedAddPrefix . ucfirst($relatedName), array(new Arg(new Variable('this')), new Arg(new ConstFetch(new Name('true'))))))))))), new Assign(new PropertyFetch(new Variable('this'), $name), new Variable($name)), new Return_(new Variable('this')))), array('comments' => array(new Comment(new Documentor(array(new ParamRow($targetModel, $name), new ParamRow('bool', 'stopPropagation'), new ReturnRow('$this')))))));
 }
 /**
  * @param  FieldMappingInterface $fieldMapping
  * @return Node
  */
 protected function getBidiretionalSetterMethodNode(FieldMappingInterface $fieldMapping)
 {
     if (!$fieldMapping instanceof AbstractMany2ManyMapping) {
         throw new \InvalidArgumentException('Field mapping has to be AbstractMany2ManyMapping!');
     }
     $name = $fieldMapping->getName();
     $singularName = StringUtil::singularify($name);
     $targetModel = $fieldMapping->getTargetModel();
     return new ClassMethod('set' . ucfirst($name), array('type' => 1, 'params' => array(new Param($name)), 'stmts' => array(new Foreach_(new PropertyFetch(new Variable('this'), $name), new Variable($singularName), array('stmts' => array(new MethodCall(new Variable('this'), 'remove' . ucfirst($singularName), array(new Arg(new Variable($singularName))))))), new Foreach_(new Variable($name), new Variable($singularName), array('stmts' => array(new MethodCall(new Variable('this'), 'add' . ucfirst($singularName), array(new Arg(new Variable($singularName))))))), new Return_(new Variable('this')))), array('comments' => array(new Comment(new Documentor(array(new ParamRow($targetModel . '[]|\\Doctrine\\Common\\Collections\\Collection', $name), new ReturnRow('$this')))))));
 }
 /**
  * @param  FieldMappingInterface $fieldMapping
  * @return Node[]
  */
 public function getMetadataNodes(FieldMappingInterface $fieldMapping)
 {
     return array(new MethodCall(new MethodCall(new MethodCall(new MethodCall(new Variable('builder'), 'createField', array(new Arg(new String_($fieldMapping->getName())), new Arg(new String_('integer')))), 'isPrimaryKey'), 'generatedValue'), 'build'));
 }
 /**
  * @param  FieldMappingInterface $fieldMapping
  * @return $this
  */
 public function addField(FieldMappingInterface $fieldMapping)
 {
     $this->fieldMappings[$fieldMapping->getName()] = $fieldMapping;
     return $this;
 }
 /**
  * @param  FieldMappingInterface $fieldMapping
  * @return Node
  */
 protected function getGetterMethodNode(FieldMappingInterface $fieldMapping)
 {
     $name = $fieldMapping->getName();
     return new ClassMethod($this->getGetterPrefix() . ucfirst($name), array('type' => 1, 'stmts' => array(new Return_(new PropertyFetch(new Variable('this'), $name)))), array('comments' => array(new Comment(new Documentor(array(new ReturnRow($this->getPhpDocType($fieldMapping))))))));
 }
 /**
  * @param  FieldMappingInterface $fieldMapping
  * @return Node[]
  */
 public function getConstructNodes(FieldMappingInterface $fieldMapping)
 {
     return array(new Assign(new PropertyFetch(new Variable('this'), $fieldMapping->getName()), new New_(new Name('\\Doctrine\\Common\\Collections\\ArrayCollection'))));
 }