Skip to content

Commit

Permalink
package by feature
Browse files Browse the repository at this point in the history
  • Loading branch information
savinmikhail committed Jan 3, 2025
1 parent 7c5f424 commit 4ff5eb5
Show file tree
Hide file tree
Showing 63 changed files with 256 additions and 268 deletions.
6 changes: 6 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ tasks:
deps: [install]
cmd: 'vendor/bin/composer-unused {{.CLI_ARGS}}'

run:
cmd: './bin/comments_density analyze:comments'

base:
cmd: './bin/comments_density generate:baseline'

check:
cmds:
- task: cs
Expand Down
4 changes: 2 additions & 2 deletions bin/comments_density
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
declare(strict_types=1);

use Composer\XdebugHandler\XdebugHandler;
use SavinMikhail\CommentsDensity\Commands\AnalyzeCommentCommand;
use SavinMikhail\CommentsDensity\Commands\BaselineCommand;
use SavinMikhail\CommentsDensity\AnalyzeComments\Commands\AnalyzeCommentCommand;
use SavinMikhail\CommentsDensity\Baseline\Commands\BaselineCommand;
use Symfony\Component\Console\Application;

// Display all errors and warnings
Expand Down
7 changes: 3 additions & 4 deletions comments_density.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

declare(strict_types=1);

use SavinMikhail\CommentsDensity\Config\DTO\ConfigDTO;
use SavinMikhail\CommentsDensity\Config\DTO\ConsoleOutputDTO;
use SavinMikhail\CommentsDensity\Config\DTO\MissingDocblockConfigDTO;
use SavinMikhail\CommentsDensity\Config\DTO\OutputDTO;
use SavinMikhail\CommentsDensity\AnalyzeComments\Config\DTO\ConfigDTO;
use SavinMikhail\CommentsDensity\AnalyzeComments\Config\DTO\ConsoleOutputDTO;
use SavinMikhail\CommentsDensity\AnalyzeComments\Config\DTO\MissingDocblockConfigDTO;

