summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2019-11-30 15:37:48 +0100
committerGitHub <noreply@github.com>2019-11-30 15:37:48 +0100
commita18c7d13fcae0af77cdaef1947f2160cbf1dc56a (patch)
tree98633eb27bc514e51643766c0c4c45fc5cecfdd3
parent14f8d208b817d8d7dccebdb5f7a6ada2bcb9d5f4 (diff)
parente80fb54522c307afec3d8bb474a47dd9d2d5da64 (diff)
Merge pull request #682 from MyIgel/php7.4
PHP 7.4 compatibility, PHP min version 7.2, Twig 3
-rw-r--r--README.md10
-rw-r--r--composer.json5
-rw-r--r--resources/views/layouts/parts/navbar.twig12
-rw-r--r--resources/views/pages/login.twig2
-rw-r--r--src/Config/ConfigServiceProvider.php5
-rw-r--r--src/Controllers/Metrics/MetricsEngine.php2
-rw-r--r--src/Helpers/Authenticator.php16
-rw-r--r--src/Middleware/ErrorHandler.php12
-rw-r--r--src/Renderer/Engine.php2
-rw-r--r--src/Renderer/EngineInterface.php2
-rw-r--r--src/Renderer/Renderer.php4
-rw-r--r--src/Renderer/Twig/Extensions/Assets.php10
-rw-r--r--src/Renderer/Twig/Extensions/Authentication.php10
-rw-r--r--src/Renderer/Twig/Extensions/Config.php6
-rw-r--r--src/Renderer/Twig/Extensions/Csrf.php10
-rw-r--r--src/Renderer/Twig/Extensions/Globals.php6
-rw-r--r--src/Renderer/Twig/Extensions/Legacy.php8
-rw-r--r--src/Renderer/Twig/Extensions/Markdown.php6
-rw-r--r--src/Renderer/Twig/Extensions/Session.php6
-rw-r--r--src/Renderer/Twig/Extensions/Translation.php29
-rw-r--r--src/Renderer/Twig/Extensions/Url.php10
-rw-r--r--src/Renderer/TwigEngine.php8
-rw-r--r--src/Renderer/TwigLoader.php10
-rw-r--r--src/Renderer/TwigServiceProvider.php8
-rw-r--r--tests/Unit/Middleware/ErrorHandlerTest.php2
-rw-r--r--tests/Unit/Renderer/Twig/Extensions/ExtensionTest.php4
-rw-r--r--tests/Unit/Renderer/Twig/Extensions/TranslationTest.php25
-rw-r--r--tests/Unit/Renderer/TwigEngineTest.php4
-rw-r--r--tests/Unit/Renderer/TwigServiceProviderTest.php21
29 files changed, 109 insertions, 146 deletions
diff --git a/README.md b/README.md
index c5f3ac86..6333d245 100644
--- a/README.md
+++ b/README.md
@@ -11,7 +11,7 @@ To report bugs use [engelsystem/issues](https://github.com/engelsystem/engelsyst
## Installation
### Requirements
- * PHP >= 7.1
+ * PHP >= 7.2
* Required modules:
* dom
* json
@@ -150,7 +150,7 @@ docker-compose up
Run these commands once initially and then as required after changes
-```
+```bash
# Install composer dependencies
docker exec -it engelsystem_dev_es_workspace_1 composer i
@@ -169,7 +169,7 @@ docker exec -it engelsystem_dev_es_workspace_1 bin/migrate
While developing you may use the watch mode to rebuild the system on changes
-```
+```bash
# Run a front-end build
docker exec -it engelsystem_dev_es_workspace_1 yarn build:watch
```
@@ -199,10 +199,10 @@ We use gettext. You may use POEdit to extract new texts from the sourcecode. Ple
### Code style
Please ensure that your pull requests follow the [PSR-12](https://www.php-fig.org/psr/psr-12/) coding style guide.
You can check that by running
-```php
+```bash
composer run phpcs
```
You may auto fix reported issues by running
-```php
+```bash
composer run phpcbf
```
diff --git a/composer.json b/composer.json
index d76abe94..0af3b2a6 100644
--- a/composer.json
+++ b/composer.json
@@ -18,7 +18,7 @@
"phpcbf": "phpcbf -p"
},
"require": {
- "php": ">=7.1.0",
+ "php": ">=7.2.0",
"ext-json": "*",
"ext-libxml": "*",
"ext-mbstring": "*",
@@ -40,8 +40,7 @@
"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",
+ "twig/twig": "^3.0",
"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) %}
<li{% if page() == active_page %} class="active"{% endif %}>
<a href="{{ link }}">
@@ -36,23 +34,23 @@
<ul class="nav navbar-nav navbar-right">
{% if is_user() %}
- {{ elements.toolbar_item(menuUserShiftState(user), url('shifts', {'action': 'next'}), '', 'glyphicon-time') }}
+ {{ _self.toolbar_item(menuUserShiftState(user), url('shifts', {'action': 'next'}), '', 'glyphicon-time') }}
{% elseif has_permission_to('register') and config('registration_enabled') %}
- {{ elements.toolbar_item(__('Register'), url('register'), 'register', 'glyphicon-plus') }}
+ {{ _self.toolbar_item(__('Register'), url('register'), 'register', 'glyphicon-plus') }}
{% endif %}
{% if has_permission_to('login') %}
- {{ elements.toolbar_item(__('Login'), url('login'), 'login', 'glyphicon-log-in') }}
+ {{ _self.toolbar_item(__('Login'), url('login'), 'login', 'glyphicon-log-in') }}
{% endif %}
{% if is_user() and has_permission_to('user_messages') %}
- {{ elements.toolbar_item(menuUserMessages(), url('user-messages'), 'user-messages', 'glyphicon-envelope') }}
+ {{ _self.toolbar_item(menuUserMessages(), url('user-messages'), 'user-messages', 'glyphicon-envelope') }}
{% endif %}
{{ menuUserHints() }}
{% if has_permission_to('user_myshifts') %}
- {{ elements.toolbar_item(user.name, url('users', {'action': 'view'}), 'users', 'icon icon-icon_angel') }}
+ {{ _self.toolbar_item(user.name, url('users', {'action': 'view'}), 'users', 'icon icon-icon_angel') }}
{% endif %}
<li class="dropdown">
diff --git a/resources/views/pages/login.twig b/resources/views/pages/login.twig
index d8a9bd4e..fdb5b116 100644
--- a/resources/views/pages/login.twig
+++ b/resources/views/pages/login.twig
@@ -17,7 +17,7 @@
(__('Event starts')): config('event_start'),
(__('Event ends')): config('event_end'),
(__('Teardown ends')): config('teardown_end')
- } if date %}
+ } | filter(date => date) %}
{% if date > date() %}
<div class="col-sm-3 text-center hidden-xs">
<h4>{{ name }}</h4>
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/Controllers/Metrics/MetricsEngine.php b/src/Controllers/Metrics/MetricsEngine.php
index 8301e388..375bb096 100644
--- a/src/Controllers/Metrics/MetricsEngine.php
+++ b/src/Controllers/Metrics/MetricsEngine.php
@@ -142,7 +142,7 @@ class MetricsEngine implements EngineInterface
* @param string|mixed[] $key
* @param mixed $value
*/
- public function share($key, $value = null)
+ public function share($key, $value = null): void
{
}
}
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;
}
diff --git a/src/Middleware/ErrorHandler.php b/src/Middleware/ErrorHandler.php
index 65e2e609..46e6e5a8 100644
--- a/src/Middleware/ErrorHandler.php
+++ b/src/Middleware/ErrorHandler.php
@@ -11,7 +11,7 @@ use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
-use Twig_LoaderInterface as TwigLoader;
+use Twig\Loader\LoaderInterface as TwigLoader;
class ErrorHandler implements MiddlewareInterface
{
@@ -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));
}
diff --git a/src/Renderer/Engine.php b/src/Renderer/Engine.php
index 60f1d686..e2ff23f2 100644
--- a/src/Renderer/Engine.php
+++ b/src/Renderer/Engine.php
@@ -11,7 +11,7 @@ abstract class Engine implements EngineInterface
* @param mixed[]|string $key
* @param null $value
*/
- public function share($key, $value = null)
+ public function share($key, $value = null): void
{
if (!is_array($key)) {
$key = [$key => $value];
diff --git a/src/Renderer/EngineInterface.php b/src/Renderer/EngineInterface.php
index 3bce9c02..dd713029 100644
--- a/src/Renderer/EngineInterface.php
+++ b/src/Renderer/EngineInterface.php
@@ -23,5 +23,5 @@ interface EngineInterface
* @param string|mixed[] $key
* @param mixed $value
*/
- public function share($key, $value = null);
+ public function share($key, $value = null): void;
}
diff --git a/src/Renderer/Renderer.php b/src/Renderer/Renderer.php
index de31ca74..ccda6881 100644
--- a/src/Renderer/Renderer.php
+++ b/src/Renderer/Renderer.php
@@ -18,7 +18,7 @@ class Renderer
* @param mixed[] $data
* @return string
*/
- public function render($template, $data = [])
+ public function render(string $template, array $data = []): string
{
foreach ($this->renderer as $renderer) {
if (!$renderer->canRender($template)) {
@@ -40,7 +40,7 @@ class Renderer
*
* @param EngineInterface $renderer
*/
- public function addRenderer(EngineInterface $renderer)
+ public function addRenderer(EngineInterface $renderer): void
{
$this->renderer[] = $renderer;
}
diff --git a/src/Renderer/Twig/Extensions/Assets.php b/src/Renderer/Twig/Extensions/Assets.php
index 2cdfb0fd..04d6c9c8 100644
--- a/src/Renderer/Twig/Extensions/Assets.php
+++ b/src/Renderer/Twig/Extensions/Assets.php
@@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions;
use Engelsystem\Http\UrlGenerator;
-use Twig_Extension as TwigExtension;
-use Twig_Function as TwigFunction;
+use Twig\Extension\AbstractExtension as TwigExtension;
+use Twig\TwigFunction;
class Assets extends TwigExtension
{
@@ -22,7 +22,7 @@ class Assets extends TwigExtension
/**
* @return TwigFunction[]
*/
- public function getFunctions()
+ public function getFunctions(): array
{
return [
new TwigFunction('asset', [$this, 'getAsset']),
@@ -31,9 +31,9 @@ class Assets extends TwigExtension
/**
* @param string $path
- * @return UrlGenerator|string
+ * @return string
*/
- public function getAsset($path)
+ public function getAsset(string $path): string
{
$path = ltrim($path, '/');
diff --git a/src/Renderer/Twig/Extensions/Authentication.php b/src/Renderer/Twig/Extensions/Authentication.php
index 538526da..061a9018 100644
--- a/src/Renderer/Twig/Extensions/Authentication.php
+++ b/src/Renderer/Twig/Extensions/Authentication.php
@@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions;
use Engelsystem\Helpers\Authenticator;
-use Twig_Extension as TwigExtension;
-use Twig_Function as TwigFunction;
+use Twig\Extension\AbstractExtension as TwigExtension;
+use Twig\TwigFunction;
class Authentication extends TwigExtension
{
@@ -22,7 +22,7 @@ class Authentication extends TwigExtension
/**
* @return TwigFunction[]
*/
- public function getFunctions()
+ public function getFunctions(): array
{
return [
new TwigFunction('is_user', [$this, 'isAuthenticated']),
@@ -34,7 +34,7 @@ class Authentication extends TwigExtension
/**
* @return bool
*/
- public function isAuthenticated()
+ public function isAuthenticated(): bool
{
return (bool)$this->auth->user();
}
@@ -42,7 +42,7 @@ class Authentication extends TwigExtension
/**
* @return bool
*/
- public function isGuest()
+ public function isGuest(): bool
{
return !$this->isAuthenticated();
}
diff --git a/src/Renderer/Twig/Extensions/Config.php b/src/Renderer/Twig/Extensions/Config.php
index dbbe93e7..da106957 100644
--- a/src/Renderer/Twig/Extensions/Config.php
+++ b/src/Renderer/Twig/Extensions/Config.php
@@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions;
use Engelsystem\Config\Config as EngelsystemConfig;
-use Twig_Extension as TwigExtension;
-use Twig_Function as TwigFunction;
+use Twig\Extension\AbstractExtension as TwigExtension;
+use Twig\TwigFunction;
class Config extends TwigExtension
{
@@ -22,7 +22,7 @@ class Config extends TwigExtension
/**
* @return TwigFunction[]
*/
- public function getFunctions()
+ public function getFunctions(): array
{
return [
new TwigFunction('config', [$this->config, 'get']),
diff --git a/src/Renderer/Twig/Extensions/Csrf.php b/src/Renderer/Twig/Extensions/Csrf.php
index 9f77df80..fee1c1f9 100644
--- a/src/Renderer/Twig/Extensions/Csrf.php
+++ b/src/Renderer/Twig/Extensions/Csrf.php
@@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
-use Twig_Extension as TwigExtension;
-use Twig_Function as TwigFunction;
+use Twig\Extension\AbstractExtension as TwigExtension;
+use Twig\TwigFunction;
class Csrf extends TwigExtension
{
@@ -22,7 +22,7 @@ class Csrf extends TwigExtension
/**
* @return TwigFunction[]
*/
- public function getFunctions()
+ public function getFunctions(): array
{
return [
new TwigFunction('csrf', [$this, 'getCsrfField'], ['is_safe' => ['html']]),
@@ -33,7 +33,7 @@ class Csrf extends TwigExtension
/**
* @return string
*/
- public function getCsrfField()
+ public function getCsrfField(): string
{
return sprintf('<input type="hidden" name="_token" value="%s">', $this->getCsrfToken());
}
@@ -41,7 +41,7 @@ class Csrf extends TwigExtension
/**
* @return string
*/
- public function getCsrfToken()
+ public function getCsrfToken(): string
{
return $this->session->get('_token');
}
diff --git a/src/Renderer/Twig/Extensions/Globals.php b/src/Renderer/Twig/Extensions/Globals.php
index ef29a819..a809682c 100644
--- a/src/Renderer/Twig/Extensions/Globals.php
+++ b/src/Renderer/Twig/Extensions/Globals.php
@@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions;
use Engelsystem\Helpers\Authenticator;
-use Twig_Extension as TwigExtension;
-use Twig_Extension_GlobalsInterface as GlobalsInterface;
+use Twig\Extension\AbstractExtension as TwigExtension;
+use Twig\Extension\GlobalsInterface as GlobalsInterface;
class Globals extends TwigExtension implements GlobalsInterface
{
@@ -24,7 +24,7 @@ class Globals extends TwigExtension implements GlobalsInterface
*
* @return array An array of global variables
*/
- public function getGlobals()
+ public function getGlobals(): array
{
$user = $this->auth->user();
diff --git a/src/Renderer/Twig/Extensions/Legacy.php b/src/Renderer/Twig/Extensions/Legacy.php
index 55c095fc..dc0c4775 100644
--- a/src/Renderer/Twig/Extensions/Legacy.php
+++ b/src/Renderer/Twig/Extensions/Legacy.php
@@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions;
use Engelsystem\Http\Request;
-use Twig_Extension as TwigExtension;
-use Twig_Function as TwigFunction;
+use Twig\Extension\AbstractExtension as TwigExtension;
+use Twig\TwigFunction;
class Legacy extends TwigExtension
{
@@ -22,7 +22,7 @@ class Legacy extends TwigExtension
/**
* @return TwigFunction[]
*/
- public function getFunctions()
+ public function getFunctions(): array
{
$isSafeHtml = ['is_safe' => ['html']];
return [
@@ -39,7 +39,7 @@ class Legacy extends TwigExtension
/**
* @return string
*/
- public function getPage()
+ public function getPage(): string
{
if ($this->request->has('p')) {
return $this->request->get('p');
diff --git a/src/Renderer/Twig/Extensions/Markdown.php b/src/Renderer/Twig/Extensions/Markdown.php
index 293efe91..c23a0031 100644
--- a/src/Renderer/Twig/Extensions/Markdown.php
+++ b/src/Renderer/Twig/Extensions/Markdown.php
@@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions;
use Parsedown;
-use Twig_Extension as TwigExtension;
-use Twig_Filter as TwigFilter;
+use Twig\Extension\AbstractExtension as TwigExtension;
+use Twig\TwigFilter;
class Markdown extends TwigExtension
{
@@ -36,7 +36,7 @@ class Markdown extends TwigExtension
* @param string $text
* @return string
*/
- public function render($text): string
+ public function render(string $text): string
{
return $this->renderer->text(htmlspecialchars($text));
}
diff --git a/src/Renderer/Twig/Extensions/Session.php b/src/Renderer/Twig/Extensions/Session.php
index 4690f701..77b5b55a 100644
--- a/src/Renderer/Twig/Extensions/Session.php
+++ b/src/Renderer/Twig/Extensions/Session.php
@@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions;
use Symfony\Component\HttpFoundation\Session\Session as SymfonySession;
-use Twig_Extension as TwigExtension;
-use Twig_Function as TwigFunction;
+use Twig\Extension\AbstractExtension as TwigExtension;
+use Twig\TwigFunction;
class Session extends TwigExtension
{
@@ -22,7 +22,7 @@ class Session extends TwigExtension
/**
* @return TwigFunction[]
*/
- public function getFunctions()
+ public function getFunctions(): array
{
return [
new TwigFunction('session_get', [$this->session, 'get']),
diff --git a/src/Renderer/Twig/Extensions/Translation.php b/src/Renderer/Twig/Extensions/Translation.php
index 3e6f30b4..fff3bfa9 100644
--- a/src/Renderer/Twig/Extensions/Translation.php
+++ b/src/Renderer/Twig/Extensions/Translation.php
@@ -3,34 +3,27 @@
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;
+use Twig\Extension\AbstractExtension as TwigExtension;
+use Twig\TwigFilter;
+use Twig\TwigFunction;
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;
}
/**
* @return array
*/
- public function getFilters()
+ public function getFilters(): array
{
return [
new TwigFilter('trans', [$this->translator, 'translate']),
@@ -40,19 +33,11 @@ class Translation extends TwigExtension
/**
* @return TwigFunction[]
*/
- public function getFunctions()
+ public function getFunctions(): array
{
return [
new TwigFunction('__', [$this->translator, 'translate']),
new TwigFunction('_e', [$this->translator, 'translatePlural']),
];
}
-
- /**
- * @return TwigTokenParser[]
- */
- public function getTokenParsers()
- {
- return [$this->tokenParser];
- }
}
diff --git a/src/Renderer/Twig/Extensions/Url.php b/src/Renderer/Twig/Extensions/Url.php
index 62e59782..17fd6ff0 100644
--- a/src/Renderer/Twig/Extensions/Url.php
+++ b/src/Renderer/Twig/Extensions/Url.php
@@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions;
use Engelsystem\Http\UrlGenerator;
-use Twig_Extension as TwigExtension;
-use Twig_Function as TwigFunction;
+use Twig\Extension\AbstractExtension as TwigExtension;
+use Twig\TwigFunction;
class Url extends TwigExtension
{
@@ -22,7 +22,7 @@ class Url extends TwigExtension
/**
* @return TwigFunction[]
*/
- public function getFunctions()
+ public function getFunctions(): array
{
return [
new TwigFunction('url', [$this, 'getUrl']),
@@ -32,9 +32,9 @@ class Url extends TwigExtension
/**
* @param string $path
* @param array $parameters
- * @return UrlGenerator|string
+ * @return string
*/
- public function getUrl($path, $parameters = [])
+ public function getUrl(string $path, array $parameters = []): string
{
$path = str_replace('_', '-', $path);
diff --git a/src/Renderer/TwigEngine.php b/src/Renderer/TwigEngine.php
index aa51a177..2c77e54f 100644
--- a/src/Renderer/TwigEngine.php
+++ b/src/Renderer/TwigEngine.php
@@ -2,10 +2,10 @@
namespace Engelsystem\Renderer;
-use Twig_Environment as Twig;
-use Twig_Error_Loader as LoaderError;
-use Twig_Error_Runtime as RuntimeError;
-use Twig_Error_Syntax as SyntaxError;
+use Twig\Environment as Twig;
+use Twig\Error\LoaderError as LoaderError;
+use Twig\Error\RuntimeError as RuntimeError;
+use Twig\Error\SyntaxError as SyntaxError;
class TwigEngine extends Engine
{
diff --git a/src/Renderer/TwigLoader.php b/src/Renderer/TwigLoader.php
index f20a8764..1bcbbd71 100644
--- a/src/Renderer/TwigLoader.php
+++ b/src/Renderer/TwigLoader.php
@@ -2,18 +2,18 @@
namespace Engelsystem\Renderer;
-use Twig_Error_Loader;
-use Twig_Loader_Filesystem as FilesystemLoader;
+use Twig\Error\LoaderError as ErrorLoader;
+use Twig\Loader\FilesystemLoader as FilesystemLoader;
class TwigLoader extends FilesystemLoader
{
/**
* @param string $name
* @param bool $throw
- * @return false|string
- * @throws Twig_Error_Loader
+ * @return string|null
+ * @throws ErrorLoader
*/
- public function findTemplate($name, $throw = true)
+ public function findTemplate(string $name, bool $throw = true): ?string
{
$extension = '.twig';
$extensionLength = mb_strlen($extension);
diff --git a/src/Renderer/TwigServiceProvider.php b/src/Renderer/TwigServiceProvider.php
index 6cd885fd..d4e4a939 100644
--- a/src/Renderer/TwigServiceProvider.php
+++ b/src/Renderer/TwigServiceProvider.php
@@ -14,9 +14,9 @@ use Engelsystem\Renderer\Twig\Extensions\Markdown;
use Engelsystem\Renderer\Twig\Extensions\Session;
use Engelsystem\Renderer\Twig\Extensions\Translation;
use Engelsystem\Renderer\Twig\Extensions\Url;
-use Twig_Environment as Twig;
-use Twig_Extension_Core as TwigCore;
-use Twig_LoaderInterface as TwigLoaderInterface;
+use Twig\Environment as Twig;
+use Twig\Extension\CoreExtension as TwigCore;
+use Twig\Loader\LoaderInterface as TwigLoaderInterface;
class TwigServiceProvider extends ServiceProvider
{
@@ -95,7 +95,7 @@ class TwigServiceProvider extends ServiceProvider
* @param string $class
* @param string $alias
*/
- protected function registerTwigExtensions($class, $alias)
+ protected function registerTwigExtensions(string $class, string $alias)
{
$alias = 'twig.extension.' . $alias;
diff --git a/tests/Unit/Middleware/ErrorHandlerTest.php b/tests/Unit/Middleware/ErrorHandlerTest.php
index 6ae604e0..ef2f7be0 100644
--- a/tests/Unit/Middleware/ErrorHandlerTest.php
+++ b/tests/Unit/Middleware/ErrorHandlerTest.php
@@ -19,7 +19,7 @@ use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
-use Twig_LoaderInterface as TwigLoader;
+use Twig\Loader\LoaderInterface as TwigLoader;
class ErrorHandlerTest extends TestCase
{
diff --git a/tests/Unit/Renderer/Twig/Extensions/ExtensionTest.php b/tests/Unit/Renderer/Twig/Extensions/ExtensionTest.php
index 921a06a3..3d7cea12 100644
--- a/tests/Unit/Renderer/Twig/Extensions/ExtensionTest.php
+++ b/tests/Unit/Renderer/Twig/Extensions/ExtensionTest.php
@@ -6,8 +6,8 @@ use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use Exception;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-use Twig_Function as TwigFunction;
-use Twig_Node as TwigNode;
+use Twig\TwigFunction;
+use Twig\Node\Node as TwigNode;
abstract class ExtensionTest extends TestCase
{
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);
- }
}
diff --git a/tests/Unit/Renderer/TwigEngineTest.php b/tests/Unit/Renderer/TwigEngineTest.php
index 5e5e59d9..8798d0ff 100644
--- a/tests/Unit/Renderer/TwigEngineTest.php
+++ b/tests/Unit/Renderer/TwigEngineTest.php
@@ -5,8 +5,8 @@ namespace Engelsystem\Test\Unit\Renderer;
use Engelsystem\Renderer\TwigEngine;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-use Twig_Environment as Twig;
-use Twig_LoaderInterface as LoaderInterface;
+use Twig\Environment as Twig;
+use Twig\Loader\LoaderInterface as LoaderInterface;
class TwigEngineTest extends TestCase
{
diff --git a/tests/Unit/Renderer/TwigServiceProviderTest.php b/tests/Unit/Renderer/TwigServiceProviderTest.php
index cd071349..3336e015 100644
--- a/tests/Unit/Renderer/TwigServiceProviderTest.php
+++ b/tests/Unit/Renderer/TwigServiceProviderTest.php
@@ -11,10 +11,11 @@ use PHPUnit\Framework\MockObject\MockObject;
use ReflectionClass as Reflection;
use ReflectionException;
use stdClass;
-use Twig_Environment as Twig;
-use Twig_Extension_Core as TwigCore;
-use Twig_ExtensionInterface as ExtensionInterface;
-use Twig_LoaderInterface as TwigLoaderInterface;
+use Twig\Environment as Twig;
+use Twig\Extension\AbstractExtension;
+use Twig\Extension\CoreExtension as TwigCore;
+use Twig\Extension\ExtensionInterface as ExtensionInterface;
+use Twig\Loader\LoaderInterface as TwigLoaderInterface;
class TwigServiceProviderTest extends ServiceProviderTest
{
@@ -103,9 +104,15 @@ class TwigServiceProviderTest extends ServiceProviderTest
/** @var Config|MockObject $config */
$config = $this->createMock(Config::class);
/** @var TwigCore|MockObject $twigCore */
- $twigCore = $this->getMockBuilder(stdClass::class)
- ->addMethods(['setTimezone'])
- ->getMock();
+ $twigCore = $this->getMockForAbstractClass(
+ AbstractExtension::class,
+ [],
+ '',
+ true,
+ true,
+ true,
+ ['setTimezone']
+ );
$app = $this->getApp(['make', 'instance', 'tag', 'get']);