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

ArrayField::render()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4.25

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 4
eloc 7
c 1
b 0
f 1
nc 5
nop 1
dl 0
loc 15
ccs 6
cts 8
cp 0.75
crap 4.25
rs 10
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