Finalized all @final classes.

This commit is contained in:
Alexander M. Turek 2019-08-21 15:47:16 +02:00
parent f30edcab65
commit 44ed90ccae
34 changed files with 88 additions and 355 deletions

View File

@ -19,10 +19,8 @@ use Twig\TwigFunction;
* Twig extension for the Symfony Asset component. * Twig extension for the Symfony Asset component.
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @final
*/ */
class AssetExtension extends AbstractExtension final class AssetExtension extends AbstractExtension
{ {
private $packages; private $packages;
@ -33,8 +31,6 @@ class AssetExtension extends AbstractExtension
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @return TwigFunction[]
*/ */
public function getFunctions(): array public function getFunctions(): array
{ {
@ -49,31 +45,17 @@ class AssetExtension extends AbstractExtension
* *
* If the package used to generate the path is an instance of * If the package used to generate the path is an instance of
* UrlPackage, you will always get a URL and not a path. * UrlPackage, you will always get a URL and not a path.
*
* @return string The public path of the asset
*/ */
public function getAssetUrl(string $path, string $packageName = null) public function getAssetUrl(string $path, string $packageName = null): string
{ {
return $this->packages->getUrl($path, $packageName); return $this->packages->getUrl($path, $packageName);
} }
/** /**
* Returns the version of an asset. * Returns the version of an asset.
*
* @return string The asset version
*/ */
public function getAssetVersion(string $path, string $packageName = null) public function getAssetVersion(string $path, string $packageName = null): string
{ {
return $this->packages->getVersion($path, $packageName); return $this->packages->getVersion($path, $packageName);
} }
/**
* Returns the name of the extension.
*
* @return string The extension name
*/
public function getName()
{
return 'asset';
}
} }

View File

@ -19,10 +19,8 @@ use Twig\TwigFilter;
* Twig extension relate to PHP code and used by the profiler and the default exception templates. * Twig extension relate to PHP code and used by the profiler and the default exception templates.
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @final
*/ */
class CodeExtension extends AbstractExtension final class CodeExtension extends AbstractExtension
{ {
private $fileLinkFormat; private $fileLinkFormat;
private $charset; private $charset;
@ -30,8 +28,6 @@ class CodeExtension extends AbstractExtension
/** /**
* @param string|FileLinkFormatter $fileLinkFormat The format for links to source files * @param string|FileLinkFormatter $fileLinkFormat The format for links to source files
* @param string $projectDir The project directory
* @param string $charset The charset
*/ */
public function __construct($fileLinkFormat, string $projectDir, string $charset) public function __construct($fileLinkFormat, string $projectDir, string $charset)
{ {
@ -42,8 +38,6 @@ class CodeExtension extends AbstractExtension
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @return TwigFilter[]
*/ */
public function getFilters(): array public function getFilters(): array
{ {
@ -61,7 +55,7 @@ class CodeExtension extends AbstractExtension
]; ];
} }
public function abbrClass(string $class) public function abbrClass(string $class): string
{ {
$parts = explode('\\', $class); $parts = explode('\\', $class);
$short = array_pop($parts); $short = array_pop($parts);
@ -69,7 +63,7 @@ class CodeExtension extends AbstractExtension
return sprintf('<abbr title="%s">%s</abbr>', $class, $short); return sprintf('<abbr title="%s">%s</abbr>', $class, $short);
} }
public function abbrMethod(string $method) public function abbrMethod(string $method): string
{ {
if (false !== strpos($method, '::')) { if (false !== strpos($method, '::')) {
list($class, $method) = explode('::', $method, 2); list($class, $method) = explode('::', $method, 2);
@ -85,10 +79,8 @@ class CodeExtension extends AbstractExtension
/** /**
* Formats an array as a string. * Formats an array as a string.
*
* @return string
*/ */
public function formatArgs(array $args) public function formatArgs(array $args): string
{ {
$result = []; $result = [];
foreach ($args as $key => $item) { foreach ($args as $key => $item) {
@ -116,20 +108,16 @@ class CodeExtension extends AbstractExtension
/** /**
* Formats an array as a string. * Formats an array as a string.
*
* @return string
*/ */
public function formatArgsAsText(array $args) public function formatArgsAsText(array $args): string
{ {
return strip_tags($this->formatArgs($args)); return strip_tags($this->formatArgs($args));
} }
/** /**
* Returns an excerpt of a code file around the given line number. * Returns an excerpt of a code file around the given line number.
*
* @return string An HTML string
*/ */
public function fileExcerpt(string $file, int $line, int $srcContext = 3) public function fileExcerpt(string $file, int $line, int $srcContext = 3): ?string
{ {
if (is_file($file) && is_readable($file)) { if (is_file($file) && is_readable($file)) {
// highlight_file could throw warnings // highlight_file could throw warnings
@ -160,10 +148,8 @@ class CodeExtension extends AbstractExtension
/** /**
* Formats a file path. * Formats a file path.
*
* @return string
*/ */
public function formatFile(string $file, int $line, string $text = null) public function formatFile(string $file, int $line, string $text = null): string
{ {
$file = trim($file); $file = trim($file);
@ -211,7 +197,7 @@ class CodeExtension extends AbstractExtension
return null; return null;
} }
public function formatFileFromText(string $text) public function formatFileFromText(string $text): string
{ {
return preg_replace_callback('/in ("|&quot;)?(.+?)\1(?: +(?:on|at))? +line (\d+)/s', function ($match) { return preg_replace_callback('/in ("|&quot;)?(.+?)\1(?: +(?:on|at))? +line (\d+)/s', function ($match) {
return 'in '.$this->formatFile($match[2], $match[3]); return 'in '.$this->formatFile($match[2], $match[3]);
@ -221,7 +207,7 @@ class CodeExtension extends AbstractExtension
/** /**
* @internal * @internal
*/ */
public function formatLogMessage(string $message, array $context) public function formatLogMessage(string $message, array $context): string
{ {
if ($context && false !== strpos($message, '{')) { if ($context && false !== strpos($message, '{')) {
$replacements = []; $replacements = [];
@ -239,15 +225,7 @@ class CodeExtension extends AbstractExtension
return htmlspecialchars($message, ENT_COMPAT | ENT_SUBSTITUTE, $this->charset); return htmlspecialchars($message, ENT_COMPAT | ENT_SUBSTITUTE, $this->charset);
} }
/** protected static function fixCodeMarkup(string $line): string
* {@inheritdoc}
*/
public function getName()
{
return 'code';
}
protected static function fixCodeMarkup(string $line)
{ {
// </span> ending tag from previous line // </span> ending tag from previous line
$opening = strpos($line, '<span'); $opening = strpos($line, '<span');

View File

@ -17,10 +17,8 @@ use Twig\TwigFunction;
/** /**
* @author Christian Flothmann <christian.flothmann@sensiolabs.de> * @author Christian Flothmann <christian.flothmann@sensiolabs.de>
* @author Titouan Galopin <galopintitouan@gmail.com> * @author Titouan Galopin <galopintitouan@gmail.com>
*
* @final
*/ */
class CsrfExtension extends AbstractExtension final class CsrfExtension extends AbstractExtension
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}

View File

@ -16,10 +16,8 @@ use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
/** /**
* @author Christian Flothmann <christian.flothmann@sensiolabs.de> * @author Christian Flothmann <christian.flothmann@sensiolabs.de>
* @author Titouan Galopin <galopintitouan@gmail.com> * @author Titouan Galopin <galopintitouan@gmail.com>
*
* @final
*/ */
class CsrfRuntime final class CsrfRuntime
{ {
private $csrfTokenManager; private $csrfTokenManager;

View File

@ -17,17 +17,14 @@ use Symfony\Component\VarDumper\Dumper\HtmlDumper;
use Twig\Environment; use Twig\Environment;
use Twig\Extension\AbstractExtension; use Twig\Extension\AbstractExtension;
use Twig\Template; use Twig\Template;
use Twig\TokenParser\TokenParserInterface;
use Twig\TwigFunction; use Twig\TwigFunction;
/** /**
* Provides integration of the dump() function with Twig. * Provides integration of the dump() function with Twig.
* *
* @author Nicolas Grekas <p@tchwork.com> * @author Nicolas Grekas <p@tchwork.com>
*
* @final
*/ */
class DumpExtension extends AbstractExtension final class DumpExtension extends AbstractExtension
{ {
private $cloner; private $cloner;
private $dumper; private $dumper;
@ -39,7 +36,7 @@ class DumpExtension extends AbstractExtension
} }
/** /**
* @return TwigFunction[] * {@inheritdoc}
*/ */
public function getFunctions(): array public function getFunctions(): array
{ {
@ -49,19 +46,14 @@ class DumpExtension extends AbstractExtension
} }
/** /**
* @return TokenParserInterface[] * {@inheritdoc}
*/ */
public function getTokenParsers(): array public function getTokenParsers(): array
{ {
return [new DumpTokenParser()]; return [new DumpTokenParser()];
} }
public function getName() public function dump(Environment $env, array $context): ?string
{
return 'dump';
}
public function dump(Environment $env, array $context)
{ {
if (!$env->isDebug()) { if (!$env->isDebug()) {
return null; return null;

View File

@ -19,15 +19,11 @@ use Twig\TwigFunction;
* ExpressionExtension gives a way to create Expressions from a template. * ExpressionExtension gives a way to create Expressions from a template.
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @final
*/ */
class ExpressionExtension extends AbstractExtension final class ExpressionExtension extends AbstractExtension
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @return TwigFunction[]
*/ */
public function getFunctions(): array public function getFunctions(): array
{ {
@ -36,18 +32,8 @@ class ExpressionExtension extends AbstractExtension
]; ];
} }
public function createExpression(string $expression) public function createExpression(string $expression): Expression
{ {
return new Expression($expression); return new Expression($expression);
} }
/**
* Returns the name of the extension.
*
* @return string The extension name
*/
public function getName()
{
return 'expression';
}
} }

View File

@ -15,7 +15,6 @@ use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
use Symfony\Component\Form\ChoiceList\View\ChoiceView; use Symfony\Component\Form\ChoiceList\View\ChoiceView;
use Symfony\Component\Form\FormView; use Symfony\Component\Form\FormView;
use Twig\Extension\AbstractExtension; use Twig\Extension\AbstractExtension;
use Twig\TokenParser\TokenParserInterface;
use Twig\TwigFilter; use Twig\TwigFilter;
use Twig\TwigFunction; use Twig\TwigFunction;
use Twig\TwigTest; use Twig\TwigTest;
@ -25,15 +24,11 @@ use Twig\TwigTest;
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
* @author Bernhard Schussek <bschussek@gmail.com> * @author Bernhard Schussek <bschussek@gmail.com>
*
* @final
*/ */
class FormExtension extends AbstractExtension final class FormExtension extends AbstractExtension
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @return TokenParserInterface[]
*/ */
public function getTokenParsers(): array public function getTokenParsers(): array
{ {
@ -45,8 +40,6 @@ class FormExtension extends AbstractExtension
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @return TwigFunction[]
*/ */
public function getFunctions(): array public function getFunctions(): array
{ {
@ -67,8 +60,6 @@ class FormExtension extends AbstractExtension
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @return TwigFilter[]
*/ */
public function getFilters(): array public function getFilters(): array
{ {
@ -80,8 +71,6 @@ class FormExtension extends AbstractExtension
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @return TwigTest[]
*/ */
public function getTests(): array public function getTests(): array
{ {
@ -90,14 +79,6 @@ class FormExtension extends AbstractExtension
new TwigTest('rootform', 'Symfony\Bridge\Twig\Extension\twig_is_root_form'), new TwigTest('rootform', 'Symfony\Bridge\Twig\Extension\twig_is_root_form'),
]; ];
} }
/**
* {@inheritdoc}
*/
public function getName()
{
return 'form';
}
} }
/** /**
@ -107,11 +88,9 @@ class FormExtension extends AbstractExtension
* *
* @param string|array $selectedValue The selected value to compare * @param string|array $selectedValue The selected value to compare
* *
* @return bool Whether the choice is selected
*
* @see ChoiceView::isSelected() * @see ChoiceView::isSelected()
*/ */
function twig_is_selected_choice(ChoiceView $choice, $selectedValue) function twig_is_selected_choice(ChoiceView $choice, $selectedValue): bool
{ {
if (\is_array($selectedValue)) { if (\is_array($selectedValue)) {
return \in_array($choice->value, $selectedValue, true); return \in_array($choice->value, $selectedValue, true);
@ -123,7 +102,7 @@ function twig_is_selected_choice(ChoiceView $choice, $selectedValue)
/** /**
* @internal * @internal
*/ */
function twig_is_root_form(FormView $formView) function twig_is_root_form(FormView $formView): bool
{ {
return null === $formView->parent; return null === $formView->parent;
} }

View File

@ -20,10 +20,8 @@ use Twig\TwigFunction;
* Twig extension for the Symfony HttpFoundation component. * Twig extension for the Symfony HttpFoundation component.
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @final
*/ */
class HttpFoundationExtension extends AbstractExtension final class HttpFoundationExtension extends AbstractExtension
{ {
private $urlHelper; private $urlHelper;
@ -34,8 +32,6 @@ class HttpFoundationExtension extends AbstractExtension
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @return TwigFunction[]
*/ */
public function getFunctions(): array public function getFunctions(): array
{ {
@ -50,11 +46,9 @@ class HttpFoundationExtension extends AbstractExtension
* *
* This method returns the path unchanged if no request is available. * This method returns the path unchanged if no request is available.
* *
* @return string The absolute URL
*
* @see Request::getUriForPath() * @see Request::getUriForPath()
*/ */
public function generateAbsoluteUrl(string $path) public function generateAbsoluteUrl(string $path): string
{ {
return $this->urlHelper->getAbsoluteUrl($path); return $this->urlHelper->getAbsoluteUrl($path);
} }
@ -64,22 +58,10 @@ class HttpFoundationExtension extends AbstractExtension
* *
* This method returns the path unchanged if no request is available. * This method returns the path unchanged if no request is available.
* *
* @return string The relative path
*
* @see Request::getRelativeUriForPath() * @see Request::getRelativeUriForPath()
*/ */
public function generateRelativePath(string $path) public function generateRelativePath(string $path): string
{ {
return $this->urlHelper->getRelativePath($path); return $this->urlHelper->getRelativePath($path);
} }
/**
* Returns the name of the extension.
*
* @return string The extension name
*/
public function getName()
{
return 'request';
}
} }

View File

@ -19,13 +19,11 @@ use Twig\TwigFunction;
* Provides integration with the HttpKernel component. * Provides integration with the HttpKernel component.
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @final
*/ */
class HttpKernelExtension extends AbstractExtension final class HttpKernelExtension extends AbstractExtension
{ {
/** /**
* @return TwigFunction[] * {@inheritdoc}
*/ */
public function getFunctions(): array public function getFunctions(): array
{ {
@ -36,16 +34,8 @@ class HttpKernelExtension extends AbstractExtension
]; ];
} }
public static function controller(string $controller, array $attributes = [], array $query = []) public static function controller(string $controller, array $attributes = [], array $query = []): ControllerReference
{ {
return new ControllerReference($controller, $attributes, $query); return new ControllerReference($controller, $attributes, $query);
} }
/**
* {@inheritdoc}
*/
public function getName()
{
return 'http_kernel';
}
} }

View File

@ -18,10 +18,8 @@ use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
* Provides integration with the HttpKernel component. * Provides integration with the HttpKernel component.
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @final
*/ */
class HttpKernelRuntime final class HttpKernelRuntime
{ {
private $handler; private $handler;
@ -35,11 +33,9 @@ class HttpKernelRuntime
* *
* @param string|ControllerReference $uri A URI as a string or a ControllerReference instance * @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
* *
* @return string The fragment content
*
* @see FragmentHandler::render() * @see FragmentHandler::render()
*/ */
public function renderFragment($uri, array $options = []) public function renderFragment($uri, array $options = []): string
{ {
$strategy = isset($options['strategy']) ? $options['strategy'] : 'inline'; $strategy = isset($options['strategy']) ? $options['strategy'] : 'inline';
unset($options['strategy']); unset($options['strategy']);
@ -52,11 +48,9 @@ class HttpKernelRuntime
* *
* @param string|ControllerReference $uri A URI as a string or a ControllerReference instance * @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
* *
* @return string The fragment content
*
* @see FragmentHandler::render() * @see FragmentHandler::render()
*/ */
public function renderFragmentStrategy(string $strategy, $uri, array $options = []) public function renderFragmentStrategy(string $strategy, $uri, array $options = []): string
{ {
return $this->handler->render($uri, $strategy, $options); return $this->handler->render($uri, $strategy, $options);
} }

View File

@ -19,10 +19,8 @@ use Twig\TwigFunction;
* LogoutUrlHelper provides generator functions for the logout URL to Twig. * LogoutUrlHelper provides generator functions for the logout URL to Twig.
* *
* @author Jeremy Mikola <jmikola@gmail.com> * @author Jeremy Mikola <jmikola@gmail.com>
*
* @final
*/ */
class LogoutUrlExtension extends AbstractExtension final class LogoutUrlExtension extends AbstractExtension
{ {
private $generator; private $generator;
@ -33,8 +31,6 @@ class LogoutUrlExtension extends AbstractExtension
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @return TwigFunction[]
*/ */
public function getFunctions(): array public function getFunctions(): array
{ {
@ -48,10 +44,8 @@ class LogoutUrlExtension extends AbstractExtension
* Generates the relative logout URL for the firewall. * Generates the relative logout URL for the firewall.
* *
* @param string|null $key The firewall key or null to use the current firewall key * @param string|null $key The firewall key or null to use the current firewall key
*
* @return string The relative logout URL
*/ */
public function getLogoutPath(string $key = null) public function getLogoutPath(string $key = null): string
{ {
return $this->generator->getLogoutPath($key); return $this->generator->getLogoutPath($key);
} }
@ -60,19 +54,9 @@ class LogoutUrlExtension extends AbstractExtension
* Generates the absolute logout URL for the firewall. * Generates the absolute logout URL for the firewall.
* *
* @param string|null $key The firewall key or null to use the current firewall key * @param string|null $key The firewall key or null to use the current firewall key
*
* @return string The absolute logout URL
*/ */
public function getLogoutUrl(string $key = null) public function getLogoutUrl(string $key = null): string
{ {
return $this->generator->getLogoutUrl($key); return $this->generator->getLogoutUrl($key);
} }
/**
* {@inheritdoc}
*/
public function getName()
{
return 'logout_url';
}
} }

View File

@ -17,10 +17,8 @@ use Twig\Profiler\Profile;
/** /**
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @final
*/ */
class ProfilerExtension extends BaseProfilerExtension final class ProfilerExtension extends BaseProfilerExtension
{ {
private $stopwatch; private $stopwatch;
private $events; private $events;
@ -51,12 +49,4 @@ class ProfilerExtension extends BaseProfilerExtension
unset($this->events[$profile]); unset($this->events[$profile]);
} }
} }
/**
* {@inheritdoc}
*/
public function getName()
{
return 'native_profiler';
}
} }

View File

@ -22,10 +22,8 @@ use Twig\TwigFunction;
* Provides integration of the Routing component with Twig. * Provides integration of the Routing component with Twig.
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @final
*/ */
class RoutingExtension extends AbstractExtension final class RoutingExtension extends AbstractExtension
{ {
private $generator; private $generator;
@ -36,8 +34,6 @@ class RoutingExtension extends AbstractExtension
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @return TwigFunction[]
*/ */
public function getFunctions(): array public function getFunctions(): array
{ {
@ -47,18 +43,12 @@ class RoutingExtension extends AbstractExtension
]; ];
} }
/** public function getPath(string $name, array $parameters = [], bool $relative = false): string
* @return string
*/
public function getPath(string $name, array $parameters = [], bool $relative = false)
{ {
return $this->generator->generate($name, $parameters, $relative ? UrlGeneratorInterface::RELATIVE_PATH : UrlGeneratorInterface::ABSOLUTE_PATH); return $this->generator->generate($name, $parameters, $relative ? UrlGeneratorInterface::RELATIVE_PATH : UrlGeneratorInterface::ABSOLUTE_PATH);
} }
/** public function getUrl(string $name, array $parameters = [], bool $schemeRelative = false): string
* @return string
*/
public function getUrl(string $name, array $parameters = [], bool $schemeRelative = false)
{ {
return $this->generator->generate($name, $parameters, $schemeRelative ? UrlGeneratorInterface::NETWORK_PATH : UrlGeneratorInterface::ABSOLUTE_URL); return $this->generator->generate($name, $parameters, $schemeRelative ? UrlGeneratorInterface::NETWORK_PATH : UrlGeneratorInterface::ABSOLUTE_URL);
} }
@ -84,8 +74,6 @@ class RoutingExtension extends AbstractExtension
* @param Node $argsNode The arguments of the path/url function * @param Node $argsNode The arguments of the path/url function
* *
* @return array An array with the contexts the URL is safe * @return array An array with the contexts the URL is safe
*
* @final
*/ */
public function isUrlGenerationSafe(Node $argsNode): array public function isUrlGenerationSafe(Node $argsNode): array
{ {
@ -102,12 +90,4 @@ class RoutingExtension extends AbstractExtension
return []; return [];
} }
/**
* {@inheritdoc}
*/
public function getName()
{
return 'routing';
}
} }

View File

@ -21,10 +21,8 @@ use Twig\TwigFunction;
* SecurityExtension exposes security context features. * SecurityExtension exposes security context features.
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @final
*/ */
class SecurityExtension extends AbstractExtension final class SecurityExtension extends AbstractExtension
{ {
private $securityChecker; private $securityChecker;
@ -33,7 +31,7 @@ class SecurityExtension extends AbstractExtension
$this->securityChecker = $securityChecker; $this->securityChecker = $securityChecker;
} }
public function isGranted($role, object $object = null, string $field = null) public function isGranted($role, object $object = null, string $field = null): bool
{ {
if (null === $this->securityChecker) { if (null === $this->securityChecker) {
return false; return false;
@ -52,8 +50,6 @@ class SecurityExtension extends AbstractExtension
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @return TwigFunction[]
*/ */
public function getFunctions(): array public function getFunctions(): array
{ {
@ -61,12 +57,4 @@ class SecurityExtension extends AbstractExtension
new TwigFunction('is_granted', [$this, 'isGranted']), new TwigFunction('is_granted', [$this, 'isGranted']),
]; ];
} }
/**
* {@inheritdoc}
*/
public function getName()
{
return 'security';
}
} }

View File

@ -20,10 +20,8 @@ use Twig\TokenParser\TokenParserInterface;
* Twig extension for the stopwatch helper. * Twig extension for the stopwatch helper.
* *
* @author Wouter J <wouter@wouterj.nl> * @author Wouter J <wouter@wouterj.nl>
*
* @final
*/ */
class StopwatchExtension extends AbstractExtension final class StopwatchExtension extends AbstractExtension
{ {
private $stopwatch; private $stopwatch;
private $enabled; private $enabled;
@ -34,7 +32,7 @@ class StopwatchExtension extends AbstractExtension
$this->enabled = $enabled; $this->enabled = $enabled;
} }
public function getStopwatch() public function getStopwatch(): Stopwatch
{ {
return $this->stopwatch; return $this->stopwatch;
} }
@ -53,9 +51,4 @@ class StopwatchExtension extends AbstractExtension
new StopwatchTokenParser(null !== $this->stopwatch && $this->enabled), new StopwatchTokenParser(null !== $this->stopwatch && $this->enabled),
]; ];
} }
public function getName()
{
return 'stopwatch';
}
} }

View File

@ -19,17 +19,14 @@ use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorTrait; use Symfony\Contracts\Translation\TranslatorTrait;
use Twig\Extension\AbstractExtension; use Twig\Extension\AbstractExtension;
use Twig\NodeVisitor\NodeVisitorInterface; use Twig\NodeVisitor\NodeVisitorInterface;
use Twig\TokenParser\AbstractTokenParser;
use Twig\TwigFilter; use Twig\TwigFilter;
/** /**
* Provides integration of the Translation component with Twig. * Provides integration of the Translation component with Twig.
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @final
*/ */
class TranslationExtension extends AbstractExtension final class TranslationExtension extends AbstractExtension
{ {
private $translator; private $translator;
private $translationNodeVisitor; private $translationNodeVisitor;
@ -40,7 +37,7 @@ class TranslationExtension extends AbstractExtension
$this->translationNodeVisitor = $translationNodeVisitor; $this->translationNodeVisitor = $translationNodeVisitor;
} }
public function getTranslator(): ?TranslatorInterface public function getTranslator(): TranslatorInterface
{ {
if (null === $this->translator) { if (null === $this->translator) {
if (!interface_exists(TranslatorInterface::class)) { if (!interface_exists(TranslatorInterface::class)) {
@ -57,8 +54,6 @@ class TranslationExtension extends AbstractExtension
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @return TwigFilter[]
*/ */
public function getFilters(): array public function getFilters(): array
{ {
@ -68,9 +63,7 @@ class TranslationExtension extends AbstractExtension
} }
/** /**
* Returns the token parser instance to add to the existing list. * {@inheritdoc}
*
* @return AbstractTokenParser[]
*/ */
public function getTokenParsers(): array public function getTokenParsers(): array
{ {
@ -85,8 +78,6 @@ class TranslationExtension extends AbstractExtension
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @return NodeVisitorInterface[]
*/ */
public function getNodeVisitors(): array public function getNodeVisitors(): array
{ {
@ -106,12 +97,4 @@ class TranslationExtension extends AbstractExtension
return $this->getTranslator()->trans($message, $arguments, $domain, $locale); return $this->getTranslator()->trans($message, $arguments, $domain, $locale);
} }
/**
* {@inheritdoc}
*/
public function getName(): string
{
return 'translator';
}
} }

View File

@ -21,10 +21,8 @@ use Twig\TwigFunction;
* Twig extension for the Symfony WebLink component. * Twig extension for the Symfony WebLink component.
* *
* @author Kévin Dunglas <dunglas@gmail.com> * @author Kévin Dunglas <dunglas@gmail.com>
*
* @final
*/ */
class WebLinkExtension extends AbstractExtension final class WebLinkExtension extends AbstractExtension
{ {
private $requestStack; private $requestStack;
@ -35,8 +33,6 @@ class WebLinkExtension extends AbstractExtension
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @return TwigFunction[]
*/ */
public function getFunctions(): array public function getFunctions(): array
{ {
@ -58,7 +54,7 @@ class WebLinkExtension extends AbstractExtension
* *
* @return string The relation URI * @return string The relation URI
*/ */
public function link(string $uri, string $rel, array $attributes = []) public function link(string $uri, string $rel, array $attributes = []): string
{ {
if (!$request = $this->requestStack->getMasterRequest()) { if (!$request = $this->requestStack->getMasterRequest()) {
return $uri; return $uri;
@ -82,7 +78,7 @@ class WebLinkExtension extends AbstractExtension
* *
* @return string The path of the asset * @return string The path of the asset
*/ */
public function preload(string $uri, array $attributes = []) public function preload(string $uri, array $attributes = []): string
{ {
return $this->link($uri, 'preload', $attributes); return $this->link($uri, 'preload', $attributes);
} }
@ -94,7 +90,7 @@ class WebLinkExtension extends AbstractExtension
* *
* @return string The path of the asset * @return string The path of the asset
*/ */
public function dnsPrefetch(string $uri, array $attributes = []) public function dnsPrefetch(string $uri, array $attributes = []): string
{ {
return $this->link($uri, 'dns-prefetch', $attributes); return $this->link($uri, 'dns-prefetch', $attributes);
} }
@ -106,7 +102,7 @@ class WebLinkExtension extends AbstractExtension
* *
* @return string The path of the asset * @return string The path of the asset
*/ */
public function preconnect(string $uri, array $attributes = []) public function preconnect(string $uri, array $attributes = []): string
{ {
return $this->link($uri, 'preconnect', $attributes); return $this->link($uri, 'preconnect', $attributes);
} }
@ -118,7 +114,7 @@ class WebLinkExtension extends AbstractExtension
* *
* @return string The path of the asset * @return string The path of the asset
*/ */
public function prefetch(string $uri, array $attributes = []) public function prefetch(string $uri, array $attributes = []): string
{ {
return $this->link($uri, 'prefetch', $attributes); return $this->link($uri, 'prefetch', $attributes);
} }
@ -130,7 +126,7 @@ class WebLinkExtension extends AbstractExtension
* *
* @return string The path of the asset * @return string The path of the asset
*/ */
public function prerender(string $uri, array $attributes = []) public function prerender(string $uri, array $attributes = []): string
{ {
return $this->link($uri, 'prerender', $attributes); return $this->link($uri, 'prerender', $attributes);
} }

View File

@ -21,10 +21,8 @@ use Twig\TwigFunction;
* WorkflowExtension. * WorkflowExtension.
* *
* @author Grégoire Pineau <lyrixx@lyrixx.info> * @author Grégoire Pineau <lyrixx@lyrixx.info>
*
* @final
*/ */
class WorkflowExtension extends AbstractExtension final class WorkflowExtension extends AbstractExtension
{ {
private $workflowRegistry; private $workflowRegistry;
@ -34,7 +32,7 @@ class WorkflowExtension extends AbstractExtension
} }
/** /**
* @return TwigFunction[] * {@inheritdoc}
*/ */
public function getFunctions(): array public function getFunctions(): array
{ {
@ -50,10 +48,8 @@ class WorkflowExtension extends AbstractExtension
/** /**
* Returns true if the transition is enabled. * Returns true if the transition is enabled.
*
* @return bool true if the transition is enabled
*/ */
public function canTransition(object $subject, string $transitionName, string $name = null) public function canTransition(object $subject, string $transitionName, string $name = null): bool
{ {
return $this->workflowRegistry->get($subject, $name)->can($subject, $transitionName); return $this->workflowRegistry->get($subject, $name)->can($subject, $transitionName);
} }
@ -63,17 +59,15 @@ class WorkflowExtension extends AbstractExtension
* *
* @return Transition[] All enabled transitions * @return Transition[] All enabled transitions
*/ */
public function getEnabledTransitions(object $subject, string $name = null) public function getEnabledTransitions(object $subject, string $name = null): array
{ {
return $this->workflowRegistry->get($subject, $name)->getEnabledTransitions($subject); return $this->workflowRegistry->get($subject, $name)->getEnabledTransitions($subject);
} }
/** /**
* Returns true if the place is marked. * Returns true if the place is marked.
*
* @return bool true if the transition is enabled
*/ */
public function hasMarkedPlace(object $subject, string $placeName, string $name = null) public function hasMarkedPlace(object $subject, string $placeName, string $name = null): bool
{ {
return $this->workflowRegistry->get($subject, $name)->getMarking($subject)->has($placeName); return $this->workflowRegistry->get($subject, $name)->getMarking($subject)->has($placeName);
} }
@ -83,7 +77,7 @@ class WorkflowExtension extends AbstractExtension
* *
* @return string[]|int[] * @return string[]|int[]
*/ */
public function getMarkedPlaces(object $subject, bool $placesNameOnly = true, string $name = null) public function getMarkedPlaces(object $subject, bool $placesNameOnly = true, string $name = null): array
{ {
$places = $this->workflowRegistry->get($subject, $name)->getMarking($subject)->getPlaces(); $places = $this->workflowRegistry->get($subject, $name)->getMarking($subject)->getPlaces();
@ -117,9 +111,4 @@ class WorkflowExtension extends AbstractExtension
return $workflow->buildTransitionBlockerList($subject, $transitionName); return $workflow->buildTransitionBlockerList($subject, $transitionName);
} }
public function getName()
{
return 'workflow';
}
} }

View File

@ -12,7 +12,6 @@
namespace Symfony\Bridge\Twig\Extension; namespace Symfony\Bridge\Twig\Extension;
use Symfony\Component\Yaml\Dumper as YamlDumper; use Symfony\Component\Yaml\Dumper as YamlDumper;
use Symfony\Component\Yaml\Yaml;
use Twig\Extension\AbstractExtension; use Twig\Extension\AbstractExtension;
use Twig\TwigFilter; use Twig\TwigFilter;
@ -20,15 +19,11 @@ use Twig\TwigFilter;
* Provides integration of the Yaml component with Twig. * Provides integration of the Yaml component with Twig.
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @final
*/ */
class YamlExtension extends AbstractExtension final class YamlExtension extends AbstractExtension
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @return TwigFilter[]
*/ */
public function getFilters(): array public function getFilters(): array
{ {
@ -38,7 +33,7 @@ class YamlExtension extends AbstractExtension
]; ];
} }
public function encode($input, int $inline = 0, int $dumpObjects = 0) public function encode($input, int $inline = 0, int $dumpObjects = 0): string
{ {
static $dumper; static $dumper;
@ -53,7 +48,7 @@ class YamlExtension extends AbstractExtension
return $dumper->dump($input, $inline, 0, false, $dumpObjects); return $dumper->dump($input, $inline, 0, false, $dumpObjects);
} }
public function dump($value, int $inline = 0, int $dumpObjects = 0) public function dump($value, int $inline = 0, int $dumpObjects = 0): string
{ {
if (\is_resource($value)) { if (\is_resource($value)) {
return '%Resource%'; return '%Resource%';
@ -65,12 +60,4 @@ class YamlExtension extends AbstractExtension
return $this->encode($value, $inline, $dumpObjects); return $this->encode($value, $inline, $dumpObjects);
} }
/**
* {@inheritdoc}
*/
public function getName()
{
return 'yaml';
}
} }

View File

@ -16,14 +16,12 @@ use Twig\Node\Node;
/** /**
* @author Julien Galenski <julien.galenski@gmail.com> * @author Julien Galenski <julien.galenski@gmail.com>
*
* @final
*/ */
class DumpNode extends Node final class DumpNode extends Node
{ {
private $varPrefix; private $varPrefix;
public function __construct($varPrefix, Node $values = null, int $lineno, string $tag = null) public function __construct($varPrefix, ?Node $values, int $lineno, string $tag = null)
{ {
$nodes = []; $nodes = [];
if (null !== $values) { if (null !== $values) {

View File

@ -17,10 +17,8 @@ use Twig\Node\Node;
/** /**
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @final
*/ */
class FormThemeNode extends Node final class FormThemeNode extends Node
{ {
public function __construct(Node $form, Node $resources, int $lineno, string $tag = null, bool $only = false) public function __construct(Node $form, Node $resources, int $lineno, string $tag = null, bool $only = false)
{ {

View File

@ -21,10 +21,8 @@ use Twig\Node\Expression\FunctionExpression;
* is "foo", the block "foo" will be rendered. * is "foo", the block "foo" will be rendered.
* *
* @author Bernhard Schussek <bschussek@gmail.com> * @author Bernhard Schussek <bschussek@gmail.com>
*
* @final
*/ */
class RenderBlockNode extends FunctionExpression final class RenderBlockNode extends FunctionExpression
{ {
public function compile(Compiler $compiler): void public function compile(Compiler $compiler): void
{ {

View File

@ -18,10 +18,8 @@ use Twig\Node\Expression\FunctionExpression;
/** /**
* @author Bernhard Schussek <bschussek@gmail.com> * @author Bernhard Schussek <bschussek@gmail.com>
*
* @final
*/ */
class SearchAndRenderBlockNode extends FunctionExpression final class SearchAndRenderBlockNode extends FunctionExpression
{ {
public function compile(Compiler $compiler): void public function compile(Compiler $compiler): void
{ {

View File

@ -19,10 +19,8 @@ use Twig\Node\Node;
* Represents a stopwatch node. * Represents a stopwatch node.
* *
* @author Wouter J <wouter@wouterj.nl> * @author Wouter J <wouter@wouterj.nl>
*
* @final
*/ */
class StopwatchNode extends Node final class StopwatchNode extends Node
{ {
public function __construct(Node $name, Node $body, AssignNameExpression $var, int $lineno = 0, string $tag = null) public function __construct(Node $name, Node $body, AssignNameExpression $var, int $lineno = 0, string $tag = null)
{ {

View File

@ -17,10 +17,8 @@ use Twig\Node\Node;
/** /**
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @final
*/ */
class TransDefaultDomainNode extends Node final class TransDefaultDomainNode extends Node
{ {
public function __construct(AbstractExpression $expr, int $lineno = 0, string $tag = null) public function __construct(AbstractExpression $expr, int $lineno = 0, string $tag = null)
{ {

View File

@ -19,15 +19,10 @@ use Twig\Node\Expression\NameExpression;
use Twig\Node\Node; use Twig\Node\Node;
use Twig\Node\TextNode; use Twig\Node\TextNode;
// BC/FC with namespaced Twig
class_exists('Twig\Node\Expression\ArrayExpression');
/** /**
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @final
*/ */
class TransNode extends Node final class TransNode extends Node
{ {
public function __construct(Node $body, Node $domain = null, AbstractExpression $count = null, AbstractExpression $vars = null, AbstractExpression $locale = null, int $lineno = 0, string $tag = null) public function __construct(Node $body, Node $domain = null, AbstractExpression $count = null, AbstractExpression $vars = null, AbstractExpression $locale = null, int $lineno = 0, string $tag = null)
{ {
@ -105,7 +100,7 @@ class TransNode extends Node
$compiler->raw(");\n"); $compiler->raw(");\n");
} }
protected function compileString(Node $body, ArrayExpression $vars, bool $ignoreStrictCheck = false) private function compileString(Node $body, ArrayExpression $vars, bool $ignoreStrictCheck = false): array
{ {
if ($body instanceof ConstantExpression) { if ($body instanceof ConstantExpression) {
$msg = $body->getAttribute('value'); $msg = $body->getAttribute('value');

View File

@ -27,10 +27,8 @@ use Twig\NodeVisitor\AbstractNodeVisitor;
/** /**
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @final
*/ */
class TranslationDefaultDomainNodeVisitor extends AbstractNodeVisitor final class TranslationDefaultDomainNodeVisitor extends AbstractNodeVisitor
{ {
private $scope; private $scope;
@ -126,7 +124,7 @@ class TranslationDefaultDomainNodeVisitor extends AbstractNodeVisitor
return false; return false;
} }
private function getVarName() private function getVarName(): string
{ {
return sprintf('__internal_%s', hash('sha256', uniqid(mt_rand(), true), false)); return sprintf('__internal_%s', hash('sha256', uniqid(mt_rand(), true), false));
} }

View File

@ -22,29 +22,27 @@ use Twig\NodeVisitor\AbstractNodeVisitor;
* TranslationNodeVisitor extracts translation messages. * TranslationNodeVisitor extracts translation messages.
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @final
*/ */
class TranslationNodeVisitor extends AbstractNodeVisitor final class TranslationNodeVisitor extends AbstractNodeVisitor
{ {
const UNDEFINED_DOMAIN = '_undefined'; const UNDEFINED_DOMAIN = '_undefined';
private $enabled = false; private $enabled = false;
private $messages = []; private $messages = [];
public function enable() public function enable(): void
{ {
$this->enabled = true; $this->enabled = true;
$this->messages = []; $this->messages = [];
} }
public function disable() public function disable(): void
{ {
$this->enabled = false; $this->enabled = false;
$this->messages = []; $this->messages = [];
} }
public function getMessages() public function getMessages(): array
{ {
return $this->messages; return $this->messages;
} }

View File

@ -44,7 +44,7 @@ class CodeExtensionTest extends TestCase
$this->assertEquals($this->getExtension()->abbrMethod($method), $abbr); $this->assertEquals($this->getExtension()->abbrMethod($method), $abbr);
} }
public function getClassNameProvider() public function getClassNameProvider(): array
{ {
return [ return [
['F\Q\N\Foo', '<abbr title="F\Q\N\Foo">Foo</abbr>'], ['F\Q\N\Foo', '<abbr title="F\Q\N\Foo">Foo</abbr>'],
@ -52,7 +52,7 @@ class CodeExtensionTest extends TestCase
]; ];
} }
public function getMethodNameProvider() public function getMethodNameProvider(): array
{ {
return [ return [
['F\Q\N\Foo::Method', '<abbr title="F\Q\N\Foo">Foo</abbr>::Method()'], ['F\Q\N\Foo::Method', '<abbr title="F\Q\N\Foo">Foo</abbr>::Method()'],
@ -62,12 +62,7 @@ class CodeExtensionTest extends TestCase
]; ];
} }
public function testGetName() protected function getExtension(): CodeExtension
{
$this->assertEquals('code', $this->getExtension()->getName());
}
protected function getExtension()
{ {
return new CodeExtension(new FileLinkFormatter('proto://%f#&line=%l&'.substr(__FILE__, 0, 5).'>foobar'), \DIRECTORY_SEPARATOR.'project', 'UTF-8'); return new CodeExtension(new FileLinkFormatter('proto://%f#&line=%l&'.substr(__FILE__, 0, 5).'>foobar'), \DIRECTORY_SEPARATOR.'project', 'UTF-8');
} }

View File

@ -26,10 +26,8 @@ use Twig\TokenParser\AbstractTokenParser;
* {% dump foo, bar %} * {% dump foo, bar %}
* *
* @author Julien Galenski <julien.galenski@gmail.com> * @author Julien Galenski <julien.galenski@gmail.com>
*
* @final
*/ */
class DumpTokenParser extends AbstractTokenParser final class DumpTokenParser extends AbstractTokenParser
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}

View File

@ -21,10 +21,8 @@ use Twig\TokenParser\AbstractTokenParser;
* Token Parser for the 'form_theme' tag. * Token Parser for the 'form_theme' tag.
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @final
*/ */
class FormThemeTokenParser extends AbstractTokenParser final class FormThemeTokenParser extends AbstractTokenParser
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}

View File

@ -21,10 +21,8 @@ use Twig\TokenParser\AbstractTokenParser;
* Token Parser for the stopwatch tag. * Token Parser for the stopwatch tag.
* *
* @author Wouter J <wouter@wouterj.nl> * @author Wouter J <wouter@wouterj.nl>
*
* @final
*/ */
class StopwatchTokenParser extends AbstractTokenParser final class StopwatchTokenParser extends AbstractTokenParser
{ {
protected $stopwatchIsAvailable; protected $stopwatchIsAvailable;
@ -54,7 +52,7 @@ class StopwatchTokenParser extends AbstractTokenParser
return $body; return $body;
} }
public function decideStopwatchEnd(Token $token) public function decideStopwatchEnd(Token $token): bool
{ {
return $token->test('endstopwatch'); return $token->test('endstopwatch');
} }

View File

@ -20,10 +20,8 @@ use Twig\TokenParser\AbstractTokenParser;
* Token Parser for the 'trans_default_domain' tag. * Token Parser for the 'trans_default_domain' tag.
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @final
*/ */
class TransDefaultDomainTokenParser extends AbstractTokenParser final class TransDefaultDomainTokenParser extends AbstractTokenParser
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}

View File

@ -24,10 +24,8 @@ use Twig\TokenParser\AbstractTokenParser;
* Token Parser for the 'trans' tag. * Token Parser for the 'trans' tag.
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @final
*/ */
class TransTokenParser extends AbstractTokenParser final class TransTokenParser extends AbstractTokenParser
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
@ -82,7 +80,7 @@ class TransTokenParser extends AbstractTokenParser
return new TransNode($body, $domain, $count, $vars, $locale, $lineno, $this->getTag()); return new TransNode($body, $domain, $count, $vars, $locale, $lineno, $this->getTag());
} }
public function decideTransFork(Token $token) public function decideTransFork(Token $token): bool
{ {
return $token->test(['endtrans']); return $token->test(['endtrans']);
} }