Skip to content

Commit

Permalink
Add type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
enumag committed Mar 19, 2017
1 parent 9240d7d commit 67ae452
Show file tree
Hide file tree
Showing 19 changed files with 82 additions and 89 deletions.
4 changes: 2 additions & 2 deletions src/Application/ApplicationSubscriber.php
Expand Up @@ -30,7 +30,7 @@ public function __construct(RequestEntityLoader $loader)
/**
* @return array
*/
public static function getSubscribedEvents()
public static function getSubscribedEvents(): array
{
return [
ApplicationEvents::REQUEST => 'requestHandler',
Expand All @@ -40,7 +40,7 @@ public static function getSubscribedEvents()
/**
* @throws BadRequestException
*/
public function requestHandler(ApplicationRequestEvent $event)
public function requestHandler(ApplicationRequestEvent $event): void
{
try {
$this->loader->filterIn($event->getRequest());
Expand Down
6 changes: 3 additions & 3 deletions src/Application/EntityLoaderPresenterTrait.php
Expand Up @@ -30,7 +30,7 @@ trait EntityLoaderPresenterTrait
*/
private $user;

final public function injectEntityLoader(RequestEntityLoader $loader, RequestEntityUnloader $unloader, User $user = null)
final public function injectEntityLoader(RequestEntityLoader $loader, RequestEntityUnloader $unloader, User $user = null): void
{
$this->loader = $loader;
$this->unloader = $unloader;
Expand All @@ -45,7 +45,7 @@ final public function injectEntityLoader(RequestEntityLoader $loader, RequestEnt
*
* @return string
*/
public function storeRequest($request = null, $expiration = '+ 10 minutes')
public function storeRequest($request = null, $expiration = '+ 10 minutes'): string
{
// both parameters are optional
if ($request === null) {
Expand Down Expand Up @@ -74,7 +74,7 @@ public function storeRequest($request = null, $expiration = '+ 10 minutes')
*
* @param string $key
*/
public function restoreRequest($key)
public function restoreRequest($key): void
{
$session = $this->getSession('Arachne.Application/requests');
if (!isset($session[$key]) || ($this->user && $session[$key][0] !== null && $session[$key][0] !== $this->user->getId())) {
Expand Down
2 changes: 1 addition & 1 deletion src/Application/ParameterFinder.php
Expand Up @@ -145,7 +145,7 @@ private function loadMapping(string $presenter, array $parameters, array &$depen
/**
* @return ComponentReflection|null
*/
private function createReflection(ReflectionClass $reflection, string $component)
private function createReflection(ReflectionClass $reflection, string $component): ?ComponentReflection
{
$pos = strpos($component, IComponent::NAME_SEPARATOR);
if ($pos !== false) {
Expand Down
8 changes: 4 additions & 4 deletions src/Application/SecuredLinksPresenterTrait.php
Expand Up @@ -13,15 +13,15 @@
trait SecuredLinksPresenterTrait
{
use BaseSecuredLinksPresenterTrait {
getCsrfToken as private parentGetCsrfToken;
getCsrfToken as private nextrasGetCsrfToken;
}

/**
* @var EntityUnloader
*/
private $entityUnloader;

public function injectEntityUnloader(EntityUnloader $entityUnloader)
public function injectEntityUnloader(EntityUnloader $entityUnloader): void
{
$this->entityUnloader = $entityUnloader;
}
Expand All @@ -33,7 +33,7 @@ public function injectEntityUnloader(EntityUnloader $entityUnloader)
*
* @return string
*/
public function getCsrfToken($control, $method, $params)
public function getCsrfToken($control, $method, $params): string
{
array_walk(
$params,
Expand All @@ -44,6 +44,6 @@ function (&$value) {
}
);

return $this->parentGetCsrfToken($control, $method, $params);
return $this->nextrasGetCsrfToken($control, $method, $params);
}
}
4 changes: 2 additions & 2 deletions src/DI/EntityLoaderExtension.php
Expand Up @@ -58,7 +58,7 @@ class EntityLoaderExtension extends CompilerExtension
StringFilterIn::class => 'string',
];

public function loadConfiguration()
public function loadConfiguration(): void
{
$this->validateConfig($this->defaults);
$builder = $this->getContainerBuilder();
Expand Down Expand Up @@ -114,7 +114,7 @@ public function loadConfiguration()
->addTag(EventDispatcherExtension::TAG_SUBSCRIBER);
}

public function beforeCompile()
public function beforeCompile(): void
{
$builder = $this->getContainerBuilder();

Expand Down
4 changes: 2 additions & 2 deletions src/Routing/RouterWrapper.php
Expand Up @@ -40,15 +40,15 @@ public function __construct(IRouter $router, RequestEntityUnloader $unloader, bo
/**
* {@inheritdoc}
*/
public function match(IRequest $httpRequest)
public function match(IRequest $httpRequest): ?Request
{
return $this->router->match($httpRequest);
}

/**
* {@inheritdoc}
*/
public function constructUrl(Request $request, Url $refUrl)
public function constructUrl(Request $request, Url $refUrl): ?string
{
$request = clone $request;
$this->unloader->filterOut($request, $this->envelopes);
Expand Down
4 changes: 3 additions & 1 deletion tests/functional/src/EntityLoaderPresenterTraitTest.php
Expand Up @@ -6,6 +6,7 @@

use Arachne\Codeception\Module\NetteApplicationModule;
use Arachne\Codeception\Module\NetteDIModule;
use Arachne\EntityLoader\Application\EntityLoaderPresenterTrait;
use Codeception\Test\Unit;
use Nette\Application\AbortException;
use Nette\Application\Application;
Expand All @@ -20,9 +21,10 @@ class EntityLoaderPresenterTraitTest extends Unit
*/
protected $tester;

public function testStoreRestoreRequest()
public function testStoreRestoreRequest(): void
{
$this->tester->amOnPage('/entity?parameter=5');
/** @var EntityLoaderPresenterTrait $presenter */
$presenter = $this->tester->grabService(Application::class)->getPresenter();
$key = $presenter->storeRequest();
try {
Expand Down
16 changes: 8 additions & 8 deletions tests/functional/src/Fixtures/ArticlePresenter.php
Expand Up @@ -16,39 +16,39 @@ class ArticlePresenter extends Presenter
use EntityLoaderPresenterTrait;
use SecuredLinksPresenterTrait;

public function startup()
public function startup(): void
{
$this->terminate();
}

public function actionUntyped($parameter)
public function actionUntyped($parameter): void
{
}

public function actionEntity(Article $parameter)
public function actionEntity(Article $parameter): void
{
}

public function actionInt(int $parameter = 1)
public function actionInt(int $parameter = 1): void
{
}

public function actionBool(bool $parameter)
public function actionBool(bool $parameter): void
{
}

public function actionFloat(float $parameter)
public function actionFloat(float $parameter): void
{
}

public function actionString(string $parameter)
public function actionString(string $parameter): void
{
}

/**
* @secured
*/
public function handleSignal(Article $parameter)
public function handleSignal(Article $parameter): void
{
}
}
22 changes: 11 additions & 11 deletions tests/functional/src/RequestEntityLoaderTest.php
Expand Up @@ -22,7 +22,7 @@ class RequestEntityLoaderTest extends Unit
*/
protected $tester;

public function testUntyped()
public function testUntyped(): void
{
$this->tester->amOnPage('/untyped?parameter=5');
$request = $this->tester->grabService(Application::class)->getPresenter()->getRequest();
Expand All @@ -35,7 +35,7 @@ public function testUntyped()
);
}

public function testEntity()
public function testEntity(): void
{
$this->tester->amOnPage('/entity?parameter=5');
$presenter = $this->tester->grabService(Application::class)->getPresenter();
Expand All @@ -50,7 +50,7 @@ public function testEntity()
);
}

public function testInt()
public function testInt(): void
{
$this->tester->amOnPage('/int?parameter=5');
$presenter = $this->tester->grabService(Application::class)->getPresenter();
Expand All @@ -65,7 +65,7 @@ public function testInt()
);
}

public function testIntWithDefault()
public function testIntWithDefault(): void
{
$this->tester->amOnPage('/int');
$presenter = $this->tester->grabService(Application::class)->getPresenter();
Expand All @@ -79,7 +79,7 @@ public function testIntWithDefault()
);
}

public function testIntError()
public function testIntError(): void
{
try {
$this->tester->amOnPage('/int?parameter[]=0');
Expand All @@ -88,7 +88,7 @@ public function testIntError()
}
}

public function testBool()
public function testBool(): void
{
$this->tester->amOnPage('/bool?parameter=1');
$presenter = $this->tester->grabService(Application::class)->getPresenter();
Expand All @@ -103,7 +103,7 @@ public function testBool()
);
}

public function testBoolError()
public function testBoolError(): void
{
try {
$this->tester->amOnPage('/bool?parameter[]=0');
Expand All @@ -112,7 +112,7 @@ public function testBoolError()
}
}

public function testFloat()
public function testFloat(): void
{
$this->tester->amOnPage('/float?parameter=1');
$presenter = $this->tester->grabService(Application::class)->getPresenter();
Expand All @@ -127,7 +127,7 @@ public function testFloat()
);
}

public function testFloatError()
public function testFloatError(): void
{
try {
$this->tester->amOnPage('/float?parameter[]=0');
Expand All @@ -136,7 +136,7 @@ public function testFloatError()
}
}

public function testString()
public function testString(): void
{
$this->tester->amOnPage('/string?parameter=1');
$presenter = $this->tester->grabService(Application::class)->getPresenter();
Expand All @@ -151,7 +151,7 @@ public function testString()
);
}

public function testStringError()
public function testStringError(): void
{
try {
$this->tester->amOnPage('/string?parameter[]=0');
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/src/RequestEntityUnloaderTest.php
Expand Up @@ -20,7 +20,7 @@ class RequestEntityUnloaderTest extends Unit
*/
protected $tester;

public function testLink()
public function testLink(): void
{
$this->tester->amOnPage('/default');
$presenter = $this->tester->grabService(Application::class)->getPresenter();
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/src/SecuredLinksPresenterTraitTest.php
Expand Up @@ -20,7 +20,7 @@ class SecuredLinksPresenterTraitTest extends Unit
*/
protected $tester;

public function testLink()
public function testLink(): void
{
$this->tester->amOnPage('/default');
$presenter = $this->tester->grabService(Application::class)->getPresenter();
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/src/Classes/TestComponent.php
Expand Up @@ -18,7 +18,7 @@ class TestComponent extends PresenterComponent
*/
public $persistent;

public function handleTestHandle(Class6 $handleEntity)
public function handleTestHandle(Class6 $handleEntity): void
{
}

Expand Down
10 changes: 5 additions & 5 deletions tests/unit/src/Classes/TestPresenter.php
Expand Up @@ -25,23 +25,23 @@ class TestPresenter extends Presenter
*/
public $persistent2;

public function actionTestAction(Class2 $actionEntity)
public function actionTestAction(Class2 $actionEntity): void
{
}

public function renderTestRender(Class3 $renderEntity)
public function renderTestRender(Class3 $renderEntity): void
{
}

public function handleTestHandle(Class4 $handleEntity)
public function handleTestHandle(Class4 $handleEntity): void
{
}

public function handleNoTypehintHandle($handleEntity)
public function handleNoTypehintHandle($handleEntity): void
{
}

public function actionNonexistentParameter($entity)
public function actionNonexistentParameter($entity): void
{
}

Expand Down
10 changes: 5 additions & 5 deletions tests/unit/src/EntityLoaderTest.php
Expand Up @@ -33,14 +33,14 @@ class EntityLoaderTest extends Unit
*/
private $filterIterator;

protected function _before()
protected function _before(): void
{
$this->filterHandle = Phony::mock(FilterInInterface::class);
$this->filterIterator = new ArrayObject();
$this->entityLoader = new EntityLoader($this->filterIterator);
}

public function testFilterIn()
public function testFilterIn(): void
{
$this->filterIterator[] = $this->filterHandle->get();

Expand All @@ -62,7 +62,7 @@ public function testFilterIn()
->calledWith(1, DateTime::class);
}

public function testFilterInFail()
public function testFilterInFail(): void
{
$this->filterIterator[] = $this->filterHandle->get();

Expand All @@ -83,14 +83,14 @@ public function testFilterInFail()
}
}

public function testFilterInIgnore()
public function testFilterInIgnore(): void
{
// Make sure that the converter is not called at all if the parameter already has the desired type.
$mock1 = Phony::mock(DateTime::class)->get();
self::assertSame($mock1, $this->entityLoader->filterIn(DateTime::class, $mock1));
}

public function testFilterNotFound()
public function testFilterNotFound(): void
{
$parameters = [
'entity' => 'value1',
Expand Down

0 comments on commit 67ae452

Please sign in to comment.