Merge pull request #713 from pahan35/fix-missed-methods-with-same-name

Fix missed methods with same name
This commit is contained in:
Barry vd. Heuvel
2018-10-06 11:33:25 +02:00
committed by GitHub
4 changed files with 56 additions and 32 deletions
+2 -2
View File
@@ -28,7 +28,7 @@ namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
//Method inherited from <?= $method->getDeclaringClass() ?> //Method inherited from <?= $method->getDeclaringClass() ?>
<?php endif; ?> <?php endif; ?>
<?= $method->shouldReturn() ? 'return ': '' ?><?= $method->getRoot() ?>::<?= $method->getName() ?>(<?= $method->getParams() ?>); <?= $method->shouldReturn() ? 'return ': '' ?><?= $method->getRoot() ?>::<?= $method->getRealName() ?>(<?= $method->getParams() ?>);
} }
<?php endforeach; ?> <?php endforeach; ?>
} }
@@ -50,7 +50,7 @@ namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
//Method inherited from <?= $method->getDeclaringClass() ?> //Method inherited from <?= $method->getDeclaringClass() ?>
<?php endif; ?> <?php endif; ?>
<?= $method->shouldReturn() ? 'return ': '' ?><?= $method->getRoot() ?>::<?= $method->getName() ?>(<?= $method->getParams() ?>); <?= $method->shouldReturn() ? 'return ': '' ?><?= $method->getRoot() ?>::<?= $method->getRealName() ?>(<?= $method->getParams() ?>);
} }
<?php endforeach; ?> <?php endforeach; ?>
<?php endif; ?>} <?php endif; ?>}
+1 -1
View File
@@ -310,7 +310,7 @@ class Alias
$method = new \ReflectionMethod($className, $name); $method = new \ReflectionMethod($className, $name);
$class = new \ReflectionClass($className); $class = new \ReflectionClass($className);
if (!in_array($method->name, $this->usedMethods)) { if (!in_array($magic, $this->usedMethods)) {
if ($class !== $this->root) { if ($class !== $this->root) {
$this->methods[] = new Method($method, $this->alias, $class, $magic, $this->interfaces); $this->methods[] = new Method($method, $this->alias, $class, $magic, $this->interfaces);
} }
+15 -21
View File
@@ -17,36 +17,30 @@ class Macro extends Method
* @param array $interfaces * @param array $interfaces
*/ */
public function __construct( public function __construct(
\ReflectionFunctionAbstract $method, $method,
$alias, $alias,
$class, $class,
$methodName = null, $methodName = null,
$interfaces = array() $interfaces = array()
) { ) {
$this->method = $method; parent::__construct($method, $alias, $class, $methodName, $interfaces);
$this->interfaces = $interfaces; }
$this->name = $methodName ?: $method->name;
$this->namespace = $class->getNamespaceName();
//Create a DocBlock and serializer instance /**
* @param \ReflectionFunctionAbstract $method
*/
protected function initPhpDoc($method)
{
$this->phpdoc = new DocBlock($method); $this->phpdoc = new DocBlock($method);
//Normalize the description and inherit the docs from parents/interfaces
try {
$this->normalizeParams($this->phpdoc);
$this->normalizeReturn($this->phpdoc);
$this->normalizeDescription($this->phpdoc);
} catch (\Exception $e) {
} }
//Get the parameters, including formatted default values /**
$this->getParameters($method); * @param \ReflectionFunctionAbstract $method
* @param \ReflectionClass $class
//Make the method static */
$this->phpdoc->appendTag(Tag::createInstance('@static', $this->phpdoc)); protected function initClassDefinedProperties($method, \ReflectionClass $class)
{
//Reference the 'real' function in the declaringclass $this->namespace = $class->getNamespaceName();
$this->declaringClassName = '\\' . ltrim($class->name, '\\'); $this->declaringClassName = '\\' . ltrim($class->name, '\\');
$this->root = '\\' . ltrim($class->getName(), '\\');
} }
} }
+36 -6
View File
@@ -26,29 +26,32 @@ class Method
protected $method; protected $method;
protected $output = ''; protected $output = '';
protected $declaringClassName;
protected $name; protected $name;
protected $namespace; protected $namespace;
protected $params = array(); protected $params = array();
protected $params_with_default = array(); protected $params_with_default = array();
protected $interfaces = array(); protected $interfaces = array();
protected $real_name;
protected $return = null; protected $return = null;
/** /**
* @param \ReflectionMethod $method * @param \ReflectionMethod|\ReflectionFunctionAbstract $method
* @param string $alias * @param string $alias
* @param \ReflectionClass $class * @param \ReflectionClass $class
* @param string|null $methodName * @param string|null $methodName
* @param array $interfaces * @param array $interfaces
*/ */
public function __construct(\ReflectionMethod $method, $alias, $class, $methodName = null, $interfaces = array()) public function __construct($method, $alias, $class, $methodName = null, $interfaces = array())
{ {
$this->method = $method; $this->method = $method;
$this->interfaces = $interfaces; $this->interfaces = $interfaces;
$this->name = $methodName ?: $method->name; $this->name = $methodName ?: $method->name;
$this->namespace = $method->getDeclaringClass()->getNamespaceName(); $this->real_name = $method->name;
$this->initClassDefinedProperties($method, $class);
//Create a DocBlock and serializer instance //Create a DocBlock and serializer instance
$this->phpdoc = new DocBlock($method, new Context($this->namespace)); $this->initPhpDoc($method);
//Normalize the description and inherit the docs from parents/interfaces //Normalize the description and inherit the docs from parents/interfaces
try { try {
@@ -65,11 +68,28 @@ class Method
$this->phpdoc->appendTag(Tag::createInstance('@static', $this->phpdoc)); $this->phpdoc->appendTag(Tag::createInstance('@static', $this->phpdoc));
//Reference the 'real' function in the declaring class //Reference the 'real' function in the declaring class
$declaringClass = $method->getDeclaringClass();
$this->declaringClassName = '\\' . ltrim($declaringClass->name, '\\');
$this->root = '\\' . ltrim($class->getName(), '\\'); $this->root = '\\' . ltrim($class->getName(), '\\');
} }
/**
* @param \ReflectionMethod $method
*/
protected function initPhpDoc($method)
{
$this->phpdoc = new DocBlock($method, new Context($this->namespace));
}
/**
* @param \ReflectionMethod $method
* @param \ReflectionClass $class
*/
protected function initClassDefinedProperties($method, \ReflectionClass $class)
{
$declaringClass = $method->getDeclaringClass();
$this->namespace = $declaringClass->getNamespaceName();
$this->declaringClassName = '\\' . ltrim($declaringClass->name, '\\');
}
/** /**
* Get the class wherein the function resides * Get the class wherein the function resides
* *
@@ -112,6 +132,16 @@ class Method
return $this->name; return $this->name;
} }
/**
* Get the real method name
*
* @return string
*/
public function getRealName()
{
return $this->real_name;
}
/** /**
* Get the parameters for this method * Get the parameters for this method
* *