Completed
Push — master ( acf857...572128 )
by Bram
01:57
created

UserNumericField::getCMSFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
/**
4
 * Class UserNumericField
5
 *
6
 * @property int Min
7
 * @property int Max
8
 *
9
 * @author Bram de Leeuw
10
 * @package UserTextField
11
 */
12
class UserNumericField extends Broarm\EventTickets\UserField
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...
13
{
14
    /**
15
     * @var NumericField
16
     */
17
    protected $fieldType = 'NumericField';
18
19
    private static $db = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
20
        'Min' => 'Int',
21
        'Max' => 'Int'
22
    );
23
24
    public function getCMSFields()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
25
    {
26
        $fields = parent::getCMSFields();
27
        $fields->addFieldsToTab('Root.Validation', array(
28
            NumericField::create('Min', _t('UserNumericField.Min', 'Minimum required number')),
29
            NumericField::create('Max', _t('UserNumericField.Max', 'Maximum required number'))
30
        ));
31
32
        return $fields;
33
    }
34
35
    /**
36
     * Create a default text field
37
     *
38
     * @param string $fieldName
39
     * @param null   $defaultValue
40
     *
41
     * @return NumericField|FormField
42
     */
43
    public function createField($fieldName, $defaultValue = null)
44
    {
45
        $numericField = parent::createField($fieldName, $defaultValue);
46
47
        if (!empty($this->Min)) {
48
            $numericField->setAttribute('min', $this->Min);
49
        }
50
51
        if (!empty($this->Max)) {
52
            $numericField->setAttribute('max', $this->Max);
53
        }
54
55
        return $numericField;
56
    }
57
}
58