From d0d0f451ac3b9b8af192178d0e165211a7705bf4 Mon Sep 17 00:00:00 2001 From: Tomas Jacik Date: Tue, 17 Oct 2017 02:37:56 +0200 Subject: [PATCH] Fixed compatibility with php 5.6 --- app/Forms/SignInFormFactory.php | 14 +++----- app/Forms/UserCreateFormFactory.php | 6 ++-- app/Forms/WikiEditFormFactory.php | 8 ++++- .../CommonMark/TableDocumentProcessor.php | 2 +- app/Libs/Config.php | 13 +++++-- app/Libs/Security/Authenticator.php | 1 - app/Libs/Security/User.php | 23 ++++++++++--- app/Libs/Security/UserManager.php | 34 +++++++++++++++---- app/Presenters/ErrorPresenter.php | 5 +-- app/Presenters/SignPresenter.php | 1 - app/Presenters/UserCreatePresenter.php | 5 ++- 11 files changed, 79 insertions(+), 33 deletions(-) diff --git a/app/Forms/SignInFormFactory.php b/app/Forms/SignInFormFactory.php index 265938b..00cc618 100644 --- a/app/Forms/SignInFormFactory.php +++ b/app/Forms/SignInFormFactory.php @@ -4,11 +4,12 @@ use Nette; use Nette\Application\UI\Form; +use Nette\Security\User; use Nette\Utils\ArrayHash; use Nextras; /** - * @method onLoggedIn(Nette\Security\User $user) + * @method onLoggedIn(User $user) */ final class SignInFormFactory { @@ -20,14 +21,11 @@ final class SignInFormFactory public $onLoggedIn = []; /** - * @var Nette\Security\User + * @var User */ private $user; - /** - * @param Nette\Security\User $user - */ - public function __construct(Nette\Security\User $user) + public function __construct(User $user) { $this->user = $user; } @@ -55,10 +53,6 @@ public function create() return $form; } - /** - * @param Form $form - * @param ArrayHash $values - */ public function formSuccess(Form $form, ArrayHash $values) { if ($values->remember) { diff --git a/app/Forms/UserCreateFormFactory.php b/app/Forms/UserCreateFormFactory.php index 3b77b8f..5004166 100644 --- a/app/Forms/UserCreateFormFactory.php +++ b/app/Forms/UserCreateFormFactory.php @@ -26,13 +26,15 @@ final class UserCreateFormFactory */ private $userManager; - public function __construct(UserManager $userManager) { $this->userManager = $userManager; } - public function create(): Form + /** + * @return Form + */ + public function create() { $form = new Form; $form->setRenderer(new Nextras\Forms\Rendering\Bs3FormRenderer) diff --git a/app/Forms/WikiEditFormFactory.php b/app/Forms/WikiEditFormFactory.php index 6cd5ace..24df083 100644 --- a/app/Forms/WikiEditFormFactory.php +++ b/app/Forms/WikiEditFormFactory.php @@ -31,7 +31,13 @@ public function __construct(Config $config) $this->config = $config; } - public function create(?string $page, string $document): Form + /** + * @param null|string $page + * @param string $document + * + * @return Form + */ + public function create($page, $document) { $form = new Form; $form->setRenderer(new Nextras\Forms\Rendering\Bs3FormRenderer) diff --git a/app/Libs/CommonMark/TableDocumentProcessor.php b/app/Libs/CommonMark/TableDocumentProcessor.php index 6ba26a8..bfe7064 100644 --- a/app/Libs/CommonMark/TableDocumentProcessor.php +++ b/app/Libs/CommonMark/TableDocumentProcessor.php @@ -8,7 +8,7 @@ final class TableDocumentProcessor implements DocumentProcessorInterface { - public function processDocument(Document $document): void + public function processDocument(Document $document) { $walker = $document->walker(); while ($event = $walker->next()) { diff --git a/app/Libs/Config.php b/app/Libs/Config.php index ae98462..47c80a3 100644 --- a/app/Libs/Config.php +++ b/app/Libs/Config.php @@ -28,8 +28,12 @@ public function __construct($arr) /** * Get Wiki page path on disk based on url path. + * + * @param null|string $wikiPath + * + * @return string */ - public function getPageFilePath(?string $wikiPath): string + public function getPageFilePath($wikiPath) { if (!$wikiPath) { $wikiPath = $this->defaultPage; @@ -38,7 +42,12 @@ public function getPageFilePath(?string $wikiPath): string return vsprintf('%s/%s.md', [$this->pageDir, $wikiPath]); } - public function getUserFilePath(string $username): string + /** + * @param string $username + * + * @return string + */ + public function getUserFilePath($username) { return vsprintf('%s/%s.neon', [$this->userDir, $username]); } diff --git a/app/Libs/Security/Authenticator.php b/app/Libs/Security/Authenticator.php index 87b1ddd..cd2f9f5 100644 --- a/app/Libs/Security/Authenticator.php +++ b/app/Libs/Security/Authenticator.php @@ -14,7 +14,6 @@ final class Authenticator implements IAuthenticator */ private $userManager; - public function __construct(UserManager $userManager) { $this->userManager = $userManager; diff --git a/app/Libs/Security/User.php b/app/Libs/Security/User.php index a6540e2..b651147 100644 --- a/app/Libs/Security/User.php +++ b/app/Libs/Security/User.php @@ -21,25 +21,38 @@ final class User implements IIdentity */ private $roles; - - public function __construct(string $username, string $name, array $roles) + /** + * @param string $username + * @param string $name + * @param array $roles + */ + public function __construct($username, $name, array $roles) { $this->username = $username; $this->name = $name; $this->roles = $roles; } - public function getId(): string + /** + * @return string + */ + public function getId() { return $this->username; } - public function getName(): string + /** + * @return string + */ + public function getName() { return $this->name; } - public function getRoles(): array + /** + * @return array + */ + public function getRoles() { return $this->roles; } diff --git a/app/Libs/Security/UserManager.php b/app/Libs/Security/UserManager.php index 07f68f0..c69c1f0 100644 --- a/app/Libs/Security/UserManager.php +++ b/app/Libs/Security/UserManager.php @@ -14,13 +14,18 @@ final class UserManager */ private $config; - public function __construct(Config $config) { $this->config = $config; } - public function getData(string $username): array + /** + * @param string $username + * + * @return array + * @throws UserNotFoundException + */ + public function getData($username) { $file = $this->config->getUserFilePath($username); if (!is_file($file)) { @@ -30,14 +35,27 @@ public function getData(string $username): array return Neon::decode(FileSystem::read($file)); } - public function getUser(string $username): User + /** + * @param string $username + * + * @return User + */ + public function getUser($username) { $data = $this->getData($username); return new User($data['username'], $data['name'], $data['roles']); } - public function create(string $username, string $name, string $password): User + /** + * @param string $username + * @param string $name + * @param string $password + * + * @return User + * @throws UserExistsException + */ + public function create($username, $name, $password) { $roles = ['admin']; @@ -57,7 +75,11 @@ public function create(string $username, string $name, string $password): User return new User($username, $name, $roles); } - public function changePassword(string $username, string $password): void + /** + * @param string $username + * @param string $password + */ + public function changePassword($username, $password) { $data = $this->getData($username); $data['password'] = Passwords::hash($password); @@ -66,12 +88,10 @@ public function changePassword(string $username, string $password): void } } - final class UserExistsException extends \Exception { } - final class UserNotFoundException extends \Exception { } diff --git a/app/Presenters/ErrorPresenter.php b/app/Presenters/ErrorPresenter.php index bf708f0..3445e08 100644 --- a/app/Presenters/ErrorPresenter.php +++ b/app/Presenters/ErrorPresenter.php @@ -10,10 +10,11 @@ final class ErrorPresenter implements Nette\Application\IPresenter { use Nette\SmartObject; - /** @var ILogger */ + /** + * @var ILogger + */ private $logger; - public function __construct(ILogger $logger) { $this->logger = $logger; diff --git a/app/Presenters/SignPresenter.php b/app/Presenters/SignPresenter.php index 50faa34..e4e8b42 100644 --- a/app/Presenters/SignPresenter.php +++ b/app/Presenters/SignPresenter.php @@ -20,7 +20,6 @@ final class SignPresenter extends BasePresenter */ public $signInFormFactory; - public function createComponentSignInForm() { $this->signInFormFactory->onLoggedIn[] = function ($user) { diff --git a/app/Presenters/UserCreatePresenter.php b/app/Presenters/UserCreatePresenter.php index 77cccca..9c03020 100644 --- a/app/Presenters/UserCreatePresenter.php +++ b/app/Presenters/UserCreatePresenter.php @@ -21,7 +21,10 @@ final class UserCreatePresenter extends BasePresenter */ public $userCreateFormFactory; - protected function createComponentUserCreateForm(): Form + /** + * @return Form + */ + protected function createComponentUserCreateForm() { $this->userCreateFormFactory->onCreate[] = function ($identity) { $this->getUser()->login($identity);