Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing Halstead metrics #10

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/cognitive-analysis
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ if (file_exists(__DIR__ . '/../../../autoload.php')) {
require_once __DIR__ . '/../vendor/autoload.php';
}

use Phauthentic\CodeQualityMetrics\Application;
use Phauthentic\CognitiveCodeAnalysis\Application;

(new Application())->run();
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
},
"autoload": {
"psr-4": {
"Phauthentic\\CodeQualityMetrics\\": "src/"
"Phauthentic\\CognitiveCodeAnalysis\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Phauthentic\\CodeQualityMetrics\\Tests\\": "tests/"
"Phauthentic\\CognitiveCodeAnalysis\\Tests\\": "tests/"
}
},
"authors": [
Expand Down
9 changes: 0 additions & 9 deletions docs/Halstead-Complexity-Analysis.md

This file was deleted.

7 changes: 0 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ You can also pass a baseline file to compare the results to. The JSON report is
bin/cognitive-analysis metrics:cognitive <path-to-folder> --baseline cognitive.json
```

Halstead Complexity Analysis

```bash
bin/cognitive-analysis metrics:halstead <path-to-folder>
```

## Documentation

* [Cognitive Complexity Analysis](./docs/Cognitive-Complexity-Analysis.md#cognitive-complexity-analysis)
Expand All @@ -45,7 +39,6 @@ bin/cognitive-analysis metrics:halstead <path-to-folder>
* [Examples](#examples)
* [Wordpress WP_Debug_Data](#wordpress-wp_debug_data)
* [Doctrine Paginator](#doctrine-paginator)
* [Halstead Complexity Analysis](./docs/Halstead-Complexity-Analysis.md)

## Resources

Expand Down
53 changes: 13 additions & 40 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@

declare(strict_types=1);

namespace Phauthentic\CodeQualityMetrics;

use Phauthentic\CodeQualityMetrics\Business\Cognitive\BaselineService;
use Phauthentic\CodeQualityMetrics\Business\Cognitive\CognitiveMetricsCollector;
use Phauthentic\CodeQualityMetrics\Business\Cognitive\FindMetricsPluginInterface;
use Phauthentic\CodeQualityMetrics\Business\Cognitive\ScoreCalculator;
use Phauthentic\CodeQualityMetrics\Business\DirectoryScanner;
use Phauthentic\CodeQualityMetrics\Business\Halstead\HalsteadMetricsCollector;
use Phauthentic\CodeQualityMetrics\Command\Cognitive\CognitiveCollectorShellOutputPlugin;
use Phauthentic\CodeQualityMetrics\Command\CognitiveMetricsCommand;
use Phauthentic\CodeQualityMetrics\Command\HalsteadMetricsCommand;
use Phauthentic\CodeQualityMetrics\Business\MetricsFacade;
use Phauthentic\CodeQualityMetrics\Command\Presentation\CognitiveMetricTextRenderer;
use Phauthentic\CodeQualityMetrics\Command\Presentation\HalsteadMetricTextRenderer;
use Phauthentic\CodeQualityMetrics\Config\ConfigLoader;
use Phauthentic\CodeQualityMetrics\Config\ConfigService;
namespace Phauthentic\CognitiveCodeAnalysis;

use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\BaselineService;
use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\CognitiveMetricsCollector;
use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\ScoreCalculator;
use Phauthentic\CognitiveCodeAnalysis\Business\DirectoryScanner;
use Phauthentic\CognitiveCodeAnalysis\Command\Cognitive\CognitiveCollectorShellOutputPlugin;
use Phauthentic\CognitiveCodeAnalysis\Command\CognitiveMetricsCommand;
use Phauthentic\CognitiveCodeAnalysis\Business\MetricsFacade;
use Phauthentic\CognitiveCodeAnalysis\Command\Presentation\CognitiveMetricTextRenderer;
use Phauthentic\CognitiveCodeAnalysis\Config\ConfigLoader;
use Phauthentic\CognitiveCodeAnalysis\Config\ConfigService;
use PhpParser\NodeTraverser;
use PhpParser\NodeTraverserInterface;
use PhpParser\ParserFactory;
Expand Down Expand Up @@ -45,9 +41,6 @@ public function __construct()

private function registerServices(): void
{
$this->containerBuilder->register(HalsteadMetricsCollector::class, HalsteadMetricsCollector::class)
->setPublic(true);

$this->containerBuilder->register(CognitiveMetricsCollector::class, CognitiveMetricsCollector::class)
->setPublic(true);

Expand All @@ -57,9 +50,6 @@ private function registerServices(): void
$this->containerBuilder->register(ConfigService::class, ConfigService::class)
->setPublic(true);

$this->containerBuilder->register(HalsteadMetricTextRenderer::class, HalsteadMetricTextRenderer::class)
->setPublic(true);

$this->containerBuilder->register(CognitiveMetricTextRenderer::class, CognitiveMetricTextRenderer::class)
->setPublic(true);

Expand Down Expand Up @@ -121,14 +111,6 @@ private function bootstrapMetricsCollectors(): void
]
])
->setPublic(true);

$this->containerBuilder->register(HalsteadMetricsCollector::class, HalsteadMetricsCollector::class)
->setArguments([
new Reference(ParserFactory::class),
new Reference(NodeTraverserInterface::class),
new Reference(DirectoryScanner::class),
])
->setPublic(true);
}

private function configureConfigService(): void
Expand All @@ -145,7 +127,6 @@ private function registerMetricsFacade(): void
{
$this->containerBuilder->register(MetricsFacade::class, MetricsFacade::class)
->setArguments([
new Reference(HalsteadMetricsCollector::class),
new Reference(CognitiveMetricsCollector::class),
new Reference(ScoreCalculator::class),
new Reference(ConfigService::class),
Expand All @@ -162,21 +143,13 @@ private function registerCommands(): void
new Reference(BaselineService::class),
])
->setPublic(true);

$this->containerBuilder->register(HalsteadMetricsCommand::class, HalsteadMetricsCommand::class)
->setArguments([
new Reference(MetricsFacade::class),
new Reference(HalsteadMetricTextRenderer::class),
])
->setPublic(true);
}

private function configureApplication(): void
{
$this->containerBuilder->register(SymfonyApplication::class, SymfonyApplication::class)
->setPublic(true)
->addMethodCall('add', [new Reference(CognitiveMetricsCommand::class)])
->addMethodCall('add', [new Reference(HalsteadMetricsCommand::class)]);
->addMethodCall('add', [new Reference(CognitiveMetricsCommand::class)]);
}

public function run(): void
Expand Down
6 changes: 3 additions & 3 deletions src/Business/Cognitive/BaselineService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

declare(strict_types=1);

namespace Phauthentic\CodeQualityMetrics\Business\Cognitive;
namespace Phauthentic\CognitiveCodeAnalysis\Business\Cognitive;

use JsonException;
use RuntimeException;

/**
Expand All @@ -30,13 +31,12 @@ public function calculateDeltas(CognitiveMetricsCollection $metricsCollection, a
}
}


/**
* Loads the baseline file and returns the data as an array.
*
* @param string $baselineFile
* @return array<string, array<string, mixed>> $baseline
* @throws \JsonException
* @throws JsonException
*/
public function loadBaseline(string $baselineFile): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Business/Cognitive/CognitiveMetrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Phauthentic\CodeQualityMetrics\Business\Cognitive;
namespace Phauthentic\CognitiveCodeAnalysis\Business\Cognitive;

use InvalidArgumentException;
use JsonSerializable;
Expand Down
2 changes: 1 addition & 1 deletion src/Business/Cognitive/CognitiveMetricsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Phauthentic\CodeQualityMetrics\Business\Cognitive;
namespace Phauthentic\CognitiveCodeAnalysis\Business\Cognitive;

use ArrayIterator;
use Closure;
Expand Down
20 changes: 10 additions & 10 deletions src/Business/Cognitive/CognitiveMetricsCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

declare(strict_types=1);

namespace Phauthentic\CodeQualityMetrics\Business\Cognitive;
namespace Phauthentic\CognitiveCodeAnalysis\Business\Cognitive;

use Phauthentic\CodeQualityMetrics\Business\DirectoryScanner;
use Phauthentic\CodeQualityMetrics\CognitiveAnalysisException;
use Phauthentic\CodeQualityMetrics\Config\ConfigService;
use Phauthentic\CodeQualityMetrics\PhpParser\CognitiveMetricsVisitor;
use Phauthentic\CognitiveCodeAnalysis\Business\DirectoryScanner;
use Phauthentic\CognitiveCodeAnalysis\CognitiveAnalysisException;
use Phauthentic\CognitiveCodeAnalysis\Config\ConfigService;
use Phauthentic\CognitiveCodeAnalysis\PhpParser\CognitiveMetricsVisitor;
use PhpParser\Error;
use PhpParser\NodeTraverserInterface;
use PhpParser\Parser;
Expand Down Expand Up @@ -38,7 +38,7 @@ public function __construct(
* @param array<string, mixed> $config
* @return array<int, string>
*/
protected function getExcludePatternsFromConfig(array $config): array
private function getExcludePatternsFromConfig(array $config): array
{
if (isset($config['excludePatterns'])) {
return $config['excludePatterns'];
Expand Down Expand Up @@ -67,7 +67,7 @@ public function collect(string $path, array $config = []): CognitiveMetricsColle
* @param iterable<SplFileInfo> $files
* @return CognitiveMetricsCollection
*/
protected function findMetrics(iterable $files): CognitiveMetricsCollection
private function findMetrics(iterable $files): CognitiveMetricsCollection
{
$metricsCollection = new CognitiveMetricsCollection();
$visitor = new CognitiveMetricsVisitor();
Expand Down Expand Up @@ -137,7 +137,7 @@ private function processMethodMetrics(
}
}

public function isExcluded(string $classAndMethod): bool
private function isExcluded(string $classAndMethod): bool
{
$regexes = $this->configService->getConfig()['cognitive']['excludePatterns'];

Expand All @@ -157,15 +157,15 @@ public function isExcluded(string $classAndMethod): bool
* @param array<int, string> $exclude List of regx to exclude
* @return iterable<mixed, SplFileInfo> An iterable of SplFileInfo objects
*/
protected function findSourceFiles(string $path, array $exclude = []): iterable
private function findSourceFiles(string $path, array $exclude = []): iterable
{
return $this->directoryScanner->scan([$path], ['^(?!.*\.php$).+'] + $exclude); // Exclude non-PHP files
}

/**
* @throws CognitiveAnalysisException
*/
protected function traverseAbstractSyntaxTree(string $code): void
private function traverseAbstractSyntaxTree(string $code): void
{
try {
$ast = $this->parser->parse($code);
Expand Down
2 changes: 1 addition & 1 deletion src/Business/Cognitive/Delta.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Phauthentic\CodeQualityMetrics\Business\Cognitive;
namespace Phauthentic\CognitiveCodeAnalysis\Business\Cognitive;

/**
*
Expand Down
4 changes: 2 additions & 2 deletions src/Business/Cognitive/Exporter/CsvExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace Phauthentic\CodeQualityMetrics\Business\Cognitive\Exporter;
namespace Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\Exporter;

use Phauthentic\CodeQualityMetrics\Business\Cognitive\CognitiveMetricsCollection;
use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\CognitiveMetricsCollection;
use RuntimeException;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Business/Cognitive/Exporter/DataExporterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Phauthentic\CodeQualityMetrics\Business\Cognitive\Exporter;
namespace Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\Exporter;

/**
*
Expand Down
4 changes: 2 additions & 2 deletions src/Business/Cognitive/Exporter/HtmlExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace Phauthentic\CodeQualityMetrics\Business\Cognitive\Exporter;
namespace Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\Exporter;

use Phauthentic\CodeQualityMetrics\Business\Cognitive\CognitiveMetricsCollection;
use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\CognitiveMetricsCollection;
use RuntimeException;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Business/Cognitive/Exporter/JsonExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace Phauthentic\CodeQualityMetrics\Business\Cognitive\Exporter;
namespace Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\Exporter;

use Phauthentic\CodeQualityMetrics\Business\Cognitive\CognitiveMetricsCollection;
use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\CognitiveMetricsCollection;
use RuntimeException;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Business/Cognitive/FindMetricsPluginInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Phauthentic\CodeQualityMetrics\Business\Cognitive;
namespace Phauthentic\CognitiveCodeAnalysis\Business\Cognitive;

use SplFileInfo;

Expand Down
2 changes: 1 addition & 1 deletion src/Business/Cognitive/MetricNames.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Phauthentic\CodeQualityMetrics\Business\Cognitive;
namespace Phauthentic\CognitiveCodeAnalysis\Business\Cognitive;

/**
* Enum to represent the metric names.
Expand Down
2 changes: 1 addition & 1 deletion src/Business/Cognitive/ScoreCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Phauthentic\CodeQualityMetrics\Business\Cognitive;
namespace Phauthentic\CognitiveCodeAnalysis\Business\Cognitive;

/**
*
Expand Down
2 changes: 1 addition & 1 deletion src/Business/DirectoryScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Phauthentic\CodeQualityMetrics\Business;
namespace Phauthentic\CognitiveCodeAnalysis\Business;

use FilesystemIterator;
use Generator;
Expand Down
Loading
Loading