Semaphoro   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 15
dl 0
loc 55
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A remove() 0 3 1
A __construct() 0 4 1
A setUnprocessed() 0 3 1
A getAvailableProcess() 0 9 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
}