-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add count of code
- Loading branch information
Showing
10 changed files
with
174 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace ArtARTs36\GitHandler\DocBuilder; | ||
|
||
use ArtARTs36\Str\Facade\Str; | ||
|
||
class CodeCountsBuilder | ||
{ | ||
private $statist; | ||
|
||
private $paths; | ||
|
||
/** | ||
* @param array<string, string> $paths | ||
*/ | ||
public function __construct( | ||
FolderStatist $statist, | ||
array $paths | ||
) { | ||
$this->statist = $statist; | ||
$this->paths = $paths; | ||
} | ||
|
||
public function build(): string | ||
{ | ||
$content = Markdown::tableHeader([ | ||
'Type', | ||
'Files\' count', | ||
'Code lines\' count', | ||
]) . "\n"; | ||
|
||
foreach ($this->paths as $type => $path) { | ||
$statistic = $this->statist->calculate($path); | ||
|
||
$content .= Markdown::tableLine([ | ||
Str::upFirstSymbol($type), | ||
$statistic->codeFiles, | ||
$statistic->codeLines, | ||
]) . "\n"; | ||
} | ||
|
||
return $content; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace ArtARTs36\GitHandler\DocBuilder; | ||
|
||
use ArtARTs36\FileSystem\Contracts\FileSystem; | ||
use ArtARTs36\Str\Facade\Str; | ||
|
||
class FolderStatist | ||
{ | ||
private $files; | ||
|
||
public function __construct(FileSystem $files) | ||
{ | ||
$this->files = $files; | ||
} | ||
|
||
public function calculate(string $path): FolderStatistic | ||
{ | ||
$codeLines = 0; | ||
$codeFiles = 0; | ||
|
||
foreach ($this->getFromDirectory($path) as $file) { | ||
if ($this->isCode($file)) { | ||
$codeFiles++; | ||
|
||
$codeLines += count(file($file)); | ||
} | ||
} | ||
|
||
return new FolderStatistic($path, $codeFiles, $codeLines); | ||
} | ||
|
||
private function isCode(string $file): bool | ||
{ | ||
return Str::endsWith($file, '.php'); | ||
} | ||
|
||
private function getFromDirectory(string $path): array | ||
{ | ||
$files = []; | ||
|
||
foreach ($this->files->getFromDirectory($path) as $file) { | ||
if (is_dir($file)) { | ||
array_push($files, ...$this->getFromDirectory($file)); | ||
} else { | ||
$files[] = $file; | ||
} | ||
} | ||
|
||
return $files; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace ArtARTs36\GitHandler\DocBuilder; | ||
|
||
class FolderStatistic | ||
{ | ||
public $path; | ||
|
||
public $codeFiles; | ||
|
||
public $codeLines; | ||
|
||
public function __construct(string $path, int $codeFiles, int $codeLines) | ||
{ | ||
$this->path = $path; | ||
$this->codeFiles = $codeFiles; | ||
$this->codeLines = $codeLines; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters