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

Reader::getDataLive()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 22
rs 9.2
cc 2
eloc 13
nc 2
nop 0
1
<?php
2
3
namespace LoteriaApi\Consumer;
4
5
use \DOMDocument;
6
use LoteriaApi\Consumer\Reader\LoteriaNumbersNode;
7
8
class Reader
9
{
10
    private $datasource;
11
    private $paths;
12
13
    public function setDataSource($datasource)
14
    {
15
        $this->datasource = $datasource;
16
        return $this;
17
    }
18
    
19
    public function setPathsStorage($paths)
20
    {
21
        $this->paths = $paths;
22
        return $this;
23
    }
24
    
25
    public function getData()
26
    {
27
        $data = [];
28
29
        // set error level
30
        $internalErrors = libxml_use_internal_errors(true);
31
32
        foreach ($this->datasource as $concursoName => $concursoData) {
33
            $file = $this->paths['path']['ext'].$concursoData['html'];
34
            $doc = new DOMDocument();
35
            $doc->loadHTMLFile($file);
36
            $data[$concursoName] = (new $concursoData['reader'])
37
                ->setDOMDocument($doc)
38
                ->setNumbersNode(new LoteriaNumbersNode)
39
                ->getData();
40
        }
41
42
        // Restore error level
43
        libxml_use_internal_errors($internalErrors);
44
        return $data;
45
    }
46
47
    public function getDataLive()
48
    {
49
        $data = [];
50
51
        // set error level
52
        $internalErrors = libxml_use_internal_errors(true);
53
54
        foreach ($this->datasource as $concursoName => $concursoData) {
55
            $file = $this->paths['path']['ext'].$concursoData['html'];
56
            $doc = new DOMDocument();
57
            $doc->loadHTMLFile($file);
58
            $data[$concursoName] = (new $concursoData['reader'])
59
                ->setDOMDocument($doc)
60
                ->setNumbersNode(new LoteriaNumbersNode)
61
                ->getDataLive();
62
        }
63
64
        // Restore error level
65
        libxml_use_internal_errors($internalErrors);
66
67
        return $data;
68
    }
69
}
70