Skip to content
Permalink
Browse files

added PHP 7.1 typehints

  • Loading branch information...
dg committed Mar 26, 2018
1 parent 2fea977 commit 9e674d7fe9cfac504586fd48811ff9afa0ea2945
@@ -20,23 +20,20 @@ public function __construct(Nette\Database\Context $database)
}
/** @return Nette\Database\Table\Selection */
public function findAll()
public function findAll(): Nette\Database\Table\Selection
{
return $this->database->table('albums');
}
/** @return Nette\Database\Table\ActiveRow */
public function findById($id)
public function findById(int $id): Nette\Database\Table\ActiveRow
{
return $this->findAll()->get($id);
}
/** @return Nette\Database\Table\ActiveRow */
public function insert($values)
public function insert(iterable $values): void
{
return $this->findAll()->insert($values);
$this->findAll()->insert($values);
}
}
@@ -20,7 +20,7 @@ public function __construct(Model\AlbumRepository $albums)
}
protected function startup()
protected function startup(): void
{
parent::startup();
@@ -36,7 +36,7 @@ protected function startup()
/********************* view default *********************/
public function renderDefault()
public function renderDefault(): void
{
$this->template->albums = $this->albums->findAll()->order('artist')->order('title');
}
@@ -45,13 +45,13 @@ public function renderDefault()
/********************* views add & edit *********************/
public function renderAdd()
public function renderAdd(): void
{
$this['albumForm']['save']->caption = 'Add';
}
public function renderEdit($id = 0)
public function renderEdit(int $id): void
{
$form = $this['albumForm'];
if (!$form->isSubmitted()) {
@@ -67,7 +67,7 @@ public function renderEdit($id = 0)
/********************* view delete *********************/
public function renderDelete($id = 0)
public function renderDelete(int $id): void
{
$this->template->album = $this->albums->findById($id);
if (!$this->template->album) {
@@ -81,9 +81,8 @@ public function renderDelete($id = 0)
/**
* Edit form factory.
* @return Form
*/
protected function createComponentAlbumForm()
protected function createComponentAlbumForm(): Form
{
$form = new Form;
$form->addText('artist', 'Artist:')
@@ -105,7 +104,7 @@ protected function createComponentAlbumForm()
}
public function albumFormSucceeded($button)
public function albumFormSucceeded(Nette\Forms\Controls\SubmitButton $button): void
{
$values = $button->getForm()->getValues();
$id = (int) $this->getParameter('id');
@@ -122,9 +121,8 @@ public function albumFormSucceeded($button)
/**
* Delete form factory.
* @return Form
*/
protected function createComponentDeleteForm()
protected function createComponentDeleteForm(): Form
{
$form = new Form;
$form->addSubmit('cancel', 'Cancel')
@@ -139,15 +137,15 @@ protected function createComponentDeleteForm()
}
public function deleteFormSucceeded()
public function deleteFormSucceeded(): void
{
$this->albums->findById($this->getParameter('id'))->delete();
$this->albums->findById((int) $this->getParameter('id'))->delete();
$this->flashMessage('Album has been deleted.');
$this->redirect('default');
}
public function formCancelled()
public function formCancelled(): void
{
$this->redirect('default');
}
@@ -15,9 +15,8 @@ class SignPresenter extends Nette\Application\UI\Presenter
/**
* Sign-in form factory.
* @return Nette\Application\UI\Form
*/
protected function createComponentSignInForm()
protected function createComponentSignInForm(): UI\Form
{
$form = new UI\Form;
$form->addText('username', 'Username:')
@@ -33,7 +32,7 @@ protected function createComponentSignInForm()
}
public function signInFormSucceeded($form, $values)
public function signInFormSucceeded(UI\Form $form, \stdClass $values): void
{
try {
$this->getUser()->login($values->username, $values->password);
@@ -48,7 +47,7 @@ public function signInFormSucceeded($form, $values)
}
public function actionOut()
public function actionOut(): void
{
$this->getUser()->logout();
$this->flashMessage('You have been signed out.');
@@ -11,10 +11,10 @@ class FifteenControl extends UI\Control
/** @var int */
public $width = 4;
/** @var callable[] function ($sender) */
/** @var callable[] function (FifteenControl $sender): void */
public $onAfterClick;
/** @var callable[] function ($sender, $round) */
/** @var callable[] function (FifteenControl $sender, int $round): void */
public $onGameOver;
/** @persistent array */
@@ -31,7 +31,7 @@ public function __construct()
}
public function handleClick($x, $y)
public function handleClick(int $x, int $y): void
{
if (!$this->isClickable($x, $y)) {
throw new UI\BadSignalException('Action not allowed.');
@@ -47,7 +47,7 @@ public function handleClick($x, $y)
}
public function handleShuffle()
public function handleShuffle(): void
{
$i = 100;
while ($i) {
@@ -62,13 +62,13 @@ public function handleShuffle()
}
public function getRound()
public function getRound(): int
{
return $this->round;
}
public function isClickable($x, $y, &$rel = null)
public function isClickable(int $x, int $y, string &$rel = null): bool
{
$rel = null;
$pos = $x + $y * $this->width;
@@ -95,7 +95,7 @@ public function isClickable($x, $y, &$rel = null)
}
private function move($x, $y)
private function move(int $x, int $y): void
{
$pos = $x + $y * $this->width;
$emptyPos = $this->searchEmpty();
@@ -104,13 +104,13 @@ private function move($x, $y)
}
private function searchEmpty()
private function searchEmpty(): int
{
return array_search(0, $this->order, true);
}
public function render()
public function render(): void
{
$template = $this->template;
$template->width = $this->width;
@@ -4,17 +4,16 @@
class DefaultPresenter extends Nette\Application\UI\Presenter
{
public function renderDefault()
public function renderDefault(): void
{
$this->redrawControl('round');
}
/**
* Fifteen game control factory.
* @return FifteenControl
*/
protected function createComponentFifteen()
protected function createComponentFifteen(): FifteenControl
{
$fifteen = new FifteenControl;
$fifteen->onGameOver[] = [$this, 'gameOver'];
@@ -23,7 +22,7 @@ protected function createComponentFifteen()
}
public function gameOver($sender, $round)
public function gameOver($sender, int $round): void
{
$this->template->flash = 'Congratulations!';
$this->redrawControl('flash');
@@ -9,7 +9,7 @@
*/
class TemplateRouter extends Routers\RouteList
{
public function __construct($path, $cachePath)
public function __construct(string $path, string $cachePath)
{
if (is_file($cacheFile = $cachePath . '/routes.php')) {
$routes = require $cacheFile;
@@ -19,8 +19,8 @@ public function __construct($path, $cachePath)
}
foreach ($routes as $mask => $file) {
$this[] = new Routers\Route($mask, function ($presenter) use ($file, $cachePath) {
return $presenter->createTemplate(null, function () use ($cachePath) {
$this[] = new Routers\Route($mask, function (NetteModule\MicroPresenter $presenter) use ($file, $cachePath) {
return $presenter->createTemplate(null, function () use ($cachePath): Latte\Engine {
$latte = new Latte\Engine;
$latte->setTempDirectory($cachePath . '/cache');
$macroSet = new Latte\Macros\MacroSet($latte->getCompiler());
@@ -32,7 +32,7 @@ public function __construct($path, $cachePath)
}
public function scanRoutes($path)
public function scanRoutes(string $path): array
{
$routes = [];
$latte = new Latte\Engine;
@@ -8,7 +8,7 @@
abstract class BasePresenter extends Nette\Application\UI\Presenter
{
protected function beforeRender()
protected function beforeRender(): void
{
$this->template->viewName = $this->getView();
$this->template->root = isset($_SERVER['SCRIPT_FILENAME']) ? realpath(dirname(dirname($_SERVER['SCRIPT_FILENAME']))) : null;

0 comments on commit 9e674d7

Please sign in to comment.
You can’t perform that action at this time.