DateColumn::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Cocur\Arff\Column;
4
5
/**
6
 * DateColumn
7
 *
8
 * @package   Cocur\Arff\Column
9
 * @author    Florian Eckerstorfer
10
 * @copyright 2015 Florian Eckerstorfer
11
 */
12
class DateColumn extends AbstractColumn
13
{
14
    /**
15
     * @var string
16
     */
17
    protected $dateFormat;
18
19
    /**
20
     * @return string
21
     */
22 1
    public function getDateFormat()
23
    {
24 1
        return $this->dateFormat;
25
    }
26
27
    /**
28
     * @param string $dateFormat
29
     *
30
     * @return DateColumn
31
     */
32 1
    public function setDateFormat($dateFormat)
33
    {
34 1
        $this->dateFormat = $dateFormat;
35
36 1
        return $this;
37
    }
38
39
    /**
40
     * @param string|null $name
41
     * @param string|null $dateFormat
42
     */
43 1
    public function __construct($name = null, $dateFormat = null)
44
    {
45 1
        if ($name !== null) {
46 1
            $this->setName($name);
47
        }
48 1
        $this->dateFormat = $dateFormat;
49 1
    }
50
51
    /**
52
     * @return string
53
     */
54 1
    public function getType()
55
    {
56 1
        return 'date';
57
    }
58
59
    /**
60
     * @return string
61
     */
62 2
    public function render()
63
    {
64 2
        $dateFormat = $this->getDateFormat();
65 2
        if ($dateFormat !== null) {
66 1
            $dateFormat = sprintf(' "%s"', $dateFormat);
67
        }
68
69 2
        return parent::render().$dateFormat;
70
    }
71
}
72