Completed
Push — master ( 17312a...d17d72 )
by Mario
03:12
created

GetTimeEntriesStartedInDateRange::constructUrl()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.3332

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 14
ccs 6
cts 9
cp 0.6667
rs 9.4285
cc 3
eloc 7
nc 3
nop 0
crap 3.3332
1
<?php
2
3
namespace Marek\Toggable\API\Http\Request\TimeEntry;
4
5
use Marek\Toggable\API\Http\Request\Request;
6
7
/**
8
 * Class GetTimeEntriesStartedInDateRange
9
 * @package Marek\Toggable\API\Http\Request\TimeEntry
10
 *
11
 * @property-read \DateTime $startDate
12
 * @property-read \DateTime $endDate
13
 */
14
class GetTimeEntriesStartedInDateRange extends Request
15
{
16
    /**
17
     * @var string
18
     */
19
    public $uri = 'time_entries';
20
21
    /**
22
     * @var \DateTime
23
     */
24
    public $startDate;
25
26
    /**
27
     * @var \DateTime
28
     */
29
    public $endDate;
30
31
    /**
32
     * GetTimeEntriesInDateRange constructor.
33
     *
34
     * @param array $properties
35
     */
36 5
    public function __construct(array $properties)
37
    {
38 5
        parent::__construct($properties);
39 5
        $this->constructUrl();
40 5
    }
41
42
    /**
43
     * Constructs query part of URL
44
     */
45 5
    protected function constructUrl()
46
    {
47 5
        if (!$this->startDate instanceof \DateTime) {
48
            return;
49
        }
50
51 5
        if (!$this->endDate instanceof \DateTime) {
52
            $this->endDate = new \DateTime();
53
        }
54
55 5
        $queryString = '?start_date=' . $this->startDate->format('c') . '&end_date=' . $this->endDate->format('c');
56
57 5
        $this->uri = urlencode($this->uri . $queryString);
58 5
    }
59
}
60