aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Form
diff options
context:
space:
mode:
authorKévin Gomez <contact@kevingomez.fr>2015-10-12 21:43:24 +0200
committerKévin Gomez <contact@kevingomez.fr>2015-11-11 16:23:49 +0100
commit003fa77438b13ceb9ceda245d6ad257801453d27 (patch)
tree6c7d375a3de3efd5c98f312a717fa02b6a97d19e /src/Wallabag/CoreBundle/Form
parentf530f7f5e19eb611ba79856d3ca3b7aebd2af367 (diff)
downloadwallabag-003fa77438b13ceb9ceda245d6ad257801453d27.tar.gz
wallabag-003fa77438b13ceb9ceda245d6ad257801453d27.tar.zst
wallabag-003fa77438b13ceb9ceda245d6ad257801453d27.zip
Add tests for the StringToListTransformer class
Diffstat (limited to 'src/Wallabag/CoreBundle/Form')
-rw-r--r--src/Wallabag/CoreBundle/Form/DataTransformer/StringToListTransformer.php14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/Wallabag/CoreBundle/Form/DataTransformer/StringToListTransformer.php b/src/Wallabag/CoreBundle/Form/DataTransformer/StringToListTransformer.php
index 332a91b8..23488d35 100644
--- a/src/Wallabag/CoreBundle/Form/DataTransformer/StringToListTransformer.php
+++ b/src/Wallabag/CoreBundle/Form/DataTransformer/StringToListTransformer.php
@@ -6,10 +6,20 @@ use Doctrine\Common\Persistence\ObjectManager;
6use Symfony\Component\Form\DataTransformerInterface; 6use Symfony\Component\Form\DataTransformerInterface;
7use Symfony\Component\Form\Exception\TransformationFailedException; 7use Symfony\Component\Form\Exception\TransformationFailedException;
8 8
9/**
10 * Transforms a comma-separated list to a proper PHP array.
11 * Example: the string "foo, bar" will become the array ["foo", "bar"]
12 */
9class StringToListTransformer implements DataTransformerInterface 13class StringToListTransformer implements DataTransformerInterface
10{ 14{
15 /**
16 * @var string
17 */
11 private $separator; 18 private $separator;
12 19
20 /**
21 * @param string $separator The separator used in the list.
22 */
13 public function __construct($separator = ',') 23 public function __construct($separator = ',')
14 { 24 {
15 $this->separator = $separator; 25 $this->separator = $separator;
@@ -40,10 +50,10 @@ class StringToListTransformer implements DataTransformerInterface
40 */ 50 */
41 public function reverseTransform($string) 51 public function reverseTransform($string)
42 { 52 {
43 if (!$string) { 53 if ($string === null) {
44 return null; 54 return null;
45 } 55 }
46 56
47 return array_filter(array_map('trim', explode($this->separator, $string))); 57 return array_values(array_filter(array_map('trim', explode($this->separator, $string))));
48 } 58 }
49} 59}