diff --git a/Utils/Git/Repository.php b/Utils/Git/Repository.php index d2d0ba7fb..0c70065f0 100644 --- a/Utils/Git/Repository.php +++ b/Utils/Git/Repository.php @@ -616,8 +616,8 @@ class Repository */ public function getCommit(string $commit) : Commit { - $lines = $this->run('show --name-only ' . escapeshellarg($commit)); - $count = count($lines); + $lines = $this->run('show --name-only ' . escapeshellarg($commit)); + $count = count($lines); if (empty($lines)) { // todo: return null commit @@ -649,6 +649,52 @@ class Repository return $commit; } + /** + * Count files in repository. + * + * @return int + * + * @throws \Exception + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function countFiles() : int + { + $lines = $this->run('ls-files'); + + return count($lines); + } + + /** + * Get LOC. + * + * @return int + * + * @throws \Exception + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getLOC() : int + { + $lines = $this->run('ls-files'); + $loc = 0; + + foreach ($lines as $line) { + $fh = fopen($this->getDirectoryPath() . ($this->bare ? '/' : '/../') . $line, 'r'); + + while (!feof($fh)) { + fgets($fh); + $loc++; + } + + fclose($fh); + } + + return $loc; + } + /** * Count commits. *