Skip to content

Commit

Permalink
various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jun 2, 2017
1 parent 316ac87 commit 3adb5e1
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 38 deletions.
Expand Up @@ -9,6 +9,9 @@ final class PresentReturnedClass
*/
public $someProperty;

/**
* @see $someProperty
*/
public function someMethod(): void
{
}
Expand Down
15 changes: 13 additions & 2 deletions packages/Element/src/Latte/Filter/MethodReflectionNamingFilter.php
Expand Up @@ -3,6 +3,8 @@
namespace ApiGen\Element\Latte\Filter;

use ApiGen\Reflection\Contract\Reflection\Class_\ClassMethodReflectionInterface;
use ApiGen\Reflection\Contract\Reflection\Interface_\InterfaceMethodReflectionInterface;
use ApiGen\Reflection\Contract\Reflection\Trait_\TraitMethodReflectionInterface;
use Symplify\ModularLatteFilters\Contract\DI\LatteFiltersProviderInterface;

final class MethodReflectionNamingFilter implements LatteFiltersProviderInterface
Expand All @@ -13,8 +15,17 @@ final class MethodReflectionNamingFilter implements LatteFiltersProviderInterfac
public function getFilters(): array
{
return [
'prettyMethodName' => function (ClassMethodReflectionInterface $methodReflection) {
return $methodReflection->getDeclaringClassName() . '::' . $methodReflection->getName() . '()';
// use in .latte: {$method|prettyMethodName}
'prettyMethodName' => function ($methodReflection) {
if ($methodReflection instanceof ClassMethodReflectionInterface) {
return $methodReflection->getDeclaringClassName() . '::' . $methodReflection->getName() . '()';
}
if ($methodReflection instanceof InterfaceMethodReflectionInterface) {
return $methodReflection->getDeclaringInterfaceName() . '::' . $methodReflection->getName() . '()';
}
if ($methodReflection instanceof TraitMethodReflectionInterface) {
return $methodReflection->getDeclaringTraitName() . '::' . $methodReflection->getName() . '()';
}
}
];
}
Expand Down
Expand Up @@ -25,12 +25,5 @@ public function isFinal(): bool;

public function isStatic(): bool;

public function getImplementedMethod(): ?InterfaceMethodReflectionInterface;

/**
* @return ClassMethodReflectionInterface|TraitMethodReflectionInterface|null
*/
public function getOverriddenMethod();

public function returnsReference(): bool;
}
Expand Up @@ -22,5 +22,7 @@ public function isVariadic(): bool;

public function isCallable(): bool;

public function isPassedByReference(): bool;

public function getDescription(): string;
}
Expand Up @@ -3,12 +3,21 @@
namespace ApiGen\Reflection\Contract\Reflection\Class_;

use ApiGen\Reflection\Contract\Reflection\AbstractMethodReflectionInterface;
use ApiGen\Reflection\Contract\Reflection\Interface_\InterfaceMethodReflectionInterface;
use ApiGen\Reflection\Contract\Reflection\Method\MethodParameterReflectionInterface;
use ApiGen\Reflection\Contract\Reflection\Trait_\TraitMethodReflectionInterface;

interface ClassMethodReflectionInterface extends AbstractMethodReflectionInterface, AbstractClassElementInterface
{
/**
* @return MethodParameterReflectionInterface[]
*/
public function getParameters(): array;

public function getImplementedMethod(): ?InterfaceMethodReflectionInterface;

/**
* @return ClassMethodReflectionInterface|TraitMethodReflectionInterface|null
*/
public function getOverriddenMethod();
}
Expand Up @@ -95,6 +95,11 @@ public function isArray(): bool
return $this->betterParameterReflection->isArray();
}

public function isPassedByReference(): bool
{
return $this->betterParameterReflection->isPassedByReference();
}

public function setTransformerCollector(TransformerCollectorInterface $transformerCollector): void
{
$this->transformerCollector = $transformerCollector;
Expand Down
Expand Up @@ -160,8 +160,6 @@ public function isStatic(): bool
return $this->betterMethodReflection->isStatic();
}

// @todo: is used?
public function getImplementedMethod(): ?InterfaceMethodReflectionInterface
{
foreach ($this->getDeclaringClass()->getOwnInterfaces() as $interface) {
Expand All @@ -172,7 +170,6 @@ public function getImplementedMethod(): ?InterfaceMethodReflectionInterface

return null;
}

// @todo: is used?
public function getOverriddenMethod(): ?ClassMethodReflectionInterface
{
Expand Down
Expand Up @@ -77,14 +77,6 @@ public function isStatic(): bool
return $this->betterMethodReflection->isStatic();
}

public function getImplementedMethod(): ?InterfaceMethodReflectionInterface
{
}

public function getOverriddenMethod(): void
{
}

public function returnsReference(): bool
{
return $this->betterMethodReflection->returnsReference();
Expand Down
Expand Up @@ -45,9 +45,10 @@ public function testGetDescription(): void
$this->assertSame('the URL of the API endpoint', $this->parameterReflection->getDescription());
}

public function testIsArray(): void
public function testType(): void
{
$this->assertFalse($this->parameterReflection->isArray());
$this->assertFalse($this->parameterReflection->isVariadic());
}

public function testGetClass(): void
Expand Down Expand Up @@ -77,18 +78,15 @@ public function testGetDeclaringClass(): void
ClassReflectionInterface::class,
$this->parameterReflection->getDeclaringClass()
);
}

public function testGetDeclaringClassName(): void
{
$this->assertSame(
ParameterMethodClass::class,
$this->parameterReflection->getDeclaringClassName()
);
}

