Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
FamilyResolveIdService
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
20
0.00% covered (danger)
0.00%
0 / 1
 resolveFamilyId
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3namespace Domain\Category\Services;
4
5use Illuminate\Support\Facades\Cache;
6
7use Domain\Integration\Exceptions\IntegrationNotFoundException;
8use Domain\Shared\Integrations\Senior\Exceptions\IntegrationSoapSeniorException;
9
10use App\Models\Category\Family;
11
12class FamilyResolveIdService
13{
14    public static function resolveFamilyId(string $codfam, string $codemp): int
15    {
16        $families = Cache::remember('job-families', 300, function () {
17            return Family::with(['integration'])->get()->toArray();
18        });
19
20        $family = array_filter($families, function ($family) use ($codfam, $codemp) {
21            if (!isset($family['integration'])) {
22                throw new IntegrationNotFoundException(
23                    __("Non-localized integration for family")
24                );
25            }
26
27            return $family['integration']['parameters']['integration_code']    == $codfam
28                && $family['integration']['parameters']['integration_company'] == $codemp;
29        });
30
31        if (empty($family)) {
32            throw new IntegrationSoapSeniorException(
33                __("Family :family not found!", ["family" => $codfam])
34            );
35        }
36
37        return array_values($family)[0]['id'];
38    }
39}