Total Complexity | 8 |
Total Lines | 76 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 2 | Features | 1 |
1 | <?php |
||
7 | class DataProvider |
||
8 | { |
||
9 | const TYPE_IN = '.in'; |
||
10 | const TYPE_OUT = '.out'; |
||
11 | |||
12 | public function getData($id) |
||
13 | { |
||
14 | $dataInput = $this->getInputFiles($id); |
||
15 | $dataOutput = $this->getOutputFiles($id); |
||
16 | |||
17 | $data = []; |
||
18 | foreach ($dataInput as $name => $content) { |
||
19 | if (!array_key_exists($name, $dataOutput)) { |
||
20 | $message = 'Problem Data is not match!'; |
||
21 | app('log')->error($message, ['pid' => $id]); |
||
22 | throw new \LogicException($message); |
||
23 | } |
||
24 | $outContent = $dataOutput[$name]; |
||
25 | $data[] = [ |
||
26 | 'input' => $content, |
||
27 | 'output' => $outContent, |
||
28 | ]; |
||
29 | } |
||
30 | return $data; |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * @param $id |
||
35 | * |
||
36 | * @return array |
||
37 | * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException |
||
38 | */ |
||
39 | public function getInputFiles($id) |
||
40 | { |
||
41 | $patten = $this->getDataPath($id). '*'. self::TYPE_IN; |
||
42 | |||
43 | $fs = new Filesystem(); |
||
44 | $files = $fs->glob($patten); |
||
45 | |||
46 | $data = []; |
||
47 | foreach ($files as $file) { |
||
48 | $data[$fs->name($file)] = $fs->get($file); |
||
49 | } |
||
50 | |||
51 | return $data; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @param $id |
||
56 | * |
||
57 | * @return array |
||
58 | * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException |
||
59 | */ |
||
60 | public function getOutputFiles($id) |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * @param $id |
||
77 | * |
||
78 | * @return string |
||
79 | */ |
||
80 | public function getDataPath($id) |
||
83 | } |
||
84 | } |
||
85 |