| Total Complexity | 8 |
| Total Lines | 74 |
| 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 | throw new LogicException($message); |
||
| 24 | } |
||
| 25 | $outContent = $dataOutput[$name]; |
||
| 26 | $data[] = [ |
||
| 27 | 'input' => $content, |
||
| 28 | 'output' => $outContent, |
||
| 29 | ]; |
||
| 30 | } |
||
| 31 | |||
| 32 | return $data; |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param $id |
||
| 37 | * |
||
| 38 | * @return array |
||
| 39 | * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException |
||
| 40 | */ |
||
| 41 | public function getInputFiles($id) |
||
| 42 | { |
||
| 43 | $pattern = $this->getDataPath($id).'*'.self::TYPE_IN; |
||
| 44 | |||
| 45 | return $this->getDataFiles($pattern); |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @param $id |
||
| 50 | * |
||
| 51 | * @return string |
||
| 52 | */ |
||
| 53 | public function getDataPath($id) |
||
| 54 | { |
||
| 55 | return config('hustoj.data_path').'/'.$id.'/'; |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @param $id |
||
| 60 | * |
||
| 61 | * @return array |
||
| 62 | * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException |
||
| 63 | */ |
||
| 64 | public function getOutputFiles($id) |
||
| 69 | } |
||
| 70 | |||
| 71 | public function getDataFiles($pattern) |
||
| 72 | { |
||
| 84 |