Semaphoro::getAvailableProcess()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
4
namespace Semaphoro;
5
6
use Semaphoro\Handlers\HandlerInterface;
7
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
61
    {
62 1
        $this->handler->remove($this->processFactory->getProcessKey($process));
63
    }
64
}