return new ConfigDTO(
thresholds: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@

declare(strict_types=1);

namespace SavinMikhail\CommentsDensity\Analyzer;
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer;

use SavinMikhail\CommentsDensity\Analyzer\DTO\Output\CommentDTO;
use SavinMikhail\CommentsDensity\Comments\CommentFactory;
use SavinMikhail\CommentsDensity\Config\DTO\ConfigDTO;
use SavinMikhail\CommentsDensity\MissingDocblock\MissingDocBlockAnalyzer;
use SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output\CommentDTO;
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\CommentFactory;
use SavinMikhail\CommentsDensity\AnalyzeComments\Config\DTO\ConfigDTO;
use SavinMikhail\CommentsDensity\AnalyzeComments\MissingDocblock\MissingDocBlockAnalyzer;
use SplFileInfo;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Contracts\Cache\CacheInterface;

use function array_merge;
use function count;
use function file;
use function file_get_contents;
use function in_array;
use function is_array;
use function token_get_all;

use const T_COMMENT;
use const T_DOC_COMMENT;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@

declare(strict_types=1);

namespace SavinMikhail\CommentsDensity\Analyzer;

use SavinMikhail\CommentsDensity\Analyzer\DTO\Output\CommentDTO;
use SavinMikhail\CommentsDensity\Analyzer\DTO\Output\CommentStatisticsDTO;
use SavinMikhail\CommentsDensity\Analyzer\DTO\Output\OutputDTO;
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer;

use SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output\CommentDTO;
use SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output\CommentStatisticsDTO;
use SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output\OutputDTO;
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\CommentFactory;
use SavinMikhail\CommentsDensity\AnalyzeComments\Config\DTO\ConfigDTO;
use SavinMikhail\CommentsDensity\AnalyzeComments\Metrics\MetricsFacade;
use SavinMikhail\CommentsDensity\AnalyzeComments\MissingDocblock\MissingDocBlockAnalyzer;
use SavinMikhail\CommentsDensity\Baseline\Storage\BaselineStorageInterface;
use SavinMikhail\CommentsDensity\Comments\CommentFactory;
use SavinMikhail\CommentsDensity\Config\DTO\ConfigDTO;
use SavinMikhail\CommentsDensity\Metrics\MetricsFacade;
use SavinMikhail\CommentsDensity\MissingDocblock\MissingDocBlockAnalyzer;
use SplFileInfo;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Contracts\Cache\CacheInterface;

use function array_push;

final class Analyzer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

declare(strict_types=1);

namespace SavinMikhail\CommentsDensity\Analyzer;
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer;

use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\CommentFactory;
use SavinMikhail\CommentsDensity\AnalyzeComments\Config\DTO\ConfigDTO;
use SavinMikhail\CommentsDensity\AnalyzeComments\Metrics\CDS;
use SavinMikhail\CommentsDensity\AnalyzeComments\Metrics\ComToLoc;
use SavinMikhail\CommentsDensity\AnalyzeComments\Metrics\MetricsFacade;
use SavinMikhail\CommentsDensity\AnalyzeComments\Metrics\ResourceUtilization;
use SavinMikhail\CommentsDensity\AnalyzeComments\MissingDocblock\MissingDocBlockAnalyzer;
use SavinMikhail\CommentsDensity\Baseline\Storage\BaselineStorageInterface;
use SavinMikhail\CommentsDensity\Comments\CommentFactory;
use SavinMikhail\CommentsDensity\Config\DTO\ConfigDTO;
use SavinMikhail\CommentsDensity\Metrics\CDS;
use SavinMikhail\CommentsDensity\Metrics\ComToLoc;
use SavinMikhail\CommentsDensity\Metrics\MetricsFacade;
use SavinMikhail\CommentsDensity\Metrics\ResourceUtilization;
use SavinMikhail\CommentsDensity\MissingDocblock\MissingDocBlockAnalyzer;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Console\Output\OutputInterface;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

declare(strict_types=1);

namespace SavinMikhail\CommentsDensity\Analyzer;

use SavinMikhail\CommentsDensity\Analyzer\DTO\Output\CommentDTO;
use SavinMikhail\CommentsDensity\Analyzer\DTO\Output\CommentStatisticsDTO;
use SavinMikhail\CommentsDensity\Comments\CommentFactory;
use SavinMikhail\CommentsDensity\Config\DTO\ConfigDTO;
use SavinMikhail\CommentsDensity\Exception\CommentsDensityException;
use SavinMikhail\CommentsDensity\MissingDocblock\MissingDocBlockAnalyzer;
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer;

use SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output\CommentDTO;
use SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output\CommentStatisticsDTO;
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\CommentFactory;
use SavinMikhail\CommentsDensity\AnalyzeComments\Config\DTO\ConfigDTO;
use SavinMikhail\CommentsDensity\AnalyzeComments\Exception\CommentsDensityException;
use SavinMikhail\CommentsDensity\AnalyzeComments\MissingDocblock\MissingDocBlockAnalyzer;
use function substr_count;

use const PHP_EOL;

final readonly class CommentStatisticsAggregator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace SavinMikhail\CommentsDensity\Analyzer\DTO\Output;
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output;

final readonly class CdsDTO
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace SavinMikhail\CommentsDensity\Analyzer\DTO\Output;
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output;

final readonly class ComToLocDTO
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace SavinMikhail\CommentsDensity\Analyzer\DTO\Output;
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output;

final readonly class CommentDTO
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace SavinMikhail\CommentsDensity\Analyzer\DTO\Output;
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output;

final readonly class CommentStatisticsDTO
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace SavinMikhail\CommentsDensity\Analyzer\DTO\Output;
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output;

final readonly class OutputDTO
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace SavinMikhail\CommentsDensity\Analyzer\DTO\Output;
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output;

final readonly class PerformanceMetricsDTO
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

declare(strict_types=1);

namespace SavinMikhail\CommentsDensity\Commands;
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Commands;

use SavinMikhail\CommentsDensity\Analyzer\AnalyzerFactory;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\AnalyzerFactory;
use SavinMikhail\CommentsDensity\AnalyzeComments\Config\ConfigLoader;
use SavinMikhail\CommentsDensity\AnalyzeComments\Config\DTO\ConfigDTO;
use SavinMikhail\CommentsDensity\AnalyzeComments\Exception\CommentsDensityException;
use SavinMikhail\CommentsDensity\AnalyzeComments\Reporters\ReporterFactory;
use SavinMikhail\CommentsDensity\Baseline\Storage\TreePhpBaselineStorage;
use SavinMikhail\CommentsDensity\Reporters\ReporterFactory;
use Symfony\Component\Console\Command\Command as SymfonyCommand;
use SplFileInfo;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand All @@ -22,14 +28,15 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$path = __DIR__ . '/../../baseline.php';
$configLoader = new ConfigLoader();
$path = $configLoader->getProjectRoot() . '/baseline.php';

$storage = new TreePhpBaselineStorage();
$storage->init($path);

$configDto = $this->getConfigDto();

$configDto = $configLoader->getConfigDto();
$files = $this->getFilesFromDirectories($configDto->directories);

$reporter = (new ReporterFactory())->createReporter($output, $configDto);
$analyzerFactory = new AnalyzerFactory();

Expand All @@ -42,10 +49,24 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($outputDTO->exceedThreshold) {
$output->writeln('<error>Comment thresholds were exceeded!</error>');

return SymfonyCommand::FAILURE;
return Command::FAILURE;
}
$output->writeln('<info>Comment thresholds are passed!</info>');

return SymfonyCommand::SUCCESS;
return Command::SUCCESS;
}

