GetTimeEntriesStartedInDateRange::getUri()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.4285
cc 3
eloc 7
nc 3
nop 0
crap 3
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
    protected $uri = 'time_entries';
20
21
    /**
22
     * @var \DateTime
23
     */
24
    protected $startDate;
25
26
    /**
27
     * @var \DateTime
28
     */
29
    protected $endDate;
30
31
    /**
32
     * GetTimeEntriesInDateRange constructor.
33
     *
34
     * @param array $properties
35
     */
36 8
    public function __construct(array $properties)
37
    {
38 8
        parent::__construct($properties);
39 8
    }
40
41
    /**
42
     * @inheritdoc
43
     */
44 3
    public function getUri()
45
    {
46 3
        if (!$this->startDate instanceof \DateTime) {
47 1
            return $this->uri;
48
        }
49
50 2
        if (!$this->endDate instanceof \DateTime) {
51 1
            $this->endDate = new \DateTime();
52 1
        }
53
54 2
        $queryString = '?start_date=' . $this->startDate->format('c') . '&end_date=' . $this->endDate->format('c');
55
56 2
        return urlencode($this->uri . $queryString);
57
    }
58
}
59