| Code Coverage | ||||||||||
| Classes and Traits | Functions and Methods | Lines | ||||||||
| Total |  | 0.00% | 0 / 1 |  | 66.67% | 2 / 3 | CRAP |  | 82.76% | 24 / 29 | 
| ShopsReader |  | 0.00% | 0 / 1 |  | 66.67% | 2 / 3 | 9.42 |  | 82.76% | 24 / 29 | 
| each |  | 100.00% | 1 / 1 | 2 |  | 100.00% | 4 / 4 | |||
| setDelimiter |  | 0.00% | 0 / 1 | 5.50 |  | 54.55% | 6 / 11 | |||
| getShop |  | 100.00% | 1 / 1 | 3 |  | 100.00% | 14 / 14 | |||
| 1 | <?php | 
| 2 | |
| 3 | namespace Qmp\Laravel\Adserving\Objects; | 
| 4 | |
| 5 | use Closure; | 
| 6 | use Illuminate\Support\Collection; | 
| 7 | use Qmp\Laravel\ToolsLaravel\FileReader\FileReader; | 
| 8 | |
| 9 | class ShopsReader extends FileReader | 
| 10 | { | 
| 11 | protected $delimiter = ','; | 
| 12 | |
| 13 | protected $keys = ['lat', 'lon', 'link_url']; | 
| 14 | |
| 15 | /** | 
| 16 | * @param Closure $func | 
| 17 | * @param $id_visual | 
| 18 | * @param null $max | 
| 19 | */ | 
| 20 | public function each(Closure $func, $max = null, $params = null) | 
| 21 | { | 
| 22 | $this->nbLines = $max; | 
| 23 | |
| 24 | foreach ($this->generator() as $row) { | 
| 25 | $func($this->getShop($params, $row)); | 
| 26 | } | 
| 27 | } | 
| 28 | |
| 29 | public function setDelimiter($delimiter) { | 
| 30 | |
| 31 | switch ($delimiter) { | 
| 32 | case 'coma' : | 
| 33 | $this->delimiter = ','; | 
| 34 | break; | 
| 35 | case 'semi-colon' : | 
| 36 | $this->delimiter = ';'; | 
| 37 | break; | 
| 38 | case 'tab' : | 
| 39 | $this->delimiter = "\t"; | 
| 40 | break; | 
| 41 | } | 
| 42 | return $this; | 
| 43 | } | 
| 44 | |
| 45 | /** | 
| 46 | * @param $id_visual | 
| 47 | * @param $rows | 
| 48 | * @return Collection | 
| 49 | */ | 
| 50 | protected function getShop($id_visual, $row) | 
| 51 | { | 
| 52 | $array = []; | 
| 53 | $temp = []; | 
| 54 | |
| 55 | $getcsv = str_getcsv(trim($row), $this->delimiter); | 
| 56 | |
| 57 | foreach ($this->keys as $index => $value) { | 
| 58 | $temp[$value] = $getcsv[$index]; | 
| 59 | } | 
| 60 | |
| 61 | for($i = count($this->keys); $i < count($getcsv); $i++) { | 
| 62 | $temp['lines'][] = $getcsv[$i]; | 
| 63 | } | 
| 64 | |
| 65 | $array = [ | 
| 66 | 'id_visual' => (int)$id_visual, | 
| 67 | 'link_url' => $temp['link_url'], | 
| 68 | 'lines' => collect($temp['lines']), | 
| 69 | 'location' => [ | 
| 70 | 'type' => 'Point', | 
| 71 | 'coordinates' => [ | 
| 72 | floatval($temp['lon']), | 
| 73 | floatval($temp['lat']) | 
| 74 | ] | 
| 75 | ] | 
| 76 | ]; | 
| 77 | |
| 78 | return collect($array); | 
| 79 | } | 
| 80 | |
| 81 | } |