/** * Проверка файлов на различия, проверяется по размеру файла и наличие файла в ФС * @retun array */ public function checkFiles() { $cachedFiles = Cache::remember(static::CACHE_KEY, Carbon::now()->addHours(6), function () { $response = $this->request('https://api.github.com/repos/:rep/git/trees/:branch?recursive=true'); $response = json_decode($response, true); $files = ['new_files' => [], 'diff_files' => [], 'third_party_plugins' => []]; if (isset($response['tree'])) { foreach ($response['tree'] as $row) { $filePath = base_path($row['path']); if (!file_exists($filePath)) { $files['new_files'][] = $this->getFileUrlByPath($row['path']); continue; } $fileSize = filesize($filePath); if (isset($row['size']) and $fileSize != $row['size']) { $diff = $fileSize - $this->countFileLines($filePath) - $row['size']; if ($diff > 1 or $diff < -1) { $files['diff_files'][] = ['diff' => Text::bytes($diff), 'path' => $row['path'], 'url' => $this->buildRemoteUrl('https://raw.githubusercontent.com/:rep/:branch/' . $row['path'])]; } } } return $files; } }); return $cachedFiles; }
/** * @return int */ public function getSize() { if ($this->isNew()) { $size = 0; } else { $size = $this->file->getSize(); } return Text::bytes($size); }