| Total Complexity | 10 |
| Total Lines | 101 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php declare(strict_types=1); |
||
| 7 | class PreguntaUno implements PreguntaInterface |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * |
||
| 11 | * @var array |
||
| 12 | */ |
||
| 13 | private array $_valores; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * |
||
| 17 | * @var string |
||
| 18 | */ |
||
| 19 | private string $_valor; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | private string $_texto; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | private string $_numero; |
||
| 32 | |||
| 33 | |||
| 34 | /** |
||
| 35 | * |
||
| 36 | * @param string $valor |
||
| 37 | */ |
||
| 38 | 11 | public function __construct(string $valor, array $valoresPermitidos) |
|
| 39 | { |
||
| 40 | 11 | $this->_valores = $valoresPermitidos; |
|
| 41 | 11 | $this->_valor = $this->setValor($valor); |
|
| 42 | 11 | $this->_texto = $this->valorTexto(); |
|
| 43 | 11 | $this->_numero = $this->valorNumero(); |
|
| 44 | 11 | } |
|
| 45 | |||
| 46 | /** |
||
| 47 | * |
||
| 48 | * @return string |
||
| 49 | */ |
||
| 50 | 4 | public function texto(): string |
|
| 51 | { |
||
| 52 | 4 | return $this->_texto; |
|
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * |
||
| 57 | * @return string |
||
| 58 | */ |
||
| 59 | 11 | public function numero(): string |
|
| 60 | { |
||
| 61 | 11 | return $this->_numero; |
|
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * |
||
| 66 | * @return string |
||
| 67 | */ |
||
| 68 | 11 | private function valorTexto(): string |
|
| 69 | { |
||
| 70 | 11 | if (is_numeric($this->_valor)) { |
|
| 71 | 11 | return $this->_valores[$this->_valor]; |
|
| 72 | } |
||
| 73 | |||
| 74 | 1 | return $this->_valor; |
|
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * |
||
| 79 | * @return string |
||
| 80 | */ |
||
| 81 | 11 | private function valorNumero(): string |
|
| 82 | { |
||
| 83 | 11 | if (!is_numeric($this->_valor)) { |
|
| 84 | 1 | return (string) array_search($this->_valor, $this->_valores); |
|
| 85 | } |
||
| 86 | |||
| 87 | 11 | return $this->_valor; |
|
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Define si lo que recibió la clase es el valor número aceptado o texto |
||
| 92 | * |
||
| 93 | * @param string $string |
||
| 94 | * |
||
| 95 | * @return string |
||
| 96 | */ |
||
| 97 | 11 | private function setValor(string $string): string |
|
| 108 | } |
||
| 109 | } |
||
| 110 |