From d203071de0798802c0024debd793ce89f180cc16 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Fri, 29 Nov 2019 15:43:53 +0100 Subject: [PATCH 1/6] First step to PHP 7.4 compatibility... --- src/Helpers/Authenticator.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Helpers/Authenticator.php b/src/Helpers/Authenticator.php index db33339b..28e48500 100644 --- a/src/Helpers/Authenticator.php +++ b/src/Helpers/Authenticator.php @@ -25,7 +25,7 @@ class Authenticator /** @var string[] */ protected $permissions; - /** @var int */ + /** @var int|string|null */ protected $passwordAlgorithm = PASSWORD_DEFAULT; /** @@ -163,13 +163,11 @@ class Authenticator */ public function verifyPassword(User $user, string $password) { - $algorithm = $this->passwordAlgorithm; - if (!password_verify($password, $user->password)) { return false; } - if (password_needs_rehash($user->password, $algorithm)) { + if (password_needs_rehash($user->password, $this->passwordAlgorithm)) { $this->setPassword($user, $password); } @@ -182,14 +180,12 @@ class Authenticator */ public function setPassword(User $user, string $password) { - $algorithm = $this->passwordAlgorithm; - - $user->password = password_hash($password, $algorithm); + $user->password = password_hash($password, $this->passwordAlgorithm); $user->save(); } /** - * @return int + * @return int|string|null */ public function getPasswordAlgorithm() { @@ -197,9 +193,9 @@ class Authenticator } /** - * @param int $passwordAlgorithm + * @param int|string|null $passwordAlgorithm */ - public function setPasswordAlgorithm(int $passwordAlgorithm) + public function setPasswordAlgorithm($passwordAlgorithm) { $this->passwordAlgorithm = $passwordAlgorithm; } From a1e1d91a640995f40181f0b720f48d971b735b76 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Fri, 29 Nov 2019 16:07:51 +0100 Subject: [PATCH 2/6] PHP 7.4: Fixed xdebug code coverage --- src/Config/ConfigServiceProvider.php | 5 +++-- src/Middleware/ErrorHandler.php | 10 ++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Config/ConfigServiceProvider.php b/src/Config/ConfigServiceProvider.php index 2c320fdd..aff7918d 100644 --- a/src/Config/ConfigServiceProvider.php +++ b/src/Config/ConfigServiceProvider.php @@ -40,10 +40,11 @@ class ConfigServiceProvider extends ServiceProvider continue; } - $config->set(array_replace_recursive( + $configuration = array_replace_recursive( $config->get(null), require $file - )); + ); + $config->set($configuration); } if (empty($config->get(null))) { diff --git a/src/Middleware/ErrorHandler.php b/src/Middleware/ErrorHandler.php index 65e2e609..b8f8b166 100644 --- a/src/Middleware/ErrorHandler.php +++ b/src/Middleware/ErrorHandler.php @@ -67,13 +67,11 @@ class ErrorHandler implements MiddlewareInterface if ($request instanceof Request) { $session = $request->getSession(); - $session->set( - 'errors', - array_merge_recursive( - $session->get('errors', []), - ['validation' => $e->getValidator()->getErrors()] - ) + $errors = array_merge_recursive( + $session->get('errors', []), + ['validation' => $e->getValidator()->getErrors()] ); + $session->set('errors', $errors); $session->set('form-data', Arr::except($request->request->all(), $this->formIgnore)); } From f8e1f8508957dfb2f4db1485f3e17358f9a72a31 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Fri, 29 Nov 2019 16:51:36 +0100 Subject: [PATCH 3/6] Removed not used {trans} twig token --- composer.json | 1 - src/Renderer/Twig/Extensions/Translation.php | 19 ++------------ .../Twig/Extensions/TranslationTest.php | 25 ++----------------- 3 files changed, 4 insertions(+), 41 deletions(-) diff --git a/composer.json b/composer.json index d76abe94..9f56bab7 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,6 @@ "swiftmailer/swiftmailer": "^6.2", "symfony/http-foundation": "^4.3", "symfony/psr-http-message-bridge": "^1.2", - "twig/extensions": "^1.5", "twig/twig": "~2.6.0", "vlucas/phpdotenv": "^3.3" }, diff --git a/src/Renderer/Twig/Extensions/Translation.php b/src/Renderer/Twig/Extensions/Translation.php index 3e6f30b4..929310a1 100644 --- a/src/Renderer/Twig/Extensions/Translation.php +++ b/src/Renderer/Twig/Extensions/Translation.php @@ -4,27 +4,20 @@ namespace Engelsystem\Renderer\Twig\Extensions; use Engelsystem\Helpers\Translation\Translator; use Twig_Extension as TwigExtension; -use Twig_Extensions_TokenParser_Trans as TranslationTokenParser; use Twig_Filter as TwigFilter; use Twig_Function as TwigFunction; -use Twig_TokenParserInterface as TwigTokenParser; class Translation extends TwigExtension { /** @var Translator */ protected $translator; - /** @var TranslationTokenParser */ - protected $tokenParser; - /** - * @param Translator $translator - * @param TranslationTokenParser $tokenParser + * @param Translator $translator */ - public function __construct(Translator $translator, TranslationTokenParser $tokenParser) + public function __construct(Translator $translator) { $this->translator = $translator; - $this->tokenParser = $tokenParser; } /** @@ -47,12 +40,4 @@ class Translation extends TwigExtension new TwigFunction('_e', [$this->translator, 'translatePlural']), ]; } - - /** - * @return TwigTokenParser[] - */ - public function getTokenParsers() - { - return [$this->tokenParser]; - } } diff --git a/tests/Unit/Renderer/Twig/Extensions/TranslationTest.php b/tests/Unit/Renderer/Twig/Extensions/TranslationTest.php index 0b055c44..3b4b05c6 100644 --- a/tests/Unit/Renderer/Twig/Extensions/TranslationTest.php +++ b/tests/Unit/Renderer/Twig/Extensions/TranslationTest.php @@ -5,7 +5,6 @@ namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions; use Engelsystem\Helpers\Translation\Translator; use Engelsystem\Renderer\Twig\Extensions\Translation; use PHPUnit\Framework\MockObject\MockObject; -use Twig_Extensions_TokenParser_Trans as TranslationTokenParser; class TranslationTest extends ExtensionTest { @@ -17,10 +16,8 @@ class TranslationTest extends ExtensionTest { /** @var Translator|MockObject $translator */ $translator = $this->createMock(Translator::class); - /** @var TranslationTokenParser|MockObject $parser */ - $parser = $this->createMock(TranslationTokenParser::class); - $extension = new Translation($translator, $parser); + $extension = new Translation($translator); $filters = $extension->getFilters(); $this->assertExtensionExists('trans', [$translator, 'translate'], $filters); @@ -33,29 +30,11 @@ class TranslationTest extends ExtensionTest { /** @var Translator|MockObject $translator */ $translator = $this->createMock(Translator::class); - /** @var TranslationTokenParser|MockObject $parser */ - $parser = $this->createMock(TranslationTokenParser::class); - $extension = new Translation($translator, $parser); + $extension = new Translation($translator); $functions = $extension->getFunctions(); $this->assertExtensionExists('__', [$translator, 'translate'], $functions); $this->assertExtensionExists('_e', [$translator, 'translatePlural'], $functions); } - - /** - * @covers \Engelsystem\Renderer\Twig\Extensions\Translation::getTokenParsers - */ - public function testGetTokenParsers() - { - /** @var Translator|MockObject $translator */ - $translator = $this->createMock(Translator::class); - /** @var TranslationTokenParser|MockObject $parser */ - $parser = $this->createMock(TranslationTokenParser::class); - - $extension = new Translation($translator, $parser); - $tokenParsers = $extension->getTokenParsers(); - - $this->assertTokenParserExists($parser, $tokenParsers); - } } From 15e6740e12df3fa53c4b0f3e85e3d91590f0ef60 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sat, 16 Mar 2019 22:02:36 +0100 Subject: [PATCH 4/6] Twig update to > 2.11: Fixed namespaces, warnings and cleanup --- composer.json | 2 +- resources/views/layouts/parts/navbar.twig | 12 +++++------- resources/views/pages/login.twig | 2 +- src/Middleware/ErrorHandler.php | 2 +- src/Renderer/Twig/Extensions/Assets.php | 4 ++-- src/Renderer/Twig/Extensions/Authentication.php | 4 ++-- src/Renderer/Twig/Extensions/Config.php | 4 ++-- src/Renderer/Twig/Extensions/Csrf.php | 4 ++-- src/Renderer/Twig/Extensions/Globals.php | 4 ++-- src/Renderer/Twig/Extensions/Legacy.php | 4 ++-- src/Renderer/Twig/Extensions/Markdown.php | 4 ++-- src/Renderer/Twig/Extensions/Session.php | 4 ++-- src/Renderer/Twig/Extensions/Translation.php | 6 +++--- src/Renderer/Twig/Extensions/Url.php | 4 ++-- src/Renderer/TwigEngine.php | 8 ++++---- src/Renderer/TwigLoader.php | 8 ++++---- src/Renderer/TwigServiceProvider.php | 6 +++--- tests/Unit/Middleware/ErrorHandlerTest.php | 2 +- .../Unit/Renderer/Twig/Extensions/ExtensionTest.php | 4 ++-- tests/Unit/Renderer/TwigEngineTest.php | 4 ++-- tests/Unit/Renderer/TwigServiceProviderTest.php | 8 ++++---- 21 files changed, 49 insertions(+), 51 deletions(-) diff --git a/composer.json b/composer.json index 9f56bab7..2beeeb68 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ "swiftmailer/swiftmailer": "^6.2", "symfony/http-foundation": "^4.3", "symfony/psr-http-message-bridge": "^1.2", - "twig/twig": "~2.6.0", + "twig/twig": "^2.11", "vlucas/phpdotenv": "^3.3" }, "require-dev": { diff --git a/resources/views/layouts/parts/navbar.twig b/resources/views/layouts/parts/navbar.twig index 0b2eee63..9045601b 100644 --- a/resources/views/layouts/parts/navbar.twig +++ b/resources/views/layouts/parts/navbar.twig @@ -1,5 +1,3 @@ -{% import _self as elements %} - {% macro toolbar_item(label, link, active_page, icon) %} @@ -36,23 +34,23 @@