Code grooming

This commit is contained in:
Possum
2015-11-05 09:57:20 +01:00
parent fd84403ac7
commit d4e3adaaee
12 changed files with 34 additions and 43 deletions
+8 -12
View File
@@ -961,13 +961,11 @@ class Twig_Environment
foreach ($this->filters as $pattern => $filter) {
$pattern = str_replace('\\*', '(.*?)', preg_quote($pattern, '#'), $count);
if ($count) {
if (preg_match('#^'.$pattern.'$#', $name, $matches)) {
array_shift($matches);
$filter->setArguments($matches);
if ($count && preg_match('#^'.$pattern.'$#', $name, $matches)) {
array_shift($matches);
$filter->setArguments($matches);
return $filter;
}
return $filter;
}
}
@@ -1112,13 +1110,11 @@ class Twig_Environment
foreach ($this->functions as $pattern => $function) {
$pattern = str_replace('\\*', '(.*?)', preg_quote($pattern, '#'), $count);
if ($count) {
if (preg_match('#^'.$pattern.'$#', $name, $matches)) {
array_shift($matches);
$function->setArguments($matches);
if ($count && preg_match('#^'.$pattern.'$#', $name, $matches)) {
array_shift($matches);
$function->setArguments($matches);
return $function;
}
return $function;
}
}
+7 -5
View File
@@ -817,9 +817,10 @@ function twig_join_filter($value, $glue = '')
* {# returns [aa, bb, cc] #}
* </pre>
*
* @param string $value A string
* @param string $delimiter The delimiter
* @param int $limit The limit
* @param Twig_Environment $env A Twig_Environment instance
* @param string $value A string
* @param string $delimiter The delimiter
* @param int $limit The limit
*
* @return array The split string as an array
*/
@@ -1476,8 +1477,9 @@ function twig_include(Twig_Environment $env, $context, $template, $variables = a
/**
* Returns a template content without rendering it.
*
* @param string $name The template name
* @param bool $ignoreMissing Whether to ignore missing templates or not
* @param Twig_Environment $env
* @param string $name The template name
* @param bool $ignoreMissing Whether to ignore missing templates or not
*
* @return string The template source
*/
+1 -1
View File
@@ -101,7 +101,7 @@ class Twig_Node implements Twig_NodeInterface
$node->appendChild($child);
}
return $asDom ? $dom : $dom->saveXml();
return $asDom ? $dom : $dom->saveXML();
}
public function compile(Twig_Compiler $compiler)
-5
View File
@@ -21,11 +21,6 @@
*/
class Twig_Node_SandboxedPrint extends Twig_Node_Print
{
public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null)
{
parent::__construct($expr, $lineno, $tag);
}
public function compile(Twig_Compiler $compiler)
{
$compiler
+3 -5
View File
@@ -94,10 +94,8 @@ class Twig_Parser implements Twig_ParserInterface
try {
$body = $this->subparse($test, $dropNeedle);
if (null !== $this->parent) {
if (null === $body = $this->filterBodyNodes($body)) {
$body = new Twig_Node();
}
if (null !== $this->parent && null === $body = $this->filterBodyNodes($body)) {
$body = new Twig_Node();
}
} catch (Twig_Error_Syntax $e) {
if (!$e->getTemplateFile()) {
@@ -148,7 +146,7 @@ class Twig_Parser implements Twig_ParserInterface
$token = $this->getCurrentToken();
if ($token->getType() !== Twig_Token::NAME_TYPE) {
throw new Twig_Error_Syntax('A block must start with a tag name', $token->getLine(), $this->getFilename());
throw new Twig_Error_Syntax('A block must start with a tag name.', $token->getLine(), $this->getFilename());
}
if (null !== $test && call_user_func($test, $token)) {
+2 -2
View File
@@ -90,13 +90,13 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase
if (preg_match('/--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)\s*(?:--DATA--\s*(.*))?\s*--EXCEPTION--\s*(.*)/sx', $test, $match)) {
$message = $match[1];
$condition = $match[2];
$templates = $this->parseTemplates($match[3]);
$templates = static::parseTemplates($match[3]);
$exception = $match[5];
$outputs = array(array(null, $match[4], null, ''));
} elseif (preg_match('/--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)--DATA--.*?--EXPECT--.*/s', $test, $match)) {
$message = $match[1];
$condition = $match[2];
$templates = $this->parseTemplates($match[3]);
$templates = static::parseTemplates($match[3]);
$exception = false;
preg_match_all('/--DATA--(.*?)(?:--CONFIG--(.*?))?--EXPECT--(.*?)(?=\-\-DATA\-\-|$)/s', $test, $outputs, PREG_SET_ORDER);
} else {
+2 -2
View File
@@ -28,7 +28,7 @@ class Twig_TokenParser_Block extends Twig_TokenParser
$stream = $this->parser->getStream();
$name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
if ($this->parser->hasBlock($name)) {
throw new Twig_Error_Syntax(sprintf("The block '$name' has already been defined line %d", $this->parser->getBlock($name)->getLine()), $stream->getCurrent()->getLine(), $stream->getFilename());
throw new Twig_Error_Syntax(sprintf("The block '%s' has already been defined line %d", $name, $this->parser->getBlock($name)->getLine()), $stream->getCurrent()->getLine(), $stream->getFilename());
}
$this->parser->setBlock($name, $block = new Twig_Node_Block($name, new Twig_Node(array()), $lineno));
$this->parser->pushLocalScope();
@@ -40,7 +40,7 @@ class Twig_TokenParser_Block extends Twig_TokenParser
$value = $token->getValue();
if ($value != $name) {
throw new Twig_Error_Syntax(sprintf('Expected endblock for block "%s" (but "%s" given)', $name, $value), $stream->getCurrent()->getLine(), $stream->getFilename());
throw new Twig_Error_Syntax(sprintf('Expected endblock for block "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getFilename());
}
}
} else {
+3 -2
View File
@@ -28,6 +28,7 @@ class Twig_TokenParserBroker implements Twig_TokenParserBrokerInterface
*
* @param array|Traversable $parsers A Traversable of Twig_TokenParserInterface instances
* @param array|Traversable $brokers A Traversable of Twig_TokenParserBrokerInterface instances
* @param bool $triggerDeprecationError
*/
public function __construct($parsers = array(), $brokers = array(), $triggerDeprecationError = true)
{
@@ -37,13 +38,13 @@ class Twig_TokenParserBroker implements Twig_TokenParserBrokerInterface
foreach ($parsers as $parser) {
if (!$parser instanceof Twig_TokenParserInterface) {
throw new LogicException('$parsers must a an array of Twig_TokenParserInterface');
throw new LogicException('$parsers must a an array of Twig_TokenParserInterface.');
}
$this->parsers[$parser->getTag()] = $parser;
}
foreach ($brokers as $broker) {
if (!$broker instanceof Twig_TokenParserBrokerInterface) {
throw new LogicException('$brokers must a an array of Twig_TokenParserBrokerInterface');
throw new LogicException('$brokers must a an array of Twig_TokenParserBrokerInterface.');
}
$this->brokers[] = $broker;
}
+3 -4
View File
@@ -11,6 +11,8 @@
class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
{
private $deprecations = array();
/**
* @expectedException LogicException
* @expectedExceptionMessage You must set a loader first.
@@ -282,7 +284,6 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
$twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
$twig->addExtension(new Twig_Tests_EnvironmentTest_Extension_WithGlobals());
$this->deprecations = array();
set_error_handler(array($this, 'handleError'));
$this->assertArrayHasKey('foo_global', $twig->getGlobals());
@@ -344,7 +345,6 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
$twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
$twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithDeprecationInitRuntime());
$this->deprecations = array();
set_error_handler(array($this, 'handleError'));
$twig->initRuntime();
@@ -365,12 +365,11 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
/**
* @requires PHP 5.3
*/
public function testOverrideExtenion()
public function testOverrideExtension()
{
$twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
$twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithDeprecationInitRuntime());
$this->deprecations = array();
set_error_handler(array($this, 'handleError'));
$twig->addExtension(new Twig_Tests_EnvironmentTest_Extension());
@@ -8,7 +8,7 @@
{% use "ancestor.twig" %}
{% block sub_container %}
<div class="overriden_sub_container">overriden sub_container</div>
<div class="overridden_sub_container">overridden sub_container</div>
{% endblock %}
--TEMPLATE(ancestor.twig)--
{% block container %}
@@ -21,5 +21,5 @@
--DATA--
return array()
--EXPECT--
<div class="container"> <div class="overriden_sub_container">overriden sub_container</div>
<div class="container"> <div class="overridden_sub_container">overridden sub_container</div>
</div>
@@ -7,7 +7,7 @@
{{ block('container') }}
--TEMPLATE(parent.twig)--
{% block sub_container %}
<div class="overriden_sub_container">overriden sub_container</div>
<div class="overridden_sub_container">overridden sub_container</div>
{% endblock %}
--TEMPLATE(ancestor.twig)--
{% block container %}
@@ -20,5 +20,5 @@
--DATA--
return array()
--EXPECT--
<div class="container"> <div class="overriden_sub_container">overriden sub_container</div>
<div class="container"> <div class="overridden_sub_container">overridden sub_container</div>
</div>
+1 -1
View File
@@ -666,7 +666,7 @@ class Twig_TemplateMagicMethodExceptionObject
{
public function __call($method, $arguments)
{
throw new BadMethodCallException(sprintf('Unkown method %s', $method));
throw new BadMethodCallException(sprintf('Unknown method "%s".', $method));
}
}