EntryWithVigenciasTrait::vigenteAhora()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\SatCatalogos\Common;
6
7
use PhpCfdi\SatCatalogos\Exceptions\SatCatalogosLogicException;
8
9
trait EntryWithVigenciasTrait
10
{
11
    /** @var int */
12
    private $vigenteDesde;
13
14
    /** @var int */
15
    private $vigenteHasta;
16
17 297
    protected function setUpVigencias(int $vigenteDesde, int $vigenteHasta): void
18
    {
19 297
        if ($vigenteDesde < 0) {
20 2
            throw new SatCatalogosLogicException('El campo vigente desde no puede ser menor a cero');
21
        }
22 295
        if ($vigenteHasta < 0) {
23 2
            throw new SatCatalogosLogicException('El campo vigente hasta no puede ser menor a cero');
24
        }
25 293
        $this->vigenteDesde = $vigenteDesde;
26 293
        $this->vigenteHasta = $vigenteHasta;
27
    }
28
29 84
    public function vigenteDesde(): int
30
    {
31 84
        return $this->vigenteDesde;
32
    }
33
34 84
    public function vigenteHasta(): int
35
    {
36 84
        return $this->vigenteHasta;
37
    }
38
39 4
    public function vigenteEn(int $timestamp): bool
40
    {
41 4
        if (0 !== $this->vigenteDesde && $timestamp < $this->vigenteDesde) {
42 3
            return false;
43
        }
44 4
        if (0 !== $this->vigenteHasta && $timestamp > $this->vigenteHasta) {
45 3
            return false;
46
        }
47 4
        return true;
48
    }
49
50 1
    public function vigenteAhora(): bool
51
    {
52 1
        return $this->vigenteEn(time());
53
    }
54
}
55