Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
97.67% covered (success)
97.67%
42 / 43
85.71% covered (warning)
85.71%
6 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
ProviderList
97.67% covered (success)
97.67%
42 / 43
85.71% covered (warning)
85.71%
6 / 7
24
0.00% covered (danger)
0.00%
0 / 1
 hasProvider
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 hasProviderStrict
80.00% covered (warning)
80.00%
4 / 5
0.00% covered (danger)
0.00%
0 / 1
3.07
 hasRequest
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
4
 withMatchingByList
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 withUniqueProvider
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
4
 withDataAsObject
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
6
 sortById
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace BO\Zmsentities\Collection;
4
5/**
6 * @extends Base<\BO\Zmsentities\Provider>
7 */
8class ProviderList extends Base
9{
10    public const ENTITY_CLASS = '\BO\Zmsentities\Provider';
11
12    public function hasProvider($providerIdCsv)
13    {
14        $providerFound = false;
15        $providerIds = explode(',', $providerIdCsv);
16        foreach ($providerIds as $providerId) {
17            if (in_array($providerId, $this->getIds())) {
18                $providerFound = true;
19            }
20        }
21        return $providerFound;
22    }
23
24    public function hasProviderStrict($providerIdCsv)
25    {
26        $providerIds = explode(',', $providerIdCsv);
27        foreach ($providerIds as $providerId) {
28            if (! in_array($providerId, $this->getIds())) {
29                return false;
30            }
31        }
32        return true;
33    }
34
35    public function hasRequest($requestIdCsv)
36    {
37        $requestIds = explode(',', $requestIdCsv);
38        foreach ($this as $entity) {
39            foreach ($requestIds as $requestId) {
40                if ($entity->hasRequest($requestId)) {
41                    return true;
42                }
43            }
44        }
45        return false;
46    }
47
48    public function withMatchingByList($providerIdCsv)
49    {
50        $collection = new self();
51        $providerIds = explode(',', $providerIdCsv);
52        foreach ($providerIds as $providerId) {
53            if (in_array($providerId, $this->getIds())) {
54                $collection->addEntity($this->getEntity($providerId));
55            }
56        }
57        return $collection;
58    }
59
60    public function withUniqueProvider()
61    {
62        $list = new self();
63        foreach ($this as $provider) {
64            if ($provider && ! $list->hasEntity($provider->id)) {
65                $list->addEntity($provider);
66            }
67        }
68        return $list;
69    }
70
71    public function withDataAsObject()
72    {
73        $list = new self();
74        foreach ($this as $provider) {
75            if (isset($provider['data']) && '{}' != $provider->data) {
76                if (is_string($provider->data)) {
77                    $provider->data = json_decode($provider->data);
78                } elseif (is_array($provider->data)) {
79                    $provider->data = json_decode(json_encode($provider->data, JSON_FORCE_OBJECT));
80                }
81            } else {
82                unset($provider['data']);
83            }
84            $list->addEntity($provider);
85        }
86        return $list;
87    }
88
89    public function sortById()
90    {
91        $list = clone $this;
92        $list->uasort(function ($a, $b) {
93            return ($a['id'] - $b['id']);
94        });
95        return (new self())->addList($list);
96    }
97}