LeftOrRight   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 50
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A Nice() 0 4 2
A saveInto() 0 9 3
A scaffoldFormField() 0 11 1
A scaffoldSearchField() 0 13 1
1
<?php
2
3
4
5
class LeftOrRight extends Boolean
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
6
{
7
    public function Nice()
8
    {
9
        return ($this->value) ? _t('FalseIsLeftTrueIsRightDBField.YESANSWER', 'Right') : _t('FalseIsLeftTrueIsRightDBField.NOANSWER', 'Left');
10
    }
11
    //
12
    // public function NiceAsBoolean() {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
13
    //     return ($this->value) ? 'true' : 'false';
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
14
    // }
15
16
    /**
17
     * Saves this field to the given data object.
18
     */
19
    public function saveInto($dataObject)
20
    {
21
        $fieldName = $this->name;
22
        if ($fieldName) {
23
            $dataObject->$fieldName = ($this->value) ? 1 : 0;
24
        } else {
25
            user_error("DBField::saveInto() Called on a nameless '$this->class' object", E_USER_ERROR);
26
        }
27
    }
28
29
    public function scaffoldFormField($title = null, $params = null)
30
    {
31
        return new OptionSetField(
32
            $this->name,
33
            $title,
34
            [
35
                0 => 'Left',
36
                1 => 'Right'
37
            ]
38
        );
39
    }
40
41
    public function scaffoldSearchField($title = null)
42
    {
43
        $anyText = _t('FalseIsLeftTrueIsRightDBField.ANY', 'Any');
44
        $source = array(
45
            0 => _t('FalseIsLeftTrueIsRightDBField.NOANSWER', 'Left'),
46
            1 => _t('FalseIsLeftTrueIsRightDBField.YESANSWER', 'Right')
47
        );
48
49
        $field = new DropdownField($this->name, $title, $source);
50
        $field->setEmptyString("($anyText)");
51
        
52
        return $field;
53
    }
54
}
55