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 string $_fraseNumero;
13
14
    private string $_valorNumero;
15
16
    private string $_valorTexto;
17
18 5
    public function __construct(string $frase, string $valor, FrasesValidas $frasesValidas)
19
    {
20 5
        $this->_frasesValidas = $frasesValidas;
21 5
        $this->_fraseNumero = $this->setFrase($frase);
22 4
        $this->_valorNumero = $this->setValor($valor);
23 3
    }
24
25 1
    public function fraseNumero(): string
26
    {
27 1
        return $this->_fraseNumero;
28
    }
29
30 1
    public function valorTexto(): string
31
    {
32 1
        return $this->_valorTexto;
33
    }
34
35 2
    public function valorNumero(): string
36
    {
37 2
        return $this->_valorNumero;
38
    }
39
40 5
    private function setFrase(string $frase): string
41
    {
42 5
        if (!array_key_exists($frase, $this->_frasesValidas->frases)) {
43 1
            throw new Exception("Error la frase no exise");
44
        }
45
46 4
        return $frase;
47
    }
48
49 4
    private function setValor(string $valor): string
50
    {
51 4
        if (array_key_exists($valor, $this->_frasesValidas->frases[$this->_fraseNumero])) {
52 3
            $this->_valorTexto = $this->_frasesValidas->frases[$this->_fraseNumero][$valor];
53 3
            return $valor;
54
        }
55
56 2
        if (in_array($valor, $this->_frasesValidas->frases[$this->_fraseNumero])) {
57 1
            $this->_valorTexto = $valor;
58 1
            return (string) array_search($valor, $this->_frasesValidas->frases[$this->_fraseNumero]);
59
        }
60
61 1
        throw new Exception("Error en el valor de la frase");
62
    }
63
}
64