VerificarPorRol   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 22
ccs 11
cts 11
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A verificar() 0 6 2
A __construct() 0 3 1
A existeElRol() 0 4 2
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