Completed
Push — 0.3-dev ( 291149...449c2f )
by Arnaud
14:26
created

Count::getType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace LAG\AdminBundle\Field\Field;
4
5
use LAG\AdminBundle\Field\Field;
6
use Symfony\Component\OptionsResolver\OptionsResolver;
7
8
/**
9
 * Count field.
10
 */
11
class Count extends Field
12
{
13
    /**
14
     * String displayed if rendered value is empty (or null or 0).
15
     *
16
     * @var string
17
     */
18
    protected $emptyString;
19
20
    public function render($value)
21
    {
22
        $count = count($value);
23
24
        if ($count > 0 || $this->emptyString === null) {
25
            $render = $count;
26
        } else {
27
            $render = $this->emptyString;
28
        }
29
30
        return $render;
31
    }
32
33
    public function configureOptions(OptionsResolver $resolver)
34
    {
35
        $resolver->setDefaults([
36
            'empty_string' => null,
37
        ]);
38
    }
39
40
    public function setOptions(array $options)
41
    {
42
        $this->emptyString = $options['empty_string'];
43
    }
44
45
    public function getType()
46
    {
47
        return 'count';
48
    }
49
}
50