public function testIsVariadic(): void
public function testIsPassedByReference(): void
{
$this->assertFalse($this->parameterReflection->isVariadic());
$this->assertFalse($this->parameterReflection->isPassedByReference());
}
}
8 changes: 4 additions & 4 deletions packages/ThemeDefault/src/class.latte
Expand Up @@ -17,15 +17,15 @@
<dd>
{if $class->getParentClass()}
extends
<a href="{$class->getParentClass()|reflectionLink}">
<a href="{$class->getParentClass()|linkReflection}">
<span n:class="$class->getParentClass()->isDeprecated() ? deprecated">{$class->getParentClass()->getName()}</span>
</a>
{/if}

{if $class->getOwnInterfaces()}
implements
{foreach $class->getOwnInterfaces() as $ownInterface}
<a href="{$ownInterface|reflectionLink}">
<a href="{$ownInterface|linkReflection}">
<span n:class="$ownInterface->isDeprecated() ? deprecated">{$ownInterface->getName()}</span>
</a>{sep}, {/sep}
{/foreach}
Expand All @@ -34,7 +34,7 @@
{if $class->getTraits()}
uses
{foreach $class->getTraits() as $ownTrait}
<a href="{$ownTrait|reflectionLink}">
<a href="{$ownTrait|linkReflection}">
<span n:class="$ownTrait->isDeprecated() ? deprecated">{$ownTrait->getName()}</span>
</a>{sep}, {/sep}
{/foreach}
Expand Down Expand Up @@ -72,7 +72,7 @@
{if $class->getOwnMethods()}
<table class="summary methods" id="methods">
<caption>Methods summary</caption>
{foreach $ownMethods as $method}
{foreach $class->getOwnMethods() as $method}
{include "partial/method.latte", method => $method}
{/foreach}
</table>
Expand Down
2 changes: 1 addition & 1 deletion packages/ThemeDefault/src/interface.latte
Expand Up @@ -20,7 +20,7 @@
{if $interface->getOwnInterfaces()}
implements
{foreach $interface->getOwnInterfaces() as $ownInterface}
<a href="{$ownInterface|reflectionLink}">
<a href="{$ownInterface|linkReflection}">
<span n:class="$ownInterface->isDeprecated() ? deprecated">{$ownInterface->getName()}</span>
</a>{sep}, {/sep}
{/foreach}
Expand Down
12 changes: 6 additions & 6 deletions packages/ThemeDefault/src/partial/method.latte
Expand Up @@ -3,7 +3,7 @@

<td class="attributes">
<code>
{if !$class->isInterface() && $method->isAbstract()}abstract{elseif $method->isFinal()}final{/if} {if $method->isProtected()}protected{elseif $method->isPrivate()}private{else}public{/if} {if $method->isStatic()}static{/if}
{if $method->isAbstract()}abstract{elseif $method->isFinal()}final{/if} {if $method->isProtected()}protected{elseif $method->isPrivate()}private{else}public{/if} {if $method->isStatic()}static{/if}

{ifset $annotations['return']}{$annotations['return'][0]|annotation:$method|noescape}{/ifset}
{if $method->returnsReference()}&amp;{/if}
Expand All @@ -22,7 +22,7 @@
{else}
{$parameter->getTypeHint()}
{/if}
<var>{if $parameter->passedByReference}&amp; {/if}${$parameter->getName()}</var>{if $parameter->defaultValueAvailable} = {$parameter->defaultValueDefinition|highlightPHP:$class|noescape}{elseif $parameter->isVariadic()},…{/if}</span>{sep}, {/sep}
<var>{if $parameter->isPassedByReference()}&amp; {/if}${$parameter->getName()}</var>{if $parameter->getDefaultValueDefinition()} = {$parameter->getDefaultValueDefinition()|highlightPHP:$class|noescape}{elseif $parameter->isVariadic()},…{/if}</span>{sep}, {/sep}
{/foreach}
){/block}</code>

Expand Down Expand Up @@ -85,12 +85,12 @@
</div>
{/foreach}

{if $method->getOverridenMethod()}
{if $method->getOverriddenMethod()}
<h4>Overrides</h4>
<div class="list">
<code>
<a n:tag-if="$method->getOverridenMethod()->getDeclaringClass()" href="{$method->getOverridenMethod()|linkReflection}">
{$method->getOverridenMethod()|prettyMethodName}
<a href="{$method->getOverriddenMethod()|linkReflection}">
{$method->getOverriddenMethod()|prettyMethodName}
</a>
</code>
</div>
Expand All @@ -100,7 +100,7 @@
<h4>Implementation of</h4>
<div class="list">
<code>
<a n:tag-if="$method->getImplementedMethod()->getDeclaringClass()" href="{$method->getImplementedMethod()|linkReflection}">
<a href="{$method->getImplementedMethod()|linkReflection}">
{$method->getImplementedMethod()|prettyMethodName}
</a>
</code>
Expand Down
2 changes: 1 addition & 1 deletion packages/ThemeDefault/src/trait.latte
Expand Up @@ -20,7 +20,7 @@
{if $trait->getTraits()}
uses
{foreach $trait->getTraits() as $ownTrait}
<a href="{$ownTrait|reflectionLink}">
<a href="{$ownTrait|linkReflection}">
<span n:class="$ownTrait->isDeprecated() ? deprecated">{$ownTrait->getName()}</span>
</a>{sep}, {/sep}
{/foreach}
Expand Down

0 comments on commit 3adb5e1

Please sign in to comment.