-
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.
- Loading branch information
1 parent
2e020ce
commit f31de9d
Showing
9 changed files
with
93 additions
and
96 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
This file was deleted.
Oops, something went wrong.
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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SavinMikhail\CommentsDensity\AnalyzeComments\File; | ||
|
||
use SavinMikhail\CommentsDensity\AnalyzeComments\Config\DTO\Config; | ||
use SplFileInfo; | ||
|
||
final readonly class FileContentExtractor | ||
{ | ||
public function __construct( | ||
private SplFileInfo $file, | ||
private Config $configDTO, | ||
) {} | ||
|
||
public function getContent(): string | ||
{ | ||
return file_get_contents($this->file->getRealPath()); | ||
} | ||
} |
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,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SavinMikhail\CommentsDensity\AnalyzeComments\File; | ||
|
||
use RecursiveDirectoryIterator; | ||
use RecursiveIteratorIterator; | ||
use SavinMikhail\CommentsDensity\AnalyzeComments\Config\DTO\Config; | ||
use SplFileInfo; | ||
|
||
final readonly class FileFinder | ||
{ | ||
public function __construct( | ||
private Config $config, | ||
) {} | ||
|
||
/** | ||
* @return SplFileInfo[] | ||
*/ | ||
public function __invoke(): iterable | ||
{ | ||
foreach ($this->config->directories as $directory) { | ||
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)); | ||
foreach ($iterator as $file) { | ||
if ($this->shouldSkipFile($file)) { | ||
continue; | ||
} | ||
yield $file; | ||
} | ||
} | ||
} | ||
|
||
private function shouldSkipFile(SplFileInfo $file): bool | ||
{ | ||
return | ||
$this->isInWhitelist($file->getRealPath()) | ||
|| $file->getSize() === 0 | ||
|| !$this->isPhpFile($file) | ||
|| !$file->isReadable(); | ||
} | ||
|
||
private function isPhpFile(SplFileInfo $file): bool | ||
{ | ||
return $file->isFile() && $file->getExtension() === 'php'; | ||
} | ||
|
||
private function isInWhitelist(string $filePath): bool | ||
{ | ||
foreach ($this->config->exclude as $whitelistedDir) { | ||
if (str_contains($filePath, $whitelistedDir)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
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