Completed
Pull Request — master (#150)
by Arnaud
05:49 queued 01:55
created

AutoField::render()   B

Complexity

Conditions 8
Paths 9

Size

Total Lines 29
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 15
c 1
b 0
f 0
nc 9
nop 1
dl 0
loc 29
rs 8.4444
1
<?php
2
3
namespace LAG\AdminBundle\Field;
4
5
use Doctrine\Common\Collections\Collection;
6
7
class AutoField extends AbstractField
8
{
9
    public function render($value = null): string
10
    {
11
        if (null === $value) {
12
            return '';
13
        }
14
15
        if (is_string($value)) {
16
            return $value;
17
        }
18
19
        if (is_array($value)) {
20
            return implode(',', $value);
21
        }
22
23
        if (is_object($value)) {
24
            if (method_exists($value, '__toString')) {
25
                return (string) $value;
26
            } else {
27
                if ($value instanceof Collection) {
28
                    $value = $value->toArray();
29
                }
30
31
                if (is_array($value)) {
32
                    return implode(',', $value);
33
                }
34
            }
35
        }
36
37
        return '';
38
    }
39
}
40