| Total Complexity | 5 | 
| Total Lines | 50 | 
| Duplicated Lines | 0 % | 
| Changes | 0 | ||
| 1 | <?php | ||
| 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 | ||
| 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 | ||
| 59 | } | ||
| 60 | } | ||
| 61 |