Completed
Push — master ( e38edc...acf857 )
by Bram
02:11
created

UserDateField   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCMSFields() 0 10 1
A createField() 0 14 3
1
<?php
2
3
/**
4
 * Class UserTextField
5
 *
6
 * @author Bram de Leeuw
7
 * @package UserTextField
8
 *
9
 * @property string MinDate
10
 * @property string MaxDate
11
 */
12
class UserDateField 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
    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...
15
        'MinDate' => 'Date',
16
        'MaxDate' => 'Date'
17
    );
18
19
    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...
20
    {
21
        $fields = parent::getCMSFields();
22
        $fields->addFieldsToTab('Root.Validation', array(
23
            DateField::create('MinDate', _t('UserDateField.MinDate', 'Minimum required date'))->setConfig('showcalendar', true),
24
            DateField::create('MaxDate', _t('UserDateField.MaxDate', 'Maximum required date'))->setConfig('showcalendar', true)
25
        ));
26
27
        return $fields;
28
    }
29
30
    /**
31
     * Create a default text field
32
     *
33
     * @param string $fieldName
34
     * @param null   $defaultValue
35
     *
36
     * @return TextField
37
     */
38
    public function createField($fieldName, $defaultValue = null)
39
    {
40
        $dateField = DateField::create($fieldName, $this->Title, $defaultValue);
41
42
        if ($this->MinDate) {
43
            $dateField->setConfig('min', $this->dbObject('MinDate')->Format('Y-m-d'));
44
        }
45
46
        if ($this->MaxDate) {
47
            $dateField->setConfig('max', $this->dbObject('MaxDate')->Format('Y-m-d'));
48
        }
49
50
        return $dateField;
51
    }
52
}
53