for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Services;
use Illuminate\Filesystem\Filesystem;
use LogicException;
class DataProvider
{
const TYPE_IN = '.in';
const TYPE_OUT = '.out';
public function getData($id)
$dataInput = $this->getInputFiles($id);
$dataOutput = $this->getOutputFiles($id);
$data = [];
foreach ($dataInput as $name => $content) {
if (!array_key_exists($name, $dataOutput)) {
$message = 'Problem Data is not match!';
app('log')->error($message, ['pid' => $id]);
throw new LogicException($message);
}
$outContent = $dataOutput[$name];
$data[] = [
'input' => $content,
'output' => $outContent,
];
return $data;
/**
* @param $id
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
* @return array
*/
public function getInputFiles($id)
$pattern = $this->getDataPath($id).'*'.self::TYPE_IN;
return $this->getDataFiles($pattern);
* @return string
public function getDataPath($id)
return config('hustoj.data_path').'/'.$id.'/';
public function getOutputFiles($id)
$pattern = $this->getDataPath($id).'*'.self::TYPE_OUT;
public function getDataFiles($pattern)
$fs = new Filesystem();
$files = $fs->glob($pattern);
foreach ($files as $file) {
$data[$fs->name($file)] = $fs->get($file);