WsdlToPhp\PackageGenerator\Model\Struct::addAttribute PHP Method

addAttribute() public method

Adds attribute based on its original name
public addAttribute ( string $attributeName, string $attributeType ) : Struct
$attributeName string the attribute name
$attributeType string the attribute type
return Struct
    public function addAttribute($attributeName, $attributeType)
    {
        if (empty($attributeName) || empty($attributeType)) {
            throw new \InvalidArgumentException(sprintf('Attribute name "%s" and/or attribute type "%s" is invalid for Struct "%s"', $attributeName, $attributeType, $this->getName()), __LINE__);
        }
        if ($this->attributes->getStructAttributeByName($attributeName) === null) {
            $structAttribute = new StructAttribute($this->getGenerator(), $attributeName, $attributeType, $this);
            $this->attributes->add($structAttribute);
        }
        return $this;
    }

Usage Example

 /**
  * @expectedException \InvalidArgumentException
  */
 public function testSetModelBasNameOneAttributeWithException()
 {
     $struct = new StructModel(self::bingGeneratorInstance(), 'Foo');
     $struct->addAttribute('bar', 'string');
     $array = new ArrayFile(self::bingGeneratorInstance(), 'Foo');
     $array->setModel($struct);
 }