InputMaskDateField   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setValue() 0 8 2
A __construct() 0 9 1
1
<?php
2
3
namespace LeKoala\FormElements;
4
5
/**
6
 * Format date field using ISO value
7
 *
8
 * Locale conversion cannot be done by InputMask and should be provided by a third party service
9
 *
10
 * @link https://robinherbots.github.io/Inputmask/#/documentation/datetime
11
 */
12
class InputMaskDateField extends InputMaskDateTimeField
13
{
14
    public function __construct($name, $title = null, $value = null)
15
    {
16
        parent::__construct($name, $title, $value);
17
18
        $format = self::getDefaultDateFormat();
19
        $this->setInputFormat($format);
20
        $this->setPlaceholder($format);
21
        // use ISO date format when unmasking to ensure proper data storage in the db
22
        $this->setOutputFormat('yyyy-mm-dd');
23
    }
24
25
    public function setValue($value, $data = null)
26
    {
27
        // Normalize input value according to our format
28
        if ($value) {
29
            $value = date(self::convertDateFormatToPhp(self::getDefaultDateFormat()), strtotime($value));
30
        }
31
        $this->value = $value;
32
        return $this;
33
    }
34
}
35