From 1f6fd6700ed2b629c788b94f7fc6027db1881a97 Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Wed, 16 Nov 2016 09:31:04 +0100 Subject: [PATCH] Clean ups --- lib/Twig/Extension/Core.php | 2 +- lib/Twig/ExtensionSet.php | 19 ------------------- lib/Twig/Lexer.php | 9 ++------- lib/Twig/Loader/Filesystem.php | 2 +- lib/Twig/Parser.php | 3 --- lib/Twig/Template.php | 12 +++--------- lib/Twig/Util/DeprecationCollector.php | 2 +- 7 files changed, 8 insertions(+), 41 deletions(-) diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 109d632a5..440cd8d16 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -408,7 +408,7 @@ function twig_date_converter(Twig_Environment $env, $date = null, $timezone = nu return false !== $timezone ? $date->setTimezone($timezone) : $date; } - if ($date instanceof DateTime || $date instanceof DateTimeInterface) { + if ($date instanceof DateTimeInterface) { $date = clone $date; if (false !== $timezone) { $date->setTimezone($timezone); diff --git a/lib/Twig/ExtensionSet.php b/lib/Twig/ExtensionSet.php index c971a7d62..f505e32d9 100644 --- a/lib/Twig/ExtensionSet.php +++ b/lib/Twig/ExtensionSet.php @@ -150,7 +150,6 @@ final class Twig_ExtensionSet throw new LogicException(sprintf('Unable to register extension "%s" as it is already registered.', $class)); } - $this->lastModifiedExtension = 0; $this->extensions[$class] = $extension; } @@ -163,9 +162,6 @@ final class Twig_ExtensionSet $this->staging->addFunction($function); } - /** - * {@inheritdoc} - */ public function getFunctions() { if (!$this->initialized) { @@ -226,9 +222,6 @@ final class Twig_ExtensionSet $this->staging->addFilter($filter); } - /** - * {@inheritdoc} - */ public function getFilters() { if (!$this->initialized) { @@ -292,9 +285,6 @@ final class Twig_ExtensionSet $this->staging->addNodeVisitor($visitor); } - /** - * {@inheritdoc} - */ public function getNodeVisitors() { if (!$this->initialized) { @@ -313,9 +303,6 @@ final class Twig_ExtensionSet $this->staging->addTokenParser($parser); } - /** - * {@inheritdoc} - */ public function getTokenParsers() { if (!$this->initialized) { @@ -325,9 +312,6 @@ final class Twig_ExtensionSet return $this->parsers; } - /** - * {@inheritdoc} - */ public function getGlobals() { if (null !== $this->globals) { @@ -364,9 +348,6 @@ final class Twig_ExtensionSet $this->staging->addTest($test); } - /** - * {@inheritdoc} - */ public function getTests() { if (!$this->initialized) { diff --git a/lib/Twig/Lexer.php b/lib/Twig/Lexer.php index 4e771c016..2f579e063 100644 --- a/lib/Twig/Lexer.php +++ b/lib/Twig/Lexer.php @@ -72,13 +72,8 @@ class Twig_Lexer ); } - /** - * {@inheritdoc} - */ - public function tokenize($code, $name = null) + public function tokenize(\Twig_Source $source) { - $source = $code; - if (((int) ini_get('mbstring.func_overload')) & 2) { $mbEncoding = mb_internal_encoding(); mb_internal_encoding('ASCII'); @@ -401,7 +396,7 @@ class Twig_Lexer private function popState() { if (0 === count($this->states)) { - throw new Exception('Cannot pop state without a previous state.'); + throw new LogicException('Cannot pop state without a previous state.'); } $this->state = array_pop($this->states); diff --git a/lib/Twig/Loader/Filesystem.php b/lib/Twig/Loader/Filesystem.php index 4ab5cd40a..25af7bfaf 100644 --- a/lib/Twig/Loader/Filesystem.php +++ b/lib/Twig/Loader/Filesystem.php @@ -285,7 +285,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI { return strspn($file, '/\\', 0, 1) || (strlen($file) > 3 && ctype_alpha($file[0]) - && substr($file, 1, 1) === ':' + && ':' === $file[1] && strspn($file, '/\\', 2, 1) ) || null !== parse_url($file, PHP_URL_SCHEME) diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php index 2e86d7add..de358fba6 100644 --- a/lib/Twig/Parser.php +++ b/lib/Twig/Parser.php @@ -41,9 +41,6 @@ class Twig_Parser return sprintf('__internal_%s', hash('sha256', uniqid(mt_rand(), true), false)); } - /** - * {@inheritdoc} - */ public function parse(Twig_TokenStream $stream, $test = null, $dropNeedle = false) { // push all variables into the stack to keep the current state of the parser diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index 9c0a10c6d..b6bd1e17c 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -281,8 +281,8 @@ abstract class Twig_Template * This method checks blocks defined in the current template * or defined in "used" traits or defined in parent templates. * - * @param array $context The context - * @param array $blocks The current set of blocks + * @param array $context The context + * @param array $blocks The current set of blocks * * @return array An array of block names * @@ -317,7 +317,7 @@ abstract class Twig_Template return $this->env->loadTemplate($template, $index); } catch (Twig_Error $e) { if (!$e->getTemplateName()) { - $e->setTemplateName($templateName ? $templateName : $this->getTemplateName()); + $e->setTemplateName($templateName ?: $this->getTemplateName()); } if ($e->getTemplateLine()) { @@ -349,17 +349,11 @@ abstract class Twig_Template return $this->blocks; } - /** - * {@inheritdoc} - */ public function display(array $context, array $blocks = array()) { $this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks)); } - /** - * {@inheritdoc} - */ public function render(array $context) { $level = ob_get_level(); diff --git a/lib/Twig/Util/DeprecationCollector.php b/lib/Twig/Util/DeprecationCollector.php index 11f3a1026..d568d38de 100644 --- a/lib/Twig/Util/DeprecationCollector.php +++ b/lib/Twig/Util/DeprecationCollector.php @@ -58,7 +58,7 @@ class Twig_Util_DeprecationCollector foreach ($iterator as $name => $contents) { try { - $this->twig->parse($this->twig->tokenize($contents, $name)); + $this->twig->parse($this->twig->tokenize($contents)); } catch (Twig_Error_Syntax $e) { // ignore templates containing syntax errors }