ConfigurablePageFieldExtension   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 56
ccs 9
cts 11
cp 0.8182
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A canEdit() 0 4 1
A getViewValue() 0 12 2
A getValueAsString() 0 4 1
A getViewFieldName() 0 4 1
1
<?php
2
3
/**
4
 * ConfigurablePageFieldExtension is an extension class that adds extra methods to the EditableField classes.
5
 *
6
 * @author  Mohamed Alsharaf <[email protected]>
7
 */
8
class ConfigurablePageFieldExtension extends DataExtension
9
{
10
    private static $belongs_many_many = [
11
        'Parents' => 'ConfigurablePage',
12
    ];
13
14
    /**
15
     * Get field value that is suitable for the view template file.
16
     *
17
     * @return object|false|string
18
     */
19 2
    public function getViewValue()
20
    {
21 2
        $class = $this->owner;
22
23
        // Header field only used in page type
24 2
        if ($class instanceof Moo_EditableFieldHeading) {
25 1
            return false;
26
        }
27
28
        // Default return string
29 1
        return (string) $this->owner->Value;
30
    }
31
32
    /**
33
     * Get string value of a field.
34
     *
35
     * @return null|string
36
     */
37 1
    public function getValueAsString()
38
    {
39 1
        return (string) $this->owner->Value;
40
    }
41
42
    /**
43
     * Format the field Title to be suitable as a variable in template.
44
     *
45
     * @return string
46
     */
47 2
    public function getViewFieldName()
48
    {
49 2
        return $this->owner->Name;
50
    }
51
52
    /**
53
     * Editable field can only be changed if is not part of a group.
54
     *
55
     * @param null $member
56
     *
57
     * @return bool
58
     */
59
    public function canEdit($member = null)
60
    {
61
        return (int) $this->owner->Group === 0;
62
    }
63
}
64