stringifyBoundary()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
nc 2
nop 1
dl 0
loc 7
c 0
b 0
f 0
cc 2
rs 10
1
<?php
2
3
namespace Belamov\PostgresRange\Ranges;
4
5
use DateTimeInterface;
6
7
trait StringifiesBoundariesFromDateTimeInterface
8
{
9
    /**
10
     * @param  DateTimeInterface|string|null  $from
11
     * @param  DateTimeInterface|string|null  $to
12
     * @param  string  $fromBound
13
     * @param  string  $toBound
14
     */
15
    public function __construct($from = null, $to = null, $fromBound = '[', $toBound = ')')
16
    {
17
        $from = $this->stringifyBoundary($from);
18
        $to = $this->stringifyBoundary($to);
19
20
        parent::__construct($from, $to, $fromBound, $toBound);
21
    }
22
23
    /**
24
     * @param  $boundary
25
     * @return string|null
26
     */
27
    protected function stringifyBoundary($boundary): ?string
28
    {
29
        if ($boundary instanceof DateTimeInterface) {
30
            return $boundary->format($this->getBoundaryFormat());
31
        }
32
33
        return $boundary;
34
    }
35
36
    /**
37
     * @return string
38
     */
39
    abstract protected function getBoundaryFormat(): string;
40
}
41