NumericReadonlyField   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 12
c 1
b 1
f 0
dl 0
loc 46
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getSuffix() 0 3 1
A Value() 0 10 3
A setSuffix() 0 4 1
A performReadonlyTransformation() 0 3 1
1
<?php
2
3
namespace LeKoala\FormElements;
4
5
use SilverStripe\Forms\ReadonlyField;
6
7
/**
8
 * Better read only field for numeric fields
9
 */
10
class NumericReadonlyField extends ReadonlyField
11
{
12
    protected $suffix =  '';
13
14
    /**
15
     * @return mixed|string
16
     */
17
    public function Value()
18
    {
19
        $value = $this->dataValue();
20
        if (!$value) {
21
            $value = 0;
22
        }
23
        if ($this->suffix) {
24
            $value .= $this->suffix;
25
        }
26
        return $value;
27
    }
28
29
    /**
30
     * Get the value of suffix
31
     * @return mixed
32
     */
33
    public function getSuffix()
34
    {
35
        return $this->suffix;
36
    }
37
38
    /**
39
     * Set the value of suffix
40
     *
41
     * @param mixed $suffix
42
     * @return $this
43
     */
44
    public function setSuffix($suffix)
45
    {
46
        $this->suffix = $suffix;
47
        return $this;
48
    }
49
50
    /**
51
     * This already is a readonly field.
52
     */
53
    public function performReadonlyTransformation()
54
    {
55
        return clone $this;
56
    }
57
}
58