Total Complexity | 7 |
Total Lines | 32 |
Duplicated Lines | 0 % |
Coverage | 93.75% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | class VerificarPorRecurso implements VerificarPermisosInterface |
||
11 | { |
||
12 | private array $_datos; |
||
13 | |||
14 | 3 | public function __construct(array $datosPorRol) |
|
15 | { |
||
16 | 3 | $this->_datos = $this->setDatos($datosPorRol); |
|
17 | 2 | } |
|
18 | |||
19 | 2 | public function verificar(string $rol, string $recursoSolicitado): void |
|
20 | { |
||
21 | 2 | $this->existeElRecurso($recursoSolicitado); |
|
22 | |||
23 | 1 | if (!in_array($rol, $this->_datos[$recursoSolicitado])) { |
|
24 | 1 | throw new NoTieneAutorizacionException("No tiene autorización"); |
|
25 | } |
||
26 | } |
||
27 | |||
28 | 2 | public function existeElRecurso(string $recursoSolicitado): void |
|
29 | { |
||
30 | 2 | if (!array_key_exists($recursoSolicitado, $this->_datos)) { |
|
31 | 1 | throw new ElRecursoNoExisteEnLosDatosDeVerificacionException("El recurso no está especificado en los datos, no se puede verificar"); |
|
32 | } |
||
33 | 1 | } |
|
34 | |||
35 | 3 | private function setDatos(array $array): array |
|
42 | } |
||
43 | } |
||
44 |