ProcessFactory::createFromKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Semaphoro;
4
5
6
class ProcessFactory
7
{
8
    /**
9
     * @param string $rangeName
10
     * @param bool $isReprocess
11
     * @return ProcessInterface
12
     */
13 4
    public function createFromKey(string $rangeName, bool $isReprocess = false): ProcessInterface
14
    {
15 4
        list($firstNumber, $lastNumber) = $this->extractNumbers($rangeName);
16
17 4
        return new Process($firstNumber, $lastNumber, $isReprocess);
0 ignored issues
show
Bug introduced by
$lastNumber of type string is incompatible with the type integer expected by parameter $end of Semaphoro\Process::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

17
        return new Process($firstNumber, /** @scrutinizer ignore-type */ $lastNumber, $isReprocess);
Loading history...
Bug introduced by
$firstNumber of type string is incompatible with the type integer expected by parameter $start of Semaphoro\Process::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

17
        return new Process(/** @scrutinizer ignore-type */ $firstNumber, $lastNumber, $isReprocess);
Loading history...
18
    }
19
20
    /**
21
     * @param $rangeNameWithoutPrefix
22
     * @return array
23
     */
24 4
    private function extractNumbers($rangeNameWithoutPrefix): array
25
    {
26 4
        return explode('_', $rangeNameWithoutPrefix);
27
    }
28
29
    /**
30
     * @param ProcessInterface $process
31
     * @return string
32
     */
33 3
    public function getProcessKey(ProcessInterface $process): string
34
    {
35 3
        return sprintf('%s_%s', $process->getStart(), $process->getEnd());
36
    }
37
}
38