Twig update to 3.0.0 and Renderer type hinting

main
Igor Scheller 5 years ago
parent 15e6740e12
commit 577c052aff

@ -40,7 +40,7 @@
"swiftmailer/swiftmailer": "^6.2", "swiftmailer/swiftmailer": "^6.2",
"symfony/http-foundation": "^4.3", "symfony/http-foundation": "^4.3",
"symfony/psr-http-message-bridge": "^1.2", "symfony/psr-http-message-bridge": "^1.2",
"twig/twig": "^2.11", "twig/twig": "^3.0",
"vlucas/phpdotenv": "^3.3" "vlucas/phpdotenv": "^3.3"
}, },
"require-dev": { "require-dev": {

@ -142,7 +142,7 @@ class MetricsEngine implements EngineInterface
* @param string|mixed[] $key * @param string|mixed[] $key
* @param mixed $value * @param mixed $value
*/ */
public function share($key, $value = null) public function share($key, $value = null): void
{ {
} }
} }

@ -11,7 +11,7 @@ abstract class Engine implements EngineInterface
* @param mixed[]|string $key * @param mixed[]|string $key
* @param null $value * @param null $value
*/ */
public function share($key, $value = null) public function share($key, $value = null): void
{ {
if (!is_array($key)) { if (!is_array($key)) {
$key = [$key => $value]; $key = [$key => $value];

@ -23,5 +23,5 @@ interface EngineInterface
* @param string|mixed[] $key * @param string|mixed[] $key
* @param mixed $value * @param mixed $value
*/ */
public function share($key, $value = null); public function share($key, $value = null): void;
} }

@ -18,7 +18,7 @@ class Renderer
* @param mixed[] $data * @param mixed[] $data
* @return string * @return string
*/ */
public function render($template, $data = []) public function render(string $template, array $data = []): string
{ {
foreach ($this->renderer as $renderer) { foreach ($this->renderer as $renderer) {
if (!$renderer->canRender($template)) { if (!$renderer->canRender($template)) {
@ -40,7 +40,7 @@ class Renderer
* *
* @param EngineInterface $renderer * @param EngineInterface $renderer
*/ */
public function addRenderer(EngineInterface $renderer) public function addRenderer(EngineInterface $renderer): void
{ {
$this->renderer[] = $renderer; $this->renderer[] = $renderer;
} }

@ -22,7 +22,7 @@ class Assets extends TwigExtension
/** /**
* @return TwigFunction[] * @return TwigFunction[]
*/ */
public function getFunctions() public function getFunctions(): array
{ {
return [ return [
new TwigFunction('asset', [$this, 'getAsset']), new TwigFunction('asset', [$this, 'getAsset']),
@ -31,9 +31,9 @@ class Assets extends TwigExtension
/** /**
* @param string $path * @param string $path
* @return UrlGenerator|string * @return string
*/ */
public function getAsset($path) public function getAsset(string $path): string
{ {
$path = ltrim($path, '/'); $path = ltrim($path, '/');

@ -22,7 +22,7 @@ class Authentication extends TwigExtension
/** /**
* @return TwigFunction[] * @return TwigFunction[]
*/ */
public function getFunctions() public function getFunctions(): array
{ {
return [ return [
new TwigFunction('is_user', [$this, 'isAuthenticated']), new TwigFunction('is_user', [$this, 'isAuthenticated']),
@ -34,7 +34,7 @@ class Authentication extends TwigExtension
/** /**
* @return bool * @return bool
*/ */
public function isAuthenticated() public function isAuthenticated(): bool
{ {
return (bool)$this->auth->user(); return (bool)$this->auth->user();
} }
@ -42,7 +42,7 @@ class Authentication extends TwigExtension
/** /**
* @return bool * @return bool
*/ */
public function isGuest() public function isGuest(): bool
{ {
return !$this->isAuthenticated(); return !$this->isAuthenticated();
} }

@ -22,7 +22,7 @@ class Config extends TwigExtension
/** /**
* @return TwigFunction[] * @return TwigFunction[]
*/ */
public function getFunctions() public function getFunctions(): array
{ {
return [ return [
new TwigFunction('config', [$this->config, 'get']), new TwigFunction('config', [$this->config, 'get']),

@ -22,7 +22,7 @@ class Csrf extends TwigExtension
/** /**
* @return TwigFunction[] * @return TwigFunction[]
*/ */
public function getFunctions() public function getFunctions(): array
{ {
return [ return [
new TwigFunction('csrf', [$this, 'getCsrfField'], ['is_safe' => ['html']]), new TwigFunction('csrf', [$this, 'getCsrfField'], ['is_safe' => ['html']]),
@ -33,7 +33,7 @@ class Csrf extends TwigExtension
/** /**
* @return string * @return string
*/ */
public function getCsrfField() public function getCsrfField(): string
{ {
return sprintf('<input type="hidden" name="_token" value="%s">', $this->getCsrfToken()); return sprintf('<input type="hidden" name="_token" value="%s">', $this->getCsrfToken());
} }
@ -41,7 +41,7 @@ class Csrf extends TwigExtension
/** /**
* @return string * @return string
*/ */
public function getCsrfToken() public function getCsrfToken(): string
{ {
return $this->session->get('_token'); return $this->session->get('_token');
} }

@ -24,7 +24,7 @@ class Globals extends TwigExtension implements GlobalsInterface
* *
* @return array An array of global variables * @return array An array of global variables
*/ */
public function getGlobals() public function getGlobals(): array
{ {
$user = $this->auth->user(); $user = $this->auth->user();

@ -22,7 +22,7 @@ class Legacy extends TwigExtension
/** /**
* @return TwigFunction[] * @return TwigFunction[]
*/ */
public function getFunctions() public function getFunctions(): array
{ {
$isSafeHtml = ['is_safe' => ['html']]; $isSafeHtml = ['is_safe' => ['html']];
return [ return [
@ -39,7 +39,7 @@ class Legacy extends TwigExtension
/** /**
* @return string * @return string
*/ */
public function getPage() public function getPage(): string
{ {
if ($this->request->has('p')) { if ($this->request->has('p')) {
return $this->request->get('p'); return $this->request->get('p');

@ -36,7 +36,7 @@ class Markdown extends TwigExtension
* @param string $text * @param string $text
* @return string * @return string
*/ */
public function render($text): string public function render(string $text): string
{ {
return $this->renderer->text(htmlspecialchars($text)); return $this->renderer->text(htmlspecialchars($text));
} }

@ -22,7 +22,7 @@ class Session extends TwigExtension
/** /**
* @return TwigFunction[] * @return TwigFunction[]
*/ */
public function getFunctions() public function getFunctions(): array
{ {
return [ return [
new TwigFunction('session_get', [$this->session, 'get']), new TwigFunction('session_get', [$this->session, 'get']),

@ -23,7 +23,7 @@ class Translation extends TwigExtension
/** /**
* @return array * @return array
*/ */
public function getFilters() public function getFilters(): array
{ {
return [ return [
new TwigFilter('trans', [$this->translator, 'translate']), new TwigFilter('trans', [$this->translator, 'translate']),
@ -33,7 +33,7 @@ class Translation extends TwigExtension
/** /**
* @return TwigFunction[] * @return TwigFunction[]
*/ */
public function getFunctions() public function getFunctions(): array
{ {
return [ return [
new TwigFunction('__', [$this->translator, 'translate']), new TwigFunction('__', [$this->translator, 'translate']),

@ -22,7 +22,7 @@ class Url extends TwigExtension
/** /**
* @return TwigFunction[] * @return TwigFunction[]
*/ */
public function getFunctions() public function getFunctions(): array
{ {
return [ return [
new TwigFunction('url', [$this, 'getUrl']), new TwigFunction('url', [$this, 'getUrl']),
@ -32,9 +32,9 @@ class Url extends TwigExtension
/** /**
* @param string $path * @param string $path
* @param array $parameters * @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); $path = str_replace('_', '-', $path);

@ -10,10 +10,10 @@ class TwigLoader extends FilesystemLoader
/** /**
* @param string $name * @param string $name
* @param bool $throw * @param bool $throw
* @return string|false|null * @return string|null
* @throws ErrorLoader * @throws ErrorLoader
*/ */
public function findTemplate($name, $throw = true) public function findTemplate(string $name, bool $throw = true): ?string
{ {
$extension = '.twig'; $extension = '.twig';
$extensionLength = mb_strlen($extension); $extensionLength = mb_strlen($extension);

@ -95,7 +95,7 @@ class TwigServiceProvider extends ServiceProvider
* @param string $class * @param string $class
* @param string $alias * @param string $alias
*/ */
protected function registerTwigExtensions($class, $alias) protected function registerTwigExtensions(string $class, string $alias)
{ {
$alias = 'twig.extension.' . $alias; $alias = 'twig.extension.' . $alias;

@ -12,6 +12,7 @@ use ReflectionClass as Reflection;
use ReflectionException; use ReflectionException;
use stdClass; use stdClass;
use Twig\Environment as Twig; use Twig\Environment as Twig;
use Twig\Extension\AbstractExtension;
use Twig\Extension\CoreExtension as TwigCore; use Twig\Extension\CoreExtension as TwigCore;
use Twig\Extension\ExtensionInterface as ExtensionInterface; use Twig\Extension\ExtensionInterface as ExtensionInterface;
use Twig\Loader\LoaderInterface as TwigLoaderInterface; use Twig\Loader\LoaderInterface as TwigLoaderInterface;
@ -103,9 +104,15 @@ class TwigServiceProviderTest extends ServiceProviderTest
/** @var Config|MockObject $config */ /** @var Config|MockObject $config */
$config = $this->createMock(Config::class); $config = $this->createMock(Config::class);
/** @var TwigCore|MockObject $twigCore */ /** @var TwigCore|MockObject $twigCore */
$twigCore = $this->getMockBuilder(stdClass::class) $twigCore = $this->getMockForAbstractClass(
->addMethods(['setTimezone']) AbstractExtension::class,
->getMock(); [],
'',
true,
true,
true,
['setTimezone']
);
$app = $this->getApp(['make', 'instance', 'tag', 'get']); $app = $this->getApp(['make', 'instance', 'tag', 'get']);

Loading…
Cancel
Save