| Total Complexity | 7 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | class VerificarPorRol implements VerificarPermisosInterface |
||
| 11 | { |
||
| 12 | private array $_datos; |
||
| 13 | |||
| 14 | 11 | public function __construct(array $datosPorRol) |
|
| 15 | { |
||
| 16 | 11 | $this->_datos = $this->setDatos($datosPorRol); |
|
| 17 | 11 | } |
|
| 18 | |||
| 19 | 11 | public function verificar(string $rol, string $recursoSolicitado): void |
|
| 20 | { |
||
| 21 | 11 | $this->existeElRol($rol); |
|
| 22 | |||
| 23 | 11 | if (!in_array($recursoSolicitado, $this->_datos[$rol])) { |
|
| 24 | 1 | throw new NoTieneAutorizacionException("No tiene autorización"); |
|
| 25 | } |
||
| 26 | 11 | } |
|
| 27 | |||
| 28 | 11 | public function existeElRol(string $rol): void |
|
| 29 | { |
||
| 30 | 11 | 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 | 11 | } |
|
| 34 | |||
| 35 | 11 | private function setDatos(array $array): array |
|
| 42 | } |
||
| 43 | } |
||
| 44 |