getViewValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * @author  Mohamed Alsharaf <[email protected]>
5
 */
6
class EditableFieldCheckboxGroupExtension extends DataExtension
7
{
8
    /**
9
     * Get field value that is suitable for the view template file.
10
     *
11
     * @return ArrayList
12
     */
13 1
    public function getViewValue()
14
    {
15 1
        $values = explode(',', $this->owner->Value);
16 1
        $value  = new ArrayList();
17
18
        array_walk($values, function ($item) use ($value) {
19 1
            $value->push(['name' => $item]);
20 1
        });
21
22 1
        return $value;
23
    }
24
25
    /**
26
     * Get string value of a field.
27
     *
28
     * @return null|string
29
     */
30 1
    public function getValueAsString()
31
    {
32 1
        $return = '';
33
34 1
        $this->getViewValue()->each(function (ArrayData $item) use (&$return) {
35 1
            if ($return) {
36 1
                $return .= ', ';
37 1
            }
38 1
            $return .= $item->getField('name');
39 1
        });
40
41 1
        return $return;
42
    }
43
}
44