|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=0); |
|
4
|
|
|
|
|
5
|
|
|
namespace MartinGeorgiev\Model; |
|
6
|
|
|
|
|
7
|
|
|
use MartinGeorgiev\Utils\MathUtils; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @implements RangeInterface<float|int> |
|
11
|
|
|
*/ |
|
12
|
|
|
class ArithmeticRange extends BaseRange |
|
13
|
|
|
{ |
|
14
|
|
|
public function __construct( |
|
15
|
|
|
public null|float|int $lower, |
|
16
|
|
|
public null|float|int $upper, |
|
17
|
|
|
public bool $lowerInclusive = true, |
|
18
|
|
|
public bool $upperInclusive = false, |
|
19
|
|
|
) { |
|
20
|
|
|
// Void |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function __toString(): string |
|
24
|
|
|
{ |
|
25
|
|
|
if (null !== $this->lower && $this->lower === $this->upper && !$this->lowerInclusive && !$this->upperInclusive) { |
|
26
|
|
|
return 'empty'; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
return \sprintf( |
|
30
|
|
|
'%s%s,%s%s', |
|
31
|
|
|
$this->lowerInclusive ? '[' : '(', |
|
32
|
|
|
$this->lower, |
|
33
|
|
|
$this->upper, |
|
34
|
|
|
$this->upperInclusive ? ']' : ')', |
|
35
|
|
|
); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function contains(mixed $target): bool |
|
39
|
|
|
{ |
|
40
|
|
|
return MathUtils::inRange($target, $this->lower, $this->upper, $this->lowerInclusive, $this->upperInclusive); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @see https://www.postgresql.org/docs/current/rangetypes.html#RANGETYPES-INFINITE |
|
45
|
|
|
*/ |
|
46
|
|
|
public static function createFromString(string $value): self |
|
47
|
|
|
{ |
|
48
|
|
|
if (!\preg_match('/([\[(])(.*),(.*)([])])/', $value, $matches)) { |
|
49
|
|
|
throw new \RuntimeException('Unexpected value: '.$value); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
$startParenthesis = $matches[1]; |
|
53
|
|
|
$startsAtString = \trim($matches[2], '"'); |
|
54
|
|
|
$endsAtString = \trim($matches[3], '"'); |
|
55
|
|
|
$endParenthesis = $matches[4]; |
|
56
|
|
|
|
|
57
|
|
|
if (\in_array($startsAtString, ['infinity', '-infinity', ''], true)) { |
|
58
|
|
|
$startsAt = null; |
|
59
|
|
|
} else { |
|
60
|
|
|
$startsAt = MathUtils::stringToNumber($startsAtString); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
if (\in_array($endsAtString, ['infinity', '-infinity', ''], true)) { |
|
64
|
|
|
$endsAt = null; |
|
65
|
|
|
} else { |
|
66
|
|
|
$endsAt = MathUtils::stringToNumber($endsAtString); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$startInclusive = '[' === $startParenthesis; |
|
70
|
|
|
$endInclusive = ']' === $endParenthesis; |
|
71
|
|
|
|
|
72
|
|
|
return new NumRange($startsAt, $endsAt, $startInclusive, $endInclusive); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths