public function saveToCsv(array $data, Profile $profile, CsvFile $csv, $incremental = false)
 {
     $cnt = 0;
     /** @var Result $result */
     foreach ($data as $result) {
         $metrics = $result->getMetrics();
         $dimensions = $result->getDimensions();
         // CSV Header
         if ($cnt == 0 && !$incremental) {
             $headerRow = array_merge(array('id', 'idProfile'), array_keys($dimensions), array_keys($metrics));
             $csv->writeRow($headerRow);
         }
         if (isset($dimensions['date'])) {
             $dimensions['date'] = date('Y-m-d', strtotime($dimensions['date']));
         }
         $row = array_merge(array_values($dimensions), array_values($metrics));
         $outRow = array_merge(array(sha1($profile->getGoogleId() . implode('', $dimensions)), $profile->getGoogleId()), $row);
         $csv->writeRow($outRow);
         $cnt++;
     }
 }
 protected function getOutputCsv($tableName, Profile $profile)
 {
     $fileName = str_replace(' ', '-', $tableName) . '-' . str_replace('/', '', $profile->getGoogleId()) . "-" . microtime() . "-" . uniqid("", true) . ".csv";
     $tmpFileInfo = $this->temp->createFile($fileName);
     return new CsvFile($tmpFileInfo->getPathname());
 }