phpDocumentor\Descriptor\TraitDescriptor::getMagicProperties PHP Method

getMagicProperties() public method

public getMagicProperties ( ) : phpDocumentor\Descriptor\Collection
return phpDocumentor\Descriptor\Collection
    public function getMagicProperties()
    {
        /** @var Collection $propertyTags */
        $propertyTags = clone $this->getTags()->get('property', new Collection());
        $propertyTags->merge($this->getTags()->get('property-read', new Collection()));
        $propertyTags->merge($this->getTags()->get('property-write', new Collection()));
        $properties = new Collection();
        /** @var Tag\PropertyDescriptor $propertyTag */
        foreach ($propertyTags as $propertyTag) {
            $property = new PropertyDescriptor();
            $property->setName(ltrim($propertyTag->getVariableName(), '$'));
            $property->setDescription($propertyTag->getDescription());
            $property->setTypes($propertyTag->getTypes());
            $property->setParent($this);
            $properties->add($property);
        }
        return $properties;
    }

Usage Example

 /**
  * @covers phpDocumentor\Descriptor\TraitDescriptor::getMagicProperties
  */
 public function testMagicPropertiesReturnsExpectedCollectionWithTags()
 {
     $mockTagPropertyDescriptor = m::mock('phpDocumentor\\Descriptor\\Tag\\PropertyDescriptor');
     $mockTagPropertyDescriptor->shouldReceive('getVariableName')->andReturn('Sample');
     $mockTagPropertyDescriptor->shouldReceive('getDescription')->andReturn('Sample description');
     $mockTagPropertyDescriptor->shouldReceive('getTypes')->andReturn(new Collection());
     $propertyCollection = new Collection(array($mockTagPropertyDescriptor));
     $this->fixture->getTags()->set('property', $propertyCollection);
     $this->assertInstanceOf('phpDocumentor\\Descriptor\\Collection', $this->fixture->getMagicProperties());
     $magicPropertiesCollection = $this->fixture->getMagicProperties();
     $this->assertSame(1, $magicPropertiesCollection->count());
     $this->assertSame('Sample', $magicPropertiesCollection[0]->getName());
     $this->assertSame('Sample description', $magicPropertiesCollection[0]->getDescription());
     $this->assertInstanceOf('phpDocumentor\\Descriptor\\Collection', $magicPropertiesCollection[0]->getTypes());
     $this->assertSame(0, $magicPropertiesCollection[0]->getTypes()->count());
     $this->assertSame($this->fixture, $magicPropertiesCollection[0]->getParent());
 }