GetCodeAnalysisUseCase.php

Code Hygiene Score: 100

Keine Issues gefunden.

Dependencies 7

Klassen 1

Funktionen 9

Verwendet von 2

Versionen 6

Code

<?php

declare(strict_types=1);

namespace UseCases\CodeAnalysis;

// @responsibility: Orchestriert Code-Analyse-Abfragen

use Domain\Constants;
use Domain\Repository\DependencyGraphRepositoryInterface;
use Domain\Repository\FileAnalysisRepositoryInterface;
use Domain\Service\CodeScannerInterface;

final class GetCodeAnalysisUseCase
{
    public function __construct(
        private FileAnalysisRepositoryInterface $fileRepository,
        private DependencyGraphRepositoryInterface $dependencyRepository,
        private CodeScannerInterface $scanner
    ) {
    }

    /**
     * @param array<string, mixed> $filters
     * @return array<array<string, mixed>>
     */
    public function execute(array $filters = [], int $limit = Constants::DEFAULT_LIMIT, int $offset = 0): array
    {
        return $this->fileRepository->findAll($filters, $limit, $offset);
    }

    /**
     * @return array<string, mixed>|null
     */
    public function findById(int $id): ?array
    {
        return $this->fileRepository->findById($id);
    }

    /**
     * @return array<string, mixed>
     */
    public function getStatistics(): array
    {
        return $this->fileRepository->getStatistics();
    }

    /**
     * @return array{directories: array<string>, namespaces: array<string>}
     */
    public function getFilterOptions(): array
    {
        return [
            'directories' => $this->fileRepository->getDistinctDirectories(),
            'namespaces' => $this->fileRepository->getDistinctNamespaces(),
        ];
    }

    /**
     * @return array{scan_id: string, files_scanned: int, files_with_errors: int, total_classes: int, total_functions: int, duration_ms: int}
     */
    public function runScan(string $triggeredBy = 'web'): array
    {
        return $this->scanner->scan(null, $triggeredBy);
    }

    public function getLatestScanId(): ?string
    {
        return $this->fileRepository->getLatestScanId();
    }

    /**
     * Find files that depend on a given FQCN.
     *
     * @return array<array{id: int, file_name: string, file_path: string, namespace: string|null, dependency_type: string}>
     */
    public function findDependents(string $fqcn): array
    {
        return $this->dependencyRepository->findDependents($fqcn);
    }

    /**
     * Get global graph data for entire project.
     *
     * @return array{nodes: array<array<string, mixed>>, links: array<array<string, mixed>>, stats: array<string, int>}
     */
    public function getGlobalGraphData(): array
    {
        return $this->dependencyRepository->getGlobalGraphData();
    }
}
← Übersicht Graph