]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Form/DataTransformer/StringToListTransformer.php
CS
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Form / DataTransformer / StringToListTransformer.php
index 332a91b87ac717797d03f65cf458a2ee1b63706f..57dbc95ed9bc83f5b51a67f4da4841678ec493bb 100644 (file)
@@ -2,14 +2,22 @@
 
 namespace Wallabag\CoreBundle\Form\DataTransformer;
 
-use Doctrine\Common\Persistence\ObjectManager;
 use Symfony\Component\Form\DataTransformerInterface;
-use Symfony\Component\Form\Exception\TransformationFailedException;
 
+/**
+ * Transforms a comma-separated list to a proper PHP array.
+ * Example: the string "foo, bar" will become the array ["foo", "bar"].
+ */
 class StringToListTransformer implements DataTransformerInterface
 {
+    /**
+     * @var string
+     */
     private $separator;
 
+    /**
+     * @param string $separator The separator used in the list
+     */
     public function __construct($separator = ',')
     {
         $this->separator = $separator;
@@ -34,16 +42,16 @@ class StringToListTransformer implements DataTransformerInterface
     /**
      * Transforms a string to a list.
      *
-     * @param  string $string
+     * @param string $string
      *
      * @return array|null
      */
     public function reverseTransform($string)
     {
-        if (!$string) {
-            return null;
+        if (null === $string) {
+            return;
         }
 
-        return array_filter(array_map('trim', explode($this->separator, $string)));
+        return array_values(array_filter(array_map('trim', explode($this->separator, $string))));
     }
 }