Completed
Push — master ( 2e6749...8bcd18 )
by Sam
02:24
created

StatisticsRequest::getTimeInterval()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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_INTERVAL_ALL_TIME   = 'allTime';
19
	const TIME_INTERVAL_LAST_MONTH = 'lastMonth';
20
21
	/**
22
	 * @var string
23
	 */
24
	private $_instanceName;
25
26
	/**
27
	 * @var string
28
	 */
29
	private $_timeInterval;
30
31
32
	/**
33
	 * StatisticsRequest constructor.
34
	 *
35
	 * @param string $type
36
	 * @param mixed  $parameters
37
	 */
38
	public function __construct($type, $parameters)
39
	{
40
		parent::__construct($type, $parameters);
41
42
		/* @var \stdClass $parameters */
43
		if (!isset($parameters->instanceName) || empty($parameters->instanceName))
44
			throw new MalformedRequestException('Missing mandatory "instanceName" parameter');
45
46
		$this->_instanceName = $parameters->instanceName;
47
48
		if (isset($parameters->timeInterval))
49
			$this->_timeInterval = $parameters->timeInterval;
50
		else
51
			$this->_timeInterval = self::TIME_INTERVAL_ALL_TIME;
52
	}
53
54
55
	/**
56
	 * @return string
57
	 */
58
	public function getInstanceName()
59
	{
60
		return $this->_instanceName;
61
	}
62
63
64
	/**
65
	 * @return string
66
	 */
67
	public function getTimeInterval()
68
	{
69
		return $this->_timeInterval;
70
	}
71
72
}
73