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