/**
* @param string[] $directories
* @return SplFileInfo[]
*/
protected function getFilesFromDirectories(array $directories): iterable
{
foreach ($directories as $directory) {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
foreach ($iterator as $file) {
yield $file;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace SavinMikhail\CommentsDensity\Comments;
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Comments;

use Stringable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace SavinMikhail\CommentsDensity\Comments;
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Comments;

interface CommentConstantsInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace SavinMikhail\CommentsDensity\Comments;
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Comments;

use function in_array;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace SavinMikhail\CommentsDensity\Comments;
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Comments;

interface CommentTypeInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace SavinMikhail\CommentsDensity\Comments;
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Comments;

final class DocBlockComment extends Comment
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace SavinMikhail\CommentsDensity\Comments;
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Comments;

final class FixMeComment extends Comment
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace SavinMikhail\CommentsDensity\Comments;
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Comments;

final class LicenseComment extends Comment
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace SavinMikhail\CommentsDensity\Comments;
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Comments;

final class RegularComment extends Comment
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace SavinMikhail\CommentsDensity\Comments;
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Comments;

final class TodoComment extends Comment
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@

declare(strict_types=1);

namespace SavinMikhail\CommentsDensity\Config;

use SavinMikhail\CommentsDensity\Config\DTO\ConfigDTO;
use SavinMikhail\CommentsDensity\Exception\CommentsDensityException;
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Config;

use SavinMikhail\CommentsDensity\AnalyzeComments\Config\DTO\ConfigDTO;
use SavinMikhail\CommentsDensity\AnalyzeComments\Exception\CommentsDensityException;
use function defined;
use function dirname;
use function file_exists;

use const DIRECTORY_SEPARATOR;

final readonly class ConfigLoader
{
private const CONFIG_FILE = 'comments_density.php';
private const DIR_LEVEL = COMMENTS_DENSITY_ENVIRONMENT === 'dev' ? 2 : 5;
private const DIR_LEVEL = COMMENTS_DENSITY_ENVIRONMENT === 'dev' ? 3 : 6;

/**
* @throws CommentsDensityException
Expand Down Expand Up @@ -46,7 +44,7 @@ public function getConfigDto(): ConfigDTO
return $config;
}

private function getProjectRoot(): string
public function getProjectRoot(): string
{
return dirname(__DIR__, self::DIR_LEVEL);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace SavinMikhail\CommentsDensity\Config\DTO;
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Config\DTO;

final readonly class ConfigDTO
{
Expand Down
Loading

0 comments on commit 4ff5eb5

Please sign in to comment.