DateTrait::setDueOn()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Helix\Asana\Base\AbstractEntity;
4
5
use DateTimeInterface;
6
use Helix\Asana\Base\AbstractEntity;
7
8
/**
9
 * Adds date helpers.
10
 *
11
 * @mixin AbstractEntity
12
 *
13
 * @method null|string  getDueOn    () `Y-m-d`
14
 * @method bool         hasDueOn    ()
15
 * @method null|string  getStartOn  () `Y-m-d`
16
 * @method bool         hasStartOn  ()
17
 */
18
trait DateTrait {
19
20
    /**
21
     * @param string $field
22
     * @param null|string|DateTimeInterface $date
23
     * @return $this
24
     */
25
    private function _setYmd (string $field, $date) {
26
        if ($date instanceof DateTimeInterface) {
27
            $date = $date->format('Y-m-d');
28
        }
29
        return $this->_set($field, $date);
30
    }
31
32
    /**
33
     * @param null|string|DateTimeInterface $date
34
     * @return $this
35
     */
36
    public function setDueOn ($date) {
37
        return $this->_setYmd('due_on', $date);
38
    }
39
40
    /**
41
     * @param null|string|DateTimeInterface $date
42
     * @return $this
43
     */
44
    public function setStartOn ($date) {
45
        // Asana says the due date must be present in the request when changing the start date.
46
        $this->setDueOn($this->getDueOn());
47
        return $this->_setYmd('start_on', $date);
48
    }
49
50
}