Skip to content

Commit

Permalink
Merge cce5380 into a5af856
Browse files Browse the repository at this point in the history
  • Loading branch information
TysonAndre committed Jun 4, 2017
2 parents a5af856 + cce5380 commit 24a3a38
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 2 deletions.
10 changes: 8 additions & 2 deletions docs/references/phpdoc/tags/method.rst
Expand Up @@ -6,13 +6,13 @@ The @method allows a class to know which 'magic' methods are callable.
Syntax
------

@method [return type] [name]([[type] [parameter]<, ...>]) [<description>]
@method [[static] return type] [name]([[type] [parameter]<, ...>]) [<description>]

Description
-----------

The @method tag is used in situation where a class contains the ``__call()``
magic method and defines some definite uses.
or ``__callStatic()`` magic method and defines some definite uses.

An example of this is a child class whose parent has a __call() to have dynamic
getters or setters for predefined properties. The child knows which getters and
Expand All @@ -26,6 +26,11 @@ return value by including those types in the signature.
When the intended method does not have a return value then the return type MAY
be omitted; in which case 'void' is implied.

If the intended method is static, the ``static`` keyword can be placed before
the return type to communicate that.
There must be a return type, ``static`` on its own would mean that the method
returns an instance of the child class which the method is called on.

@method tags MUST NOT be used in a :term:`PHPDoc` that is not associated with
a *class* or *interface*.

Expand Down Expand Up @@ -54,6 +59,7 @@ Examples
* @method string getString()
* @method void setInteger(integer $integer)
* @method setString(integer $integer)
* @method static string staticGetter()
*/
class Child extends Parent
{
Expand Down
Expand Up @@ -38,6 +38,7 @@ public function create($data)
$descriptor = new MethodDescriptor($data->getName());
$descriptor->setDescription($data->getDescription());
$descriptor->setMethodName($data->getMethodName());
$descriptor->setStatic($data->isStatic());

$response = new ReturnDescriptor('return');
$response->setTypes($this->builder->buildDescriptor(new Collection($data->getTypes())));
Expand Down
1 change: 1 addition & 0 deletions src/phpDocumentor/Descriptor/ClassDescriptor.php
Expand Up @@ -203,6 +203,7 @@ public function getMagicMethods()
$method = new MethodDescriptor();
$method->setName($methodTag->getMethodName());
$method->setDescription($methodTag->getDescription());
$method->setStatic($methodTag->isStatic());
$method->setParent($this);

$returnTags = $method->getTags()->get('return', new Collection());
Expand Down
19 changes: 19 additions & 0 deletions src/phpDocumentor/Descriptor/Tag/MethodDescriptor.php
Expand Up @@ -22,6 +22,9 @@ class MethodDescriptor extends TagDescriptor

protected $response;

/** @var bool */
protected $static;

public function __construct($name)
{
parent::__construct($name);
Expand Down Expand Up @@ -76,4 +79,20 @@ public function getResponse()
{
return $this->response;
}

/**
* @param bool $static
*/
public function setStatic($static)
{
$this->static = $static;
}

/**
* @return bool
*/
public function isStatic()
{
return $this->static;
}
}
1 change: 1 addition & 0 deletions src/phpDocumentor/Descriptor/TraitDescriptor.php
Expand Up @@ -76,6 +76,7 @@ public function getMagicMethods()
$method = new MethodDescriptor();
$method->setName($methodTag->getMethodName());
$method->setDescription($methodTag->getDescription());
$method->setStatic($methodTag->isStatic());
$method->setParent($this);

$methods->add($method);
Expand Down
1 change: 1 addition & 0 deletions tests/ReferenceImplementation.php
Expand Up @@ -73,6 +73,7 @@ class SubClass extends SuperClass
* @author Mike van Riel <mike.vanriel@naenius.com>
* @package Class
* @method string myMagicMethod(\stdClass $argument1) This is a description.
* @method static string myStaticMagicMethod(\stdClass $argument1) This is a description.
* @property string $myMagicProperty This is a description.
*/
class SuperClass implements SubInterface
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/phpDocumentor/Descriptor/ClassDescriptorTest.php
Expand Up @@ -377,6 +377,7 @@ public function testGetMagicMethods()
$methodMock->shouldReceive('getDescription')->andReturn($description);
$methodMock->shouldReceive('getResponse')->andReturn($response);
$methodMock->shouldReceive('getArguments')->andReturn($arguments);
$methodMock->shouldReceive('isStatic')->andReturn(true);

$this->fixture->getTags()->get('method', new Collection())->add($methodMock);

Expand All @@ -389,6 +390,7 @@ public function testGetMagicMethods()
$this->assertEquals($methodName, $magicMethod->getName());
$this->assertEquals($description, $magicMethod->getDescription());
$this->assertEquals($response, $magicMethod->getResponse());
$this->assertEquals(true, $magicMethod->isStatic());

$mock = m::mock('phpDocumentor\Descriptor\ClassDescriptor');
$mock->shouldReceive('getMagicMethods')->andReturn(new Collection(array('magicMethods')));
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/phpDocumentor/Descriptor/TraitDescriptorTest.php
Expand Up @@ -101,6 +101,7 @@ public function testMagicMethodsReturnsExpectedCollectionWithTags()
{
$mockMethodDescriptor = m::mock('phpDocumentor\Descriptor\Tag\MethodDescriptor');
$mockMethodDescriptor->shouldReceive('getMethodName')->andReturn('Sample');
$mockMethodDescriptor->shouldReceive('isStatic')->andReturn(false);
$mockMethodDescriptor->shouldReceive('getDescription')->andReturn('Sample description');

$methodCollection = new Collection(array($mockMethodDescriptor));
Expand All @@ -111,6 +112,7 @@ public function testMagicMethodsReturnsExpectedCollectionWithTags()
$this->assertSame(1, $magicMethodsCollection->count());
$this->assertSame('Sample', $magicMethodsCollection[0]->getName());
$this->assertSame('Sample description', $magicMethodsCollection[0]->getDescription());
$this->assertSame(false, $magicMethodsCollection[0]->isStatic());
$this->assertSame($this->fixture, $magicMethodsCollection[0]->getParent());
}

Expand Down

0 comments on commit 24a3a38

Please sign in to comment.