Completed
Push — master ( ee94bf...c321ed )
by Mohamed
07:15
created

ConfigurablePageFieldExtension::countryFieldValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 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
    public function getViewValue()
20
    {
21
        $class = $this->owner;
22
23
        // Header field only used in page type
24
        if ($class instanceof Moo_EditableFieldHeading) {
0 ignored issues
show
Bug introduced by
The class Moo_EditableFieldHeading does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
25
            return false;
26
        }
27
28
        // Default return string
29
        return (string)$this->owner->Value;
30
    }
31
32
    /**
33
     * Get string value of a field.
34
     *
35
     * @return null|string
36
     */
37
    public function getValueAsString()
38
    {
39
        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
    public function getViewFieldName()
48
    {
49
        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