InvalidStateTransitionException   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getJob() 0 3 1
A getAllowedStates() 0 3 1
A __construct() 0 9 2
A getNewState() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\SyliusSchedulerPlugin\Exception;
6
7
use Setono\SyliusSchedulerPlugin\Model\JobInterface;
8
9
class InvalidStateTransitionException extends \InvalidArgumentException
10
{
11
    /**
12
     * @var JobInterface
13
     */
14
    private $job;
15
16
    /**
17
     * @var string
18
     */
19
    private $newState;
20
21
    /**
22
     * @var array
23
     */
24
    private $allowedStates;
25
26
    public function __construct(JobInterface $job, string $newState, array $allowedStates = [])
27
    {
28
        $msg = sprintf('The Job(id = %d) cannot change from "%s" to "%s". Allowed transitions: ', $job->getId(), $job->getState(), $newState);
29
        $msg .= count($allowedStates) > 0 ? '"' . implode('", "', $allowedStates) . '"' : '#none#';
30
        parent::__construct($msg);
31
32
        $this->job = $job;
33
        $this->newState = $newState;
34
        $this->allowedStates = $allowedStates;
35
    }
36
37
    /**
38
     * @return JobInterface
39
     */
40
    public function getJob(): JobInterface
41
    {
42
        return $this->job;
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function getNewState(): string
49
    {
50
        return $this->newState;
51
    }
52
53
    /**
54
     * @return array
55
     */
56
    public function getAllowedStates(): array
57
    {
58
        return $this->allowedStates;
59
    }
60
}
61