Skip to content

Commit f20fcb4

Browse files
Optional Cache to speedup consecutive Runs (#56)
1 parent ff4f2c5 commit f20fcb4

27 files changed

Lines changed: 1507 additions & 301 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
!/bin/phpcca.bat
55
/.phive/
66
/.phpunit.cache/
7+
/.phpcca.cache/
78
/tmp/
89
/tools/
910
/benchmarks/storage/

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"require": {
66
"php": "^8.1",
77
"nikic/php-parser": "^5.1",
8+
"psr/cache": "^3.0",
89
"symfony/console": "^6.0||^7.0",
910
"symfony/config": "^6.0||^7.0",
1011
"symfony/yaml": "^6.0||^7.0",

composer.lock

Lines changed: 2 additions & 212 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ cognitive:
4040
threshold: 1
4141
scale: 1.0
4242
enabled: true
43+
cache:
44+
enabled: false
45+
directory: './.phpcca.cache'
4346
# Example of custom reporters:
4447
# customReporters:
4548
# cognitive:

src/Application.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\ScoreCalculator;
2222
use Phauthentic\CognitiveCodeAnalysis\Business\MetricsFacade;
2323
use Phauthentic\CognitiveCodeAnalysis\Business\Utility\DirectoryScanner;
24+
use Phauthentic\CognitiveCodeAnalysis\Cache\FileCache;
2425
use Phauthentic\CognitiveCodeAnalysis\Command\ChurnCommand;
2526
use Phauthentic\CognitiveCodeAnalysis\Command\ChurnSpecifications\ChurnValidationSpecificationFactory;
2627
use Phauthentic\CognitiveCodeAnalysis\Command\CognitiveMetricsCommand;
@@ -42,6 +43,7 @@
4243
use PhpParser\NodeTraverser;
4344
use PhpParser\NodeTraverserInterface;
4445
use PhpParser\ParserFactory;
46+
use Psr\Cache\CacheItemPoolInterface;
4547
use Symfony\Component\Config\Definition\Processor;
4648
use Symfony\Component\Console\Application as SymfonyApplication;
4749
use Symfony\Component\Console\Input\ArgvInput;
@@ -99,6 +101,12 @@ private function registerCoreServices(): void
99101
$this->containerBuilder->register(ConfigService::class, ConfigService::class)
100102
->setPublic(true);
101103

104+
$this->containerBuilder->register(CacheItemPoolInterface::class, FileCache::class)
105+
->setArguments([
106+
'./.phpcca.cache' // Default cache directory, can be overridden by config
107+
])
108+
->setPublic(true);
109+
102110
$this->containerBuilder->register(Baseline::class, Baseline::class)
103111
->setPublic(true);
104112

@@ -242,7 +250,8 @@ private function bootstrapMetricsCollectors(): void
242250
new Reference(Parser::class),
243251
new Reference(DirectoryScanner::class),
244252
new Reference(ConfigService::class),
245-
new Reference(MessageBusInterface::class)
253+
new Reference(MessageBusInterface::class),
254+
new Reference(CacheItemPoolInterface::class)
246255
])
247256
->setPublic(true);
248257
}

src/Business/Cognitive/CognitiveMetricsCollection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ public function groupBy(string $property): array
130130
$grouped[$key]->add($metric);
131131
}
132132

133+
ksort($grouped);
134+
133135
return $grouped;
134136
}
135137

0 commit comments

Comments
 (0)