Completed
Push — master ( 2b45da...60f6b8 )
by Arnaud
16s queued 12s
created

ArrayField   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 86.67%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 13
c 1
b 0
f 1
dl 0
loc 32
ccs 13
cts 15
cp 0.8667
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 15 4
A isSortable() 0 3 1
A configureOptions() 0 7 1
1
<?php
2
3
namespace LAG\AdminBundle\Field;
4
5
use Doctrine\Common\Collections\Collection;
6
use Iterator;
7
use LAG\AdminBundle\Configuration\ActionConfiguration;
8
use Symfony\Component\OptionsResolver\OptionsResolver;
9
10
class ArrayField extends AbstractField
11
{
12 2
    public function configureOptions(OptionsResolver $resolver, ActionConfiguration $actionConfiguration)
13
    {
14
        $resolver
15 2
            ->setDefaults([
16 2
                'glue' => ',',
17
            ])
18 2
            ->setAllowedTypes('glue', 'string')
19
        ;
20 2
    }
21
22 2
    public function isSortable(): bool
23
    {
24 2
        return false;
25
    }
26
27 2
    public function render($value = null): string
28
    {
29 2
        if (null === $value) {
30 2
            return '';
31
        }
32
33 2
        if ($value instanceof Collection) {
34
            $value = $value->toArray();
35
        }
36
37 2
        if ($value instanceof Iterator) {
38
            $value = iterator_to_array($value);
39
        }
40
41 2
        return implode($this->options['glue'], $value);
42
    }
43
}
44