Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
14 / 14 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| CompanyRolePlayScorecardRepository | |
100.00% |
14 / 14 |
|
100.00% |
4 / 4 |
5 | |
100.00% |
1 / 1 |
| listForCompany | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| findForCompanyAndCallType | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| upsertForCompanyAndCallType | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| deleteForCompanyAndCallType | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Repositories; |
| 4 | |
| 5 | use App\Http\Models\CompanyRolePlayScorecard; |
| 6 | use App\Http\Repositories\interfaces\ICompanyRolePlayScorecardRepository; |
| 7 | use Illuminate\Support\Collection; |
| 8 | |
| 9 | /** |
| 10 | * Repository for company-level RolePlay scorecard data access. |
| 11 | * |
| 12 | * Wraps the CompanyRolePlayScorecard query scopes so controllers and |
| 13 | * services never touch the model directly (Controller → Service → |
| 14 | * Repository → Model per CLAUDE.MD). |
| 15 | */ |
| 16 | class CompanyRolePlayScorecardRepository implements ICompanyRolePlayScorecardRepository |
| 17 | { |
| 18 | /** |
| 19 | * {@inheritDoc} |
| 20 | */ |
| 21 | public function listForCompany(string $companyId): Collection |
| 22 | { |
| 23 | return CompanyRolePlayScorecard::forCompany($companyId) |
| 24 | ->orderBy('call_type') |
| 25 | ->get(); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * {@inheritDoc} |
| 30 | */ |
| 31 | public function findForCompanyAndCallType(string $companyId, string $callType): ?CompanyRolePlayScorecard |
| 32 | { |
| 33 | return CompanyRolePlayScorecard::forCompany($companyId) |
| 34 | ->forCallType($callType) |
| 35 | ->first(); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * {@inheritDoc} |
| 40 | */ |
| 41 | public function upsertForCompanyAndCallType(string $companyId, string $callType, array $attributes): CompanyRolePlayScorecard |
| 42 | { |
| 43 | return CompanyRolePlayScorecard::updateOrCreate( |
| 44 | ['company_id' => $companyId, 'call_type' => $callType], |
| 45 | $attributes |
| 46 | )->fresh(); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * {@inheritDoc} |
| 51 | */ |
| 52 | public function deleteForCompanyAndCallType(string $companyId, string $callType): bool |
| 53 | { |
| 54 | $scorecard = $this->findForCompanyAndCallType($companyId, $callType); |
| 55 | |
| 56 | if (! $scorecard) { |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | return (bool) $scorecard->delete(); |
| 61 | } |
| 62 | } |