Frase::valorTexto()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php declare(strict_types=1);
2
3
namespace src\frases;
4
5
use Exception;
6
use src\interfaces\FraseInterface;
7
8
class Frase implements FraseInterface
9
{
10
    private FrasesValidas $_frasesValidas;
11
12
    private ValoresValidos $_valoresValidos;
13
14
    private string $_fraseTexto;
15
16
    private string $_fraseNumero;
17
18
    private string $_valorNumero;
19
20
    private string $_valorTexto;
21
22 5
    public function __construct(string $frase, string $valor, FrasesValidas $frasesValidas, ValoresValidos $valoresValidos)
23
    {
24 5
        $this->_frasesValidas = $frasesValidas;
25 5
        $this->_valoresValidos = $valoresValidos;
26 5
        $this->_fraseNumero = $this->setFrase($frase);
27 4
        $this->_valorNumero = $this->setValor($valor);
28 3
    }
29
30 1
    public function fraseTexto(): string
31
    {
32 1
        return $this->_fraseTexto;
33
    }
34
35 1
    public function fraseNumero(): string
36
    {
37 1
        return $this->_fraseNumero;
38
    }
39
40 1
    public function valorTexto(): string
41
    {
42 1
        return $this->_valorTexto;
43
    }
44
45 2
    public function valorNumero(): string
46
    {
47 2
        return $this->_valorNumero;
48
    }
49
50 5
    private function setFrase(string $frase): string
51
    {
52 5
        if (!array_key_exists($frase, $this->_frasesValidas->frases)) {
53 1
            throw new Exception("Error la fraser no exise");
54
        }
55
56 4
        $this->_fraseTexto = $this->_frasesValidas->frases[$frase];
57
58 4
        return $frase;
59
    }
60
61 4
    private function setValor(string $valor): string
62
    {
63 4
        if (array_key_exists($valor, $this->_valoresValidos->valores)) {
64 3
            $this->_valorTexto = $this->_valoresValidos->valores[$valor];
65 3
            return $valor;
66
        }
67
68 2
        if (in_array($valor, $this->_valoresValidos->valores)) {
69 1
            $this->_valorTexto = $valor;
70 1
            return (string) array_search($valor, $this->_valoresValidos->valores);
71
        }
72
73 1
        throw new Exception("Error en el valor de la frase");
74
    }
75
}
76