Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
16 / 16 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| ExtensionTestingReportRepository | |
100.00% |
16 / 16 |
|
100.00% |
6 / 6 |
9 | |
100.00% |
1 / 1 |
| listAll | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
4 | |||
| findById | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| findByArtifactAndUser | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| create | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| update | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| delete | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Repositories; |
| 4 | |
| 5 | use App\Http\Models\ExtensionTestingReport; |
| 6 | use Illuminate\Support\Collection; |
| 7 | |
| 8 | /** |
| 9 | * Repository for Extension Testing Report data access operations. |
| 10 | * |
| 11 | * Handles all database queries related to testing reports, keeping |
| 12 | * data access logic separate from business logic. |
| 13 | */ |
| 14 | class ExtensionTestingReportRepository |
| 15 | { |
| 16 | /** |
| 17 | * List all testing reports with optional filters. |
| 18 | * |
| 19 | * @param array{artifact_id?: string, environment?: string, status?: string} $filters Optional filters |
| 20 | * @return Collection<int, ExtensionTestingReport> |
| 21 | */ |
| 22 | public function listAll(array $filters = []): Collection |
| 23 | { |
| 24 | $query = ExtensionTestingReport::query()->orderBy('created_at', 'desc'); |
| 25 | |
| 26 | if (! empty($filters['artifact_id'])) { |
| 27 | $query->byArtifact($filters['artifact_id']); |
| 28 | } |
| 29 | |
| 30 | if (! empty($filters['environment'])) { |
| 31 | $query->byEnvironment($filters['environment']); |
| 32 | } |
| 33 | |
| 34 | if (! empty($filters['status'])) { |
| 35 | $query->byStatus($filters['status']); |
| 36 | } |
| 37 | |
| 38 | return $query->get(); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Find a testing report by its ID. |
| 43 | * |
| 44 | * @param string $id The report ID |
| 45 | */ |
| 46 | public function findById(string $id): ?ExtensionTestingReport |
| 47 | { |
| 48 | return ExtensionTestingReport::find($id); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Find a testing report by artifact ID and user ID (one per user per artifact). |
| 53 | * |
| 54 | * @param string $artifactId The artifact identifier |
| 55 | * @param string $userId The user ID |
| 56 | */ |
| 57 | public function findByArtifactAndUser(string $artifactId, string $userId): ?ExtensionTestingReport |
| 58 | { |
| 59 | return ExtensionTestingReport::where('artifact_id', $artifactId) |
| 60 | ->where('created_by', $userId) |
| 61 | ->first(); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Create a new testing report. |
| 66 | * |
| 67 | * @param array{name: string, version_tested: string, environment: string, artifact_id: string, tester_name: string, created_by: string, status: string, domains: array} $data |
| 68 | */ |
| 69 | public function create(array $data): ExtensionTestingReport |
| 70 | { |
| 71 | return ExtensionTestingReport::create($data); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Update an existing testing report. |
| 76 | * |
| 77 | * @param ExtensionTestingReport $report The report to update |
| 78 | * @param array{name?: string, version_tested?: string, status?: string, domains?: array, tester_name?: string} $data The update data |
| 79 | */ |
| 80 | public function update(ExtensionTestingReport $report, array $data): ExtensionTestingReport |
| 81 | { |
| 82 | $report->update($data); |
| 83 | |
| 84 | return $report->fresh(); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Delete a testing report. |
| 89 | * |
| 90 | * @param ExtensionTestingReport $report The report to delete |
| 91 | */ |
| 92 | public function delete(ExtensionTestingReport $report): bool |
| 93 | { |
| 94 | return $report->delete(); |
| 95 | } |
| 96 | } |