Completed
Push — master ( 07f159...bb7259 )
by Sam
03:38
created

StatisticsRequest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 44.44%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
c 2
b 0
f 1
lcom 0
cbo 2
dl 0
loc 60
ccs 4
cts 9
cp 0.4444
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 4
A getInstanceName() 0 4 1
A getTimeInterval() 0 4 1
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 \stdClass  $parameters
37
	 * 
38
	 * @throws MalformedRequestException
39
	 */
40 1
	public function __construct($type, $parameters)
41
	{
42 1
		parent::__construct($type, $parameters);
43
44
		/* @var \stdClass $parameters */
45 1
		if (!isset($parameters->instanceName) || empty($parameters->instanceName))
46 1
			throw new MalformedRequestException('Missing mandatory "instanceName" parameter');
47
48
		$this->_instanceName = $parameters->instanceName;
49
50
		if (isset($parameters->timeInterval))
51
			$this->_timeInterval = $parameters->timeInterval;
52
		else
53
			$this->_timeInterval = self::TIME_INTERVAL_ALL_TIME;
54
	}
55
56
57
	/**
58
	 * @return string
59
	 */
60
	public function getInstanceName()
61
	{
62
		return $this->_instanceName;
63
	}
64
65
66
	/**
67
	 * @return string
68
	 */
69
	public function getTimeInterval()
70
	{
71
		return $this->_timeInterval;
72
	}
73
74
}
75