Files
michaelschiemer/src/Framework/Design/Analyzer/ComponentDetectionResult.php
Michael Schiemer 9b74ade5b0 feat: Fix discovery system critical issues
Resolved multiple critical discovery system issues:

## Discovery System Fixes
- Fixed console commands not being discovered on first run
- Implemented fallback discovery for empty caches
- Added context-aware caching with separate cache keys
- Fixed object serialization preventing __PHP_Incomplete_Class

## Cache System Improvements
- Smart caching that only caches meaningful results
- Separate caches for different execution contexts (console, web, test)
- Proper array serialization/deserialization for cache compatibility
- Cache hit logging for debugging and monitoring

## Object Serialization Fixes
- Fixed DiscoveredAttribute serialization with proper string conversion
- Sanitized additional data to prevent object reference issues
- Added fallback for corrupted cache entries

## Performance & Reliability
- All 69 console commands properly discovered and cached
- 534 total discovery items successfully cached and restored
- No more __PHP_Incomplete_Class cache corruption
- Improved error handling and graceful fallbacks

## Testing & Quality
- Fixed code style issues across discovery components
- Enhanced logging for better debugging capabilities
- Improved cache validation and error recovery

Ready for production deployment with stable discovery system.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-13 12:04:17 +02:00

167 lines
5.0 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Framework\Design\Analyzer;
use App\Framework\Design\ValueObjects\ComponentPattern;
/**
* Ergebnis der Component-Pattern-Erkennung
*/
final readonly class ComponentDetectionResult
{
/**
* @param ComponentPattern[] $bemComponents
* @param ComponentPattern[] $utilityComponents
* @param ComponentPattern[] $traditionalComponents
*/
public function __construct(
public int $totalComponents,
public array $bemComponents,
public array $utilityComponents,
public array $traditionalComponents,
public array $patternStatistics,
public array $recommendations
) {
}
/**
* Gibt die dominante Pattern-Methodik zurück
*/
public function getDominantPattern(): string
{
$counts = [
'bem' => count($this->bemComponents),
'utility' => count($this->utilityComponents),
'traditional' => count($this->traditionalComponents),
];
$max = max($counts);
if ($max === 0) {
return 'none';
}
return array_search($max, $counts);
}
/**
* Gibt Pattern-Diversity-Score zurück (0-100)
*/
public function getPatternDiversity(): int
{
$patterns = [$this->bemComponents, $this->utilityComponents, $this->traditionalComponents];
$nonEmptyPatterns = array_filter($patterns, fn ($p) => ! empty($p));
if (empty($nonEmptyPatterns)) {
return 0;
}
// Je mehr verschiedene Pattern-Typen verwendet werden, desto höher die Diversity
$diversityScore = (count($nonEmptyPatterns) / 3) * 100;
return (int) round($diversityScore);
}
/**
* Gibt Konsistenz-Score zurück (0-100)
*/
public function getConsistencyScore(): int
{
$totalComponents = $this->totalComponents;
if ($totalComponents === 0) {
return 100;
}
$dominantCount = max(
count($this->bemComponents),
count($this->utilityComponents),
count($this->traditionalComponents)
);
// Je höher der Anteil der dominanten Methodik, desto konsistenter
$consistencyScore = ($dominantCount / $totalComponents) * 100;
return (int) round($consistencyScore);
}
/**
* Gibt empfohlene Aktionen basierend auf der Analyse zurück
*/
public function getActionableRecommendations(): array
{
$actions = [];
$consistency = $this->getConsistencyScore();
$diversity = $this->getPatternDiversity();
if ($consistency < 60 && $diversity > 80) {
$actions[] = [
'priority' => 'high',
'action' => 'standardize_methodology',
'description' => 'Standardize on one primary CSS methodology to improve consistency.',
];
}
if (count($this->bemComponents) > 5 && count($this->utilityComponents) < 3) {
$actions[] = [
'priority' => 'medium',
'action' => 'add_utilities',
'description' => 'Add utility classes for common spacing, colors, and typography.',
];
}
if (count($this->traditionalComponents) > 10) {
$actions[] = [
'priority' => 'medium',
'action' => 'refactor_to_bem',
'description' => 'Consider refactoring traditional components to BEM methodology.',
];
}
return $actions;
}
/**
* Gibt Pattern-Verteilung zurück
*/
public function getPatternDistribution(): array
{
$total = $this->totalComponents;
if ($total === 0) {
return [
'bem' => 0,
'utility' => 0,
'traditional' => 0,
];
}
return [
'bem' => round((count($this->bemComponents) / $total) * 100, 1),
'utility' => round((count($this->utilityComponents) / $total) * 100, 1),
'traditional' => round((count($this->traditionalComponents) / $total) * 100, 1),
];
}
/**
* Konvertiert zu Array für Export
*/
public function toArray(): array
{
return [
'total_components' => $this->totalComponents,
'bem_components' => array_map(fn (ComponentPattern $p) => $p->toArray(), $this->bemComponents),
'utility_components' => array_map(fn (ComponentPattern $p) => $p->toArray(), $this->utilityComponents),
'traditional_components' => array_map(fn (ComponentPattern $p) => $p->toArray(), $this->traditionalComponents),
'pattern_statistics' => $this->patternStatistics,
'recommendations' => $this->recommendations,
'dominant_pattern' => $this->getDominantPattern(),
'pattern_diversity' => $this->getPatternDiversity(),
'consistency_score' => $this->getConsistencyScore(),
'actionable_recommendations' => $this->getActionableRecommendations(),
];
}
}