Completed
Branch master (01610a)
by Arnaud
06:29
created

Count   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 6
c 1
b 1
f 0
lcom 1
cbo 2
dl 0
loc 39
ccs 0
cts 24
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 12 3
A configureOptions() 0 6 1
A setOptions() 0 4 1
A getType() 0 4 1
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