Completed
Push — master ( 16b026...023b4f )
by Sam
02:59
created

StatisticsRequest::getTimeInterval()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Jalle19\StatusManager\Message\Request;
4
5
use Jalle19\StatusManager\Exception\MalformedRequestException;
6
use Jalle19\StatusManager\Message\AbstractMessage;
7
8
/**
9
 * Base class for all requests for statistics
10
 *
11
 * @package   Jalle19\StatusManager\Message\Request
12
 * @copyright Copyright &copy; Sam Stenvall 2016-
13
 * @license   https://www.gnu.org/licenses/gpl.html The GNU General Public License v2.0
14
 */
15
abstract class StatisticsRequest extends AbstractMessage
16
{
17
18
	const TIME_FRAME_ALL_TIME   = 'allTime';
19
	const TIME_FRAME_LAST_MONTH = 'lastMonth';
20
	const TIME_FRAME_LAST_WEEK  = 'lastWeek';
21
	const TIME_FRAME_LAST_DAY   = 'lastDay';
22
23
	/**
24
	 * @var string
25
	 */
26
	private $_instanceName;
27
28
	/**
29
	 * @var string
30
	 */
31
	private $_timeFrame;
32
33
34
	/**
35
	 * StatisticsRequest constructor.
36
	 *
37
	 * @param string    $type
38
	 * @param \stdClass $parameters
39
	 *
40
	 * @throws MalformedRequestException
41
	 */
42 1
	public function __construct($type, $parameters)
43
	{
44 1
		parent::__construct($type, $parameters);
45
46
		/* @var \stdClass $parameters */
47 1
		if (!isset($parameters->instanceName) || empty($parameters->instanceName))
48 1
			throw new MalformedRequestException('Missing mandatory "instanceName" parameter');
49
50
		$this->_instanceName = $parameters->instanceName;
51
52
		if (isset($parameters->timeFrame))
53
			$this->_timeFrame = $parameters->timeFrame;
54
		else
55
			$this->_timeFrame = self::TIME_FRAME_ALL_TIME;
56
	}
57
58
59
	/**
60
	 * @return string
61
	 */
62
	public function getInstanceName()
63
	{
64
		return $this->_instanceName;
65
	}
66
67
68
	/**
69
	 * @return string
70
	 */
71
	public function getTimeFrame()
72
	{
73
		return $this->_timeFrame;
74
	}
75
76
}
77