VerificarPorRol::verificar()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
namespace src;
4
5
use src\excepciones\ElRolNoExisteEnLosDatosDeVerificacionException;
6
use src\excepciones\LosDatosParaVerificarAutorizacionEstanVaciosException;
7
use src\excepciones\NoTieneAutorizacionException;
8
use src\interfaces\VerificarPermisosInterface;
9
10
class VerificarPorRol implements VerificarPermisosInterface
11
{
12
    private array $_datos;
13
14 14
    public function __construct(DatosDeConfiguracion $datosPorRol)
15
    {
16 14
        $this->_datos = $datosPorRol->datos();
17 14
    }
18
19 14
    public function verificar(string $rol, string $recursoSolicitado): void
20
    {
21 14
        $this->existeElRol($rol);
22
23 14
        if (!in_array($recursoSolicitado, $this->_datos[$rol])) {
24 1
            throw new NoTieneAutorizacionException("No tiene autorización");
25
        }
26 14
    }
27
28 14
    private function existeElRol(string $rol): void
29
    {
30 14
        if (!array_key_exists($rol, $this->_datos)) {
31 1
            throw new ElRolNoExisteEnLosDatosDeVerificacionException("El rol no está especificado en los datos, no se puede verificar");
32
        }
33 14
    }
34
}
35