Completed
Pull Request — master (#7)
by
unknown
01:12
created

HtmlLotomania::getDataLive()   F

Complexity

Conditions 18
Paths > 20000

Size

Total Lines 88
Code Lines 56

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 88
rs 2
cc 18
eloc 56
nc 131072
nop 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace LoteriaApi\Consumer\Reader;
4
5
use \DOMDocument;
6
use \DOMNodeList;
7
use \DomXPath;
8
9
class HtmlLotomania extends AbstractReaderHtmlLoteria
10
{
11
    public function getData()
12
    {
13
        $this->numbersNode->setNumberConcurso(0)
14
            ->setDataConcurso(1)
15
            ->setDezenasConcurso([2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21])
16
            ->setArrecadacaoConcurso(22)
17
            ->setTotalGanhadoresPrimeiroPremio(23)
18
            ->setTotalGanhadoresSegundoPremio(26)
19
            ->setTotalGanhadoresTerceiroPremio(27)
20
            ->setValorGanhadoresPrimeiroPremio(31)
21
            ->setValorGanhadoresSegundoPremio(32)
22
            ->setValorGanhadoresTerceiroPremio(33)
23
            ->setValorAcumuladoConcurso(37)
24
            ->setValorEstimadoProximoConcurso(43);
25
26
        parent::loadData($this->numbersNode);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (loadData() instead of getData()). Are you sure this is correct? If so, you might want to change this to $this->loadData().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
27
28
        return $this->data;
29
    }
30
31
        public function getDataLive() {
32
33
        // Instance for query
34
        $finder = new DomXPath($this->domdocument);        
35
36
        // Concurso
37
        $nodes = $finder->query("//div[contains(@class, 'title-bar')]");
38
        $domConcurso = $nodes->item(0);
39
        preg_match('/ ([0-9]{4,}) \((.*?)\)/', $domConcurso->nodeValue, $map);
40
        $nrconcurso = trim($map[1]);
41
42
        // Data
43
        $data = trim($map[2]);
44
45
        // Dezenas
46
        $nodes = $finder->query("//table[contains(@class, 'simple-table')][contains(@class, 'lotomania')]/tr/td");
47
        $dezenas = parent::loadDezenasLive($nodes);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (loadDezenasLive() instead of getDataLive()). Are you sure this is correct? If so, you might want to change this to $this->loadDezenasLive().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
48
49
        // Arrecadacao
50
        $nodes = $finder->query("//div[contains(@class, 'related-box')][contains(@class, 'gray-text')]/p/strong");
51
        $arrecadacao = trim(preg_replace('/[^0-9,\.]/si', '', $nodes->item(7)->nodeValue));
52
53
        // Total ganhadores primeiro premio
54
        $nodes = $finder->query("//div[contains(@class, 'related-box')][contains(@class, 'gray-text')]/p");
55
        preg_match('/([0-9]*?) aposta/', $nodes->item(0)->nodeValue, $map);
56
        $totalGanhadoresPrimeiroPremio = isset($map[1]) ? trim(preg_replace('/[^0-9]/si', '', $map[1])) : "";
57
        $totalGanhadoresPrimeiroPremio = empty($totalGanhadoresPrimeiroPremio) ? 0 : $totalGanhadoresPrimeiroPremio;
58
59
        // Total ganhadores segundo premio
60
        $nodes = $finder->query("//div[contains(@class, 'related-box')][contains(@class, 'gray-text')]/p");
61
        preg_match('/([0-9]*?) aposta/', $nodes->item(1)->nodeValue, $map);
62
        $totalGanhadoresSegundoPremio = isset($map[1]) ? trim(preg_replace('/[^0-9]/si', '', $map[1])) : "";
63
        $totalGanhadoresSegundoPremio = empty($totalGanhadoresSegundoPremio) ? 0 : $totalGanhadoresSegundoPremio;
64
65
        // Total ganhadores terceiro premio
66
        $nodes = $finder->query("//div[contains(@class, 'related-box')][contains(@class, 'gray-text')]/p");
67
        preg_match('/([0-9]*?) aposta/', $nodes->item(2)->nodeValue, $map);
68
        $totalGanhadoresTerceiroPremio = isset($map[1]) ? trim(preg_replace('/[^0-9]/si', '', $map[1])) : "";
69
        $totalGanhadoresTerceiroPremio = empty($totalGanhadoresTerceiroPremio) ? 0 : $totalGanhadoresTerceiroPremio;
70
71
        // Valor ganhadores primeiro premio
72
        $nodes = $finder->query("//div[contains(@class, 'related-box')][contains(@class, 'gray-text')]/p");
73
        preg_match('/R\$ ([0-9,\.]*)/', $nodes->item(0)->nodeValue, $map);
74
        $valorGanhadoresPrimeiroPremio = isset($map[1]) ? trim(preg_replace('/[^0-9,\.]/si', '', $map[1])) : "";
75
        $valorGanhadoresPrimeiroPremio = empty($valorGanhadoresPrimeiroPremio) ? 0 : $valorGanhadoresPrimeiroPremio;
76
77
        // Valor ganhadores segundo premio
78
        $nodes = $finder->query("//div[contains(@class, 'related-box')][contains(@class, 'gray-text')]/p");
79
        preg_match('/R\$ ([0-9,\.]*)/', $nodes->item(1)->nodeValue, $map);
80
        $valorGanhadoresSegundoPremio = isset($map[1]) ? trim(preg_replace('/[^0-9,\.]/si', '', $map[1])) : "";
81
        $valorGanhadoresSegundoPremio = empty($valorGanhadoresSegundoPremio) ? 0 : $valorGanhadoresSegundoPremio;
82
83
        // Valor ganhadores terceiro premio
84
        $nodes = $finder->query("//div[contains(@class, 'related-box')][contains(@class, 'gray-text')]/p");
85
        preg_match('/R\$ ([0-9,\.]*)/', $nodes->item(2)->nodeValue, $map);
86
        $valorGanhadoresTerceiroPremio = isset($map[1]) ? trim(preg_replace('/[^0-9,\.]/si', '', $map[1])) : "";
87
        $valorGanhadoresTerceiroPremio = empty($valorGanhadoresTerceiroPremio) ? 0 : $valorGanhadoresTerceiroPremio;
88
89
        // Valor Acumulado
90
        $nodes = $finder->query("//div[contains(@class, 'totals')]/p/span[contains(@class, 'value')]");
91
        $valorAcumulado = isset($nodes->item(0)->nodeValue) ? trim(preg_replace('/[^0-9,\.]/si', '', $nodes->item(0)->nodeValue)) : "";
92
        $valorAcumulado = empty($valorAcumulado) ? 0 : $valorAcumulado;
93
94
        // Acumulado
95
        $acumulado = $valorGanhadoresPrimeiroPremio > 0 ? 'NÃO' : 'SIM';
96
97
        // Valor estimado proximo concurso
98
        $nodes = $finder->query("//div[contains(@class, 'next-prize')]/p[contains(@class, 'value')]");
99
        $valorEstimadoProximoConcurso = isset($nodes->item(0)->nodeValue) ? trim(preg_replace('/[^0-9,\.]/si', '', $nodes->item(0)->nodeValue)) : "";
100
        $valorEstimadoProximoConcurso = empty($valorEstimadoProximoConcurso) ? 0 : $valorEstimadoProximoConcurso;
101
102
        $this->data[$nrconcurso] = [
103
                'data' => $data,
104
                'dezenas' => $dezenas,
105
                'arrecadacao' => $arrecadacao,
106
                'total_ganhadores_primeiro_premio' => $totalGanhadoresPrimeiroPremio,
107
                'total_ganhadores_segundo_premio' => $totalGanhadoresSegundoPremio,
108
                'total_ganhadores_terceiro_premio' => $totalGanhadoresTerceiroPremio,
109
                'valor_ganhadores_primeiro_premio' => $valorGanhadoresPrimeiroPremio,
110
                'valor_ganhadores_segundo_premio' => $valorGanhadoresSegundoPremio,
111
                'valor_ganhadores_terceiro_premio' => $valorGanhadoresTerceiroPremio,
112
                'acumulado' => $acumulado,
113
                'valor_acumulado' => $valorAcumulado,
114
                'valor_estimado_proximo_concurso' => $valorEstimadoProximoConcurso,
115
        ];
116
117
        return $this->data;
118
    }
0 ignored issues
show
Coding Style introduced by
Closing brace indented incorrectly; expected 8 spaces, found 4
Loading history...
119
}
120