ソースを参照

Make casting scalar to array consistent

Victor Berchet 14 年 前
コミット
f83e92bf44

+ 1 - 3
src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php

@@ -686,9 +686,7 @@ abstract class AbstractDoctrineExtensionTest extends TestCase
 
     protected function getContainer($bundles = 'YamlBundle', $vendor = null)
     {
-        if (!is_array($bundles)) {
-            $bundles = array($bundles);
-        }
+        $bundles = (array) $bundles;
 
         $map = array();
         foreach ($bundles as $bundle) {

+ 1 - 4
src/Symfony/Component/Config/FileLocator.php

@@ -27,10 +27,7 @@ class FileLocator implements FileLocatorInterface
      */
     public function __construct($paths = array())
     {
-        if (!is_array($paths)) {
-            $paths = array($paths);
-        }
-        $this->paths = $paths;
+        $this->paths = (array) $paths;
     }
 
     /**

+ 1 - 3
src/Symfony/Component/Console/Helper/FormatterHelper.php

@@ -41,9 +41,7 @@ class FormatterHelper extends Helper
      */
     public function formatBlock($messages, $style, $large = false)
     {
-        if (!is_array($messages)) {
-            $messages = array($messages);
-        }
+        $messages = (array) $messages;
 
         $len = 0;
         $lines = array();

+ 2 - 6
src/Symfony/Component/Console/Input/ArgvInput.php

@@ -260,9 +260,7 @@ class ArgvInput extends Input
      */
     public function hasParameterOption($values)
     {
-        if (!is_array($values)) {
-            $values = array($values);
-        }
+        $values = (array) $values;
 
         foreach ($this->tokens as $v) {
             if (in_array($v, $values)) {
@@ -285,9 +283,7 @@ class ArgvInput extends Input
      */
     public function getParameterOption($values, $default = false)
     {
-        if (!is_array($values)) {
-            $values = array($values);
-        }
+        $values = (array) $values;
 
         $tokens = $this->tokens;
         while ($token = array_shift($tokens)) {

+ 2 - 6
src/Symfony/Component/Console/Input/ArrayInput.php

@@ -69,9 +69,7 @@ class ArrayInput extends Input
      */
     public function hasParameterOption($values)
     {
-        if (!is_array($values)) {
-            $values = array($values);
-        }
+        $values = (array) $values;
 
         foreach ($this->parameters as $k => $v) {
             if (!is_int($k)) {
@@ -99,9 +97,7 @@ class ArrayInput extends Input
      */
     public function getParameterOption($values, $default = false)
     {
-        if (!is_array($values)) {
-            $values = array($values);
-        }
+        $values = (array) $values;
 
         foreach ($this->parameters as $k => $v) {
             if (is_int($k) && in_array($v, $values)) {

+ 1 - 3
src/Symfony/Component/Console/Output/Output.php

@@ -154,9 +154,7 @@ abstract class Output implements OutputInterface
             return;
         }
 
-        if (!is_array($messages)) {
-            $messages = array($messages);
-        }
+        $messages = (array) $messages;
 
         foreach ($messages as $message) {
             switch ($type) {

+ 1 - 3
src/Symfony/Component/DomCrawler/Crawler.php

@@ -447,9 +447,7 @@ class Crawler extends \SplObjectStorage
      */
     public function extract($attributes)
     {
-        if (!is_array($attributes)) {
-            $attributes = array($attributes);
-        }
+        $attributes = (array) $attributes;
 
         $data = array();
         foreach ($this as $node) {

+ 2 - 2
src/Symfony/Component/DomCrawler/Field/ChoiceFormField.php

@@ -115,8 +115,8 @@ class ChoiceFormField extends FormField
                 throw new \InvalidArgumentException(sprintf('Input "%s" cannot take "%s" as a value (possible values: %s).', $this->name, $value, implode(', ', $this->options)));
             }
 
-            if ($this->multiple && !is_array($value)) {
-                $value = array($value);
+            if ($this->multiple) {
+                $value = (array) $value;
             }
 
             if (is_array($value)) {

+ 1 - 3
src/Symfony/Component/Finder/Finder.php

@@ -327,9 +327,7 @@ class Finder implements \IteratorAggregate
      */
     public function in($dirs)
     {
-        if (!is_array($dirs)) {
-            $dirs = array($dirs);
-        }
+        $dirs = (array) $dirs;
 
         foreach ($dirs as $dir) {
             if (!is_dir($dir)) {

+ 1 - 5
src/Symfony/Component/Form/Extension/Validator/Validator/DelegatingValidator.php

@@ -231,10 +231,6 @@ class DelegatingValidator implements FormValidatorInterface
             $groups = array('Default');
         }
 
-        if (!is_array($groups)) {
-            $groups = array($groups);
-        }
-
-        return $groups;
+        return (array) $groups;
     }
 }

+ 1 - 3
src/Symfony/Component/HttpFoundation/HeaderBag.php

@@ -119,9 +119,7 @@ class HeaderBag
     {
         $key = strtr(strtolower($key), '_', '-');
 
-        if (!is_array($values)) {
-            $values = array($values);
-        }
+        $values = (array) $values;
 
         if (true === $replace || !isset($this->headers[$key])) {
             $this->headers[$key] = $values;

+ 1 - 5
src/Symfony/Component/Templating/Asset/AssetPackage.php

@@ -32,11 +32,7 @@ class AssetPackage implements AssetPackageInterface
         $this->baseUrls = array();
         $this->version = $version;
 
-        if (!is_array($baseUrls)) {
-            $baseUrls = (array) $baseUrls;
-        }
-
-        foreach ($baseUrls as $baseUrl) {
+        foreach ((array) $baseUrls as $baseUrl) {
             $this->baseUrls[] = rtrim($baseUrl, '/');
         }
     }

+ 1 - 5
src/Symfony/Component/Templating/Loader/FilesystemLoader.php

@@ -31,11 +31,7 @@ class FilesystemLoader extends Loader
      */
     public function __construct($templatePathPatterns)
     {
-        if (!is_array($templatePathPatterns)) {
-            $templatePathPatterns = array($templatePathPatterns);
-        }
-
-        $this->templatePathPatterns = $templatePathPatterns;
+        $this->templatePathPatterns = (array) $templatePathPatterns;
     }
 
     /**