| Total Complexity | 8 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Coverage | 90% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 5 | class ArrayNormalizer extends AbstractNormalizer |
||
| 6 | { |
||
| 7 | /** @var string */ |
||
| 8 | private $delimiter; |
||
| 9 | /** @var StringNormalizer */ |
||
| 10 | private $stringNormalizer; |
||
| 11 | |||
| 12 | 1 | public function __construct(NormalizerInterface $normalizer = null, string $delimiter = ',') |
|
| 13 | { |
||
| 14 | 1 | $this->setDelimiter($delimiter); |
|
| 15 | |||
| 16 | 1 | $this->stringNormalizer = new StringNormalizer(); |
|
| 17 | 1 | $this->stringNormalizer->setTrimCharMask($this->stringNormalizer->getTrimCharMask() . $this->delimiter); |
|
| 18 | |||
| 19 | 1 | parent::__construct($normalizer); |
|
| 20 | 1 | } |
|
| 21 | |||
| 22 | 1 | public function normalize(string $value) |
|
| 25 | } |
||
| 26 | |||
| 27 | 1 | protected function getNormalizedValue(string $value) |
|
| 28 | { |
||
| 29 | 1 | $value = $this->stringNormalizer->normalize($value); |
|
| 30 | 1 | $normalizedValue = \explode($this->delimiter, $value) ?: []; |
|
| 31 | |||
| 32 | 1 | if ($this->normalizer) { |
|
| 33 | 1 | foreach ($normalizedValue as &$part) { |
|
| 34 | 1 | $part = $this->normalizer->normalize($part); |
|
| 35 | } |
||
| 36 | } |
||
| 37 | |||
| 38 | 1 | return $normalizedValue; |
|
| 39 | } |
||
| 40 | |||
| 41 | 1 | public function setDelimiter(string $delimiter): self |
|
| 46 | } |
||
| 47 | |||
| 48 | public function getDelimiter(): string |
||
| 51 | } |
||
| 52 | } |
||
| 53 |