Completed
Push — master ( 60e59a...334051 )
by Adam
06:35
created

Job   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 62
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 2
A getAction() 0 4 1
A getPackage() 0 4 1
1
<?php
2
/**
3
 * Job.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        http://www.ipublikuj.eu
7
 * @author         Adam Kadlec http://www.ipublikuj.eu
8
 * @package        iPublikuj:Packages!
9
 * @subpackage     DependencyResolver
10
 * @since          2.0.0
11
 *
12
 * @date           27.06.16
13
 */
14
15
declare(strict_types = 1);
16
17
namespace IPub\Packages\DependencyResolver;
18
19
use IPub;
20
use IPub\Packages;
21
use IPub\Packages\Entities;
22
use IPub\Packages\Exceptions;
23
24
/**
25
 * Dependency solver job definition
26
 *
27
 * @package        iPublikuj:Packages!
28
 * @subpackage     DependencyResolver
29
 *
30
 * @author         Josef Kříž <[email protected]>
31
 * @author         Adam Kadlec <[email protected]>
32
 */
33
class Job
34
{
35
	/**
36
	 * Define actions
37
	 */
38
	const ACTION_ENABLE = 'enable';
39
	const ACTION_DISABLE = 'disable';
40
41
	/**
42
	 * List of available statuses
43
	 */
44
	const ACTIONS = [
45
		self::ACTION_ENABLE,
46
		self::ACTION_DISABLE,
47
	];
48
49
	/**
50
	 * @var string
51
	 */
52
	private $action;
53
54
	/**
55
	 * @var Entities\IPackage
56
	 */
57
	private $package;
58
59
	/**
60
	 * @param string $action
61
	 * @param Entities\IPackage $package
62
	 *
63
	 * @throws Exceptions\InvalidJobActionException
64
	 */
65
	public function __construct(string $action, Entities\IPackage $package)
66
	{
67
		if (!in_array($action, self::ACTIONS, TRUE)) {
68
			throw new Exceptions\InvalidJobActionException(sprintf(
69
				'Action must be one of "%s". "%s" is given.',
70
				join(', ', self::ACTIONS),
71
				$action
72
			));
73
		}
74
75
		$this->action = $action;
76
		$this->package = $package;
77
	}
78
79
	/**
80
	 * @return string
81
	 */
82
	public function getAction() : string
83
	{
84
		return $this->action;
85
	}
86
87
	/**
88
	 * @return Entities\IPackage
89
	 */
90
	public function getPackage() : Entities\IPackage
91
	{
92
		return $this->package;
93
	}
94
}
95