DiscountCouponSiteTreeDOD_Field   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 35
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B saveInto() 0 27 8
1
<?php
2
3
4
class DiscountCouponSiteTreeDOD_Field extends TreeMultiselectField
5
{
6
7
    /**
8
     *
9
     * TO DO: explain how this works or what it does.
10
     */
11
    public function saveInto(DataObjectInterface $record)
12
    {
13
        if ($this->value !== 'unchanged') {
14
            $items = array();
15
16
            $fieldName = $this->name;
17
18
            if ($this->value) {
19
                $items = preg_split("/ *, */", trim($this->value));
20
            }
21
22
            // Allows you to modify the items on your object before save
23
            $funcName = "onChange$fieldName";
24
            if ($record->hasMethod($funcName)) {
25
                $result = $record->$funcName($items);
26
                if (!$result) {
27
                    return;
28
                }
29
            }
30
            if ($fieldName && ($record->has_many($fieldName) || $record->many_many($fieldName))) {
31
                // Set related records
32
                $record->$fieldName()->setByIDList($items);
33
            } else {
34
                $record->$fieldName = implode(',', $items);
35
            }
36
        }
37
    }
38
}
39