Passed
Pull Request — master (#32)
by
unknown
02:37
created

TimestampRangeCast   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRangeInstance() 0 3 1
A parseStringRange() 0 6 1
1
<?php
2
3
namespace Belamov\PostgresRange\Casts;
4
5
use Belamov\PostgresRange\Ranges\TimestampRange;
6
7
class TimestampRangeCast extends RangeCast
8
{
9
    /**
10
     * @param  array  $matches
11
     * @return TimestampRange
12
     */
13
    public function getRangeInstance(array $matches): TimestampRange
14
    {
15
        return new TimestampRange($matches[2], $matches[3], $matches[1], $matches[4]);
16
    }
17
18
    /**
19
     * @param  $value
20
     * @return array
21
     */
22
    protected function parseStringRange($value): array
23
    {
24
        $matches = [];
25
        preg_match('/([\[(])\"?([^",]*)\"?,\"?([^",]*)\"?([])])/', $value, $matches);
26
27
        return $matches;
28
    }
29
}
30