| Total Complexity | 5 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | class Semaphoro |
||
| 9 | { |
||
| 10 | const RANGE_OPEN = 0; |
||
| 11 | const RANGE_IS_REPROCESS = true; |
||
| 12 | const INCREMENT_FIRST_NUMBER = 1; |
||
| 13 | const INCREMENT_LAST_NUMBER = 50; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var HandlerInterface |
||
| 17 | */ |
||
| 18 | private $handler; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var ProcessFactory |
||
| 22 | */ |
||
| 23 | private $processFactory; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Semaphoro constructor. |
||
| 27 | * @param HandlerInterface $handler |
||
| 28 | */ |
||
| 29 | 4 | public function __construct(HandlerInterface $handler) |
|
| 30 | { |
||
| 31 | 4 | $this->handler = $handler; |
|
| 32 | 4 | $this->processFactory = new ProcessFactory(); |
|
| 33 | 4 | } |
|
| 34 | |||
| 35 | /** |
||
| 36 | * @return ProcessInterface |
||
| 37 | */ |
||
| 38 | 2 | public function getAvailableProcess(): ProcessInterface |
|
| 39 | { |
||
| 40 | 2 | if ($openProcessKey = $this->handler->getProcessOpened()) { |
|
| 41 | 1 | return $this->processFactory->createFromKey($openProcessKey, self::RANGE_IS_REPROCESS); |
|
| 42 | } |
||
| 43 | |||
| 44 | 1 | $processKey = $this->handler->createProcessKey(); |
|
| 45 | |||
| 46 | 1 | return $this->processFactory->createFromKey($processKey); |
|
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @param ProcessInterface $process |
||
| 51 | */ |
||
| 52 | 1 | public function setUnprocessed(ProcessInterface $process): void |
|
| 53 | { |
||
| 54 | 1 | $this->handler->setUnprocessedStatus($this->processFactory->getProcessKey($process)); |
|
| 55 | 1 | } |
|
| 56 | |||
| 57 | /** |
||
| 58 | * @param ProcessInterface $process |
||
| 59 | */ |
||
| 60 | 1 | public function remove(ProcessInterface $process): void |
|
| 63 | } |
||
| 64 | } |