Lines 96.77% 30 / 31
Functions and Methods 75.00% 3 / 4
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
Matching 96.77% 30 / 31 75.00% 3 / 4 12 0.00% 0 / 1
 hasProviderRequest 100.00% 10 / 10 100.00% 1 / 1 3
 isProviderExisting 100.00% 6 / 6 100.00% 1 / 1 2
 isRequestExisting 100.00% 6 / 6 100.00% 1 / 1 3
 testCurrentScopeHasRequest 88.88% 8 / 9 0.00% 0 / 1 4.02
1<?php
2
3namespace BO\Zmsbackend\Helper;
4
5use BO\Mellon\Validator;
6use BO\Zmsbackend\Provider\Service\Provider;
7use BO\Zmsbackend\Request\Service\Request;
8
9/**
10 * example class to generate a response
11 */
12class Matching
13{
14    public static function hasProviderRequest($session)
15    {
16        $result = true;
17        $requestIdCsv = $session->getRequests();
18        $providerList = (new \BO\Zmsbackend\Provider\Service\Provider())->readListBySource($session->getSource(), 0, null, $requestIdCsv);
19        if ($session->hasProvider()) {
20            $providerIdCsv = $session->getProviders();
21            $result = $providerList->hasProvider($providerIdCsv);
22        } elseif ($session->hasScope()) {
23            $scope = (new \BO\Zmsbackend\Scope\Service\Scope())->readEntity($session->getScope(), 1);
24            $result = $providerList->hasProvider($scope->getProviderId());
25        }
26        return $result;
27    }
28
29    public static function isProviderExisting($session)
30    {
31        $result = true;
32        if ($session->hasProvider()) {
33            $providerIdCsv = $session->getProviders();
34            $providerList = (new \BO\Zmsbackend\Provider\Service\Provider())->readListBySource($session->getSource());
35            $result = $providerList->hasProvider($providerIdCsv);
36        }
37        return $result;
38    }
39
40    public static function isRequestExisting($session): bool
41    {
42        $result = true;
43        if ($session->hasRequests()) {
44            $requestIdCsv = $session->getRequests();
45            $providerList = (new \BO\Zmsbackend\Provider\Service\Provider())->readListBySource($session->getSource(), 1, null, $requestIdCsv);
46            $result = (count($providerList)) ? true : false;
47        }
48        return $result;
49    }
50
51    /**
52     * @return void
53     */
54    public static function testCurrentScopeHasRequest(\BO\Zmsentities\Process $process)
55    {
56        if (0 === count($process->getRequestIds())) {
57            return;
58        }
59
60        $scope = (new \BO\Zmsbackend\Scope\Service\Scope())->readEntity($process->getScopeId(), 1);
61        if (!$scope instanceof \BO\Zmsentities\Scope) {
62            throw new \BO\Zmsbackend\Scope\Exception\ScopeNotFound();
63        }
64        $requestRelationList = (new \BO\Zmsbackend\RequestRelation\Service\RequestRelation())
65            ->readListByProviderId($scope->getProviderId(), $scope->getSource());
66
67        if (!$requestRelationList->hasRequest($process->getRequestCSV())) {
68            throw new \BO\Zmsbackend\Matching\Exception\RequestNotFound();
69        }
70    }
71}