Browse code

minor #2256 1 x cleanups (SpacePossum)

This PR was squashed before being merged into the 1.x branch (closes #2256).

Discussion
----------

1 x cleanups

Commits
-------

2ea7d78 1 x cleanups

Fabien Potencier authored on 17/11/2016 16:06:11
Showing 5 changed files
... ...
@@ -296,8 +296,8 @@ function twig_cycle($values, $position)
296 296
  * - a random character from a string
297 297
  * - a random integer between 0 and the integer parameter.
298 298
  *
299
- * @param Twig_Environment             $env
300
- * @param Traversable|array|int|string $values The values to pick a random item from
299
+ * @param Twig_Environment                   $env
300
+ * @param Traversable|array|int|float|string $values The values to pick a random item from
301 301
  *
302 302
  * @throws Twig_Error_Runtime When $values is an empty array (does not apply to an empty string which is returned as is).
303 303
  *
... ...
@@ -991,7 +991,7 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html',
991 991
                 $string = twig_convert_encoding($string, 'UTF-8', $charset);
992 992
             }
993 993
 
994
-            if (0 == strlen($string) ? false : (1 == preg_match('/^./su', $string) ? false : true)) {
994
+            if (0 == strlen($string) ? false : 1 !== preg_match('/^./su', $string)) {
995 995
                 throw new Twig_Error_Runtime('The string to escape is not a valid UTF-8 string.');
996 996
             }
997 997
 
... ...
@@ -1008,7 +1008,7 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html',
1008 1008
                 $string = twig_convert_encoding($string, 'UTF-8', $charset);
1009 1009
             }
1010 1010
 
1011
-            if (0 == strlen($string) ? false : (1 == preg_match('/^./su', $string) ? false : true)) {
1011
+            if (0 == strlen($string) ? false : 1 !== preg_match('/^./su', $string)) {
1012 1012
                 throw new Twig_Error_Runtime('The string to escape is not a valid UTF-8 string.');
1013 1013
             }
1014 1014
 
... ...
@@ -1025,7 +1025,7 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html',
1025 1025
                 $string = twig_convert_encoding($string, 'UTF-8', $charset);
1026 1026
             }
1027 1027
 
1028
-            if (0 == strlen($string) ? false : (1 == preg_match('/^./su', $string) ? false : true)) {
1028
+            if (0 == strlen($string) ? false : 1 !== preg_match('/^./su', $string)) {
1029 1029
                 throw new Twig_Error_Runtime('The string to escape is not a valid UTF-8 string.');
1030 1030
             }
1031 1031
 
... ...
@@ -43,7 +43,7 @@ class Twig_Node_Expression_Array extends Twig_Node_Expression
43 43
         foreach ($this->getKeyValuePairs() as $pair) {
44 44
             // we compare the string representation of the keys
45 45
             // to avoid comparing the line numbers which are not relevant here.
46
-            if ((string) $key == (string) $pair['key']) {
46
+            if ((string) $key === (string) $pair['key']) {
47 47
                 return true;
48 48
             }
49 49
         }
... ...
@@ -146,7 +146,7 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
146 146
                     throw new Twig_Error_Syntax(sprintf('Argument "%s" is defined twice for %s "%s".', $name, $callType, $callName));
147 147
                 }
148 148
 
149
-                if (!empty($missingArguments)) {
149
+                if (count($missingArguments)) {
150 150
                     throw new Twig_Error_Syntax(sprintf(
151 151
                         'Argument "%s" could not be assigned for %s "%s(%s)" because it is mapped to an internal PHP function which cannot determine default value for optional argument%s "%s".',
152 152
                         $name, $callType, $callName, implode(', ', $names), count($missingArguments) > 1 ? 's' : '', implode('", "', $missingArguments))
... ...
@@ -218,7 +218,7 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
218 218
 
219 219
     private function getCallableParameters($callable, $isVariadic)
220 220
     {
221
-        list($r, $_) = $this->reflectCallable($callable);
221
+        list($r) = $this->reflectCallable($callable);
222 222
         if (null === $r) {
223 223
             return array();
224 224
         }
... ...
@@ -133,13 +133,14 @@ class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor
133 133
             return $node;
134 134
         }
135 135
 
136
+        $exprNode = $node->getNode('expr');
136 137
         if (
137
-            $node->getNode('expr') instanceof Twig_Node_Expression_BlockReference ||
138
-            $node->getNode('expr') instanceof Twig_Node_Expression_Parent
138
+            $exprNode instanceof Twig_Node_Expression_BlockReference ||
139
+            $exprNode instanceof Twig_Node_Expression_Parent
139 140
         ) {
140
-            $node->getNode('expr')->setAttribute('output', true);
141
+            $exprNode->setAttribute('output', true);
141 142
 
142
-            return $node->getNode('expr');
143
+            return $exprNode;
143 144
         }
144 145
 
145 146
         return $node;
... ...
@@ -50,7 +50,7 @@ final class Twig_TemplateWrapper
50 50
      */
51 51
     public function display($context = array())
52 52
     {
53
-        return $this->template->display($context);
53
+        $this->template->display($context);
54 54
     }
55 55
 
56 56
     /**