Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
Add method visibility & fix CS
Browse files Browse the repository at this point in the history
  • Loading branch information
blanchonvincent committed Oct 14, 2013
1 parent cf1299b commit cb06934
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
13 changes: 7 additions & 6 deletions library/Zend/Code/Reflection/MethodReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,12 @@ public function getPrototype($format = MethodReflection::PROTOTYPE_AS_ARRAY)

$declaringClass = $this->getDeclaringClass();
$prototype = array(
'namespace' => $declaringClass->getNamespaceName(),
'class' => substr($declaringClass->getName(), strlen($declaringClass->getNamespaceName()) + 1),
'name' => $this->getName(),
'return' => $returnType,
'arguments' => array(),
'namespace' => $declaringClass->getNamespaceName(),
'class' => substr($declaringClass->getName(), strlen($declaringClass->getNamespaceName()) + 1),
'name' => $this->getName(),
'visibility' => ($this->isPublic() ? 'public' : ($this->isPrivate() ? 'private' : 'protected')),
'return' => $returnType,
'arguments' => array(),
);

$parameters = $this->getParameters();
Expand All @@ -134,7 +135,7 @@ public function getPrototype($format = MethodReflection::PROTOTYPE_AS_ARRAY)
}

if ($format == MethodReflection::PROTOTYPE_AS_STRING) {
$line = $prototype['return'] . ' ' . $prototype['name'] . '(';
$line = $prototype['visibility'] . ' ' . $prototype['return'] . ' ' . $prototype['name'] . '(';
$args = array();
foreach ($prototype['arguments'] as $name => $argument) {
$argsLine = ($argument['type'] ? $argument['type'] . ' ' : '') . ($argument['by_ref'] ? '&' : '') . '$' . $name;
Expand Down
9 changes: 6 additions & 3 deletions tests/ZendTest/Code/Reflection/MethodReflectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function testGetPrototypeMethod()
'namespace' => 'ZendTest\Code\Reflection\TestAsset',
'class' => 'TestSampleClass10',
'name' => 'doSomethingElse',
'visibility' => 'public',
'return' => 'int',
'arguments' => array(
'one' => array(
Expand All @@ -89,13 +90,14 @@ public function testGetPrototypeMethod()
),
);
$this->assertEquals($prototype, $reflectionMethod->getPrototype());
$this->assertEquals('int doSomethingElse(int $one, int $two = 2, string $three = \'three\')', $reflectionMethod->getPrototype(MethodReflection::PROTOTYPE_AS_STRING));
$this->assertEquals('public int doSomethingElse(int $one, int $two = 2, string $three = \'three\')', $reflectionMethod->getPrototype(MethodReflection::PROTOTYPE_AS_STRING));

$reflectionMethod = new MethodReflection('ZendTest\Code\Reflection\TestAsset\TestSampleClass2', 'getProp2');
$prototype = array(
'namespace' => 'ZendTest\Code\Reflection\TestAsset',
'class' => 'TestSampleClass2',
'name' => 'getProp2',
'visibility' => 'public',
'return' => 'mixed',
'arguments' => array(
'param1' => array(
Expand All @@ -113,13 +115,14 @@ public function testGetPrototypeMethod()
),
);
$this->assertEquals($prototype, $reflectionMethod->getPrototype());
$this->assertEquals('mixed getProp2($param1, ZendTest\Code\Reflection\TestAsset\TestSampleClass $param2)', $reflectionMethod->getPrototype(MethodReflection::PROTOTYPE_AS_STRING));
$this->assertEquals('public mixed getProp2($param1, ZendTest\Code\Reflection\TestAsset\TestSampleClass $param2)', $reflectionMethod->getPrototype(MethodReflection::PROTOTYPE_AS_STRING));

$reflectionMethod = new MethodReflection('ZendTest\Code\Reflection\TestAsset\TestSampleClass12', 'doSomething');
$prototype = array(
'namespace' => 'ZendTest\Code\Reflection\TestAsset',
'class' => 'TestSampleClass12',
'name' => 'doSomething',
'visibility' => 'protected',
'return' => 'string',
'arguments' => array(
'one' => array(
Expand All @@ -137,6 +140,6 @@ public function testGetPrototypeMethod()
),
);
$this->assertEquals($prototype, $reflectionMethod->getPrototype());
$this->assertEquals('string doSomething(int &$one, int $two)', $reflectionMethod->getPrototype(MethodReflection::PROTOTYPE_AS_STRING));
$this->assertEquals('protected string doSomething(int &$one, int $two)', $reflectionMethod->getPrototype(MethodReflection::PROTOTYPE_AS_STRING));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
class TestSampleClass12
{
/**
*
* @param int $one
* @param int $two
*
* @param int $one
* @param int $two
* @return string
*/
public function doSomething(&$one, $two)
protected function doSomething(&$one, $two)
{
return 'mixedValue';
}
Expand Down

0 comments on commit cb06934

Please sign in to comment.