Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
86.67% covered (warning)
86.67%
26 / 30
80.00% covered (warning)
80.00%
4 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
Location
86.67% covered (warning)
86.67%
26 / 30
80.00% covered (warning)
80.00%
4 / 5
12.34
0.00% covered (danger)
0.00%
0 / 1
 parseData
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 fetchList
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
3
 fetchFromCsv
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
4
 readSearchResultList
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 fetchListByOffice
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * @package 115Mandant
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsdldb\File;
9
10use BO\Zmsdldb\Entity\Location as Entity;
11use BO\Zmsdldb\Collection\Locations as Collection;
12
13/**
14 * Common methods shared by access classes
15 *
16 * @extends Base<Collection, Entity>
17 */
18class Location extends Base
19{
20    /**
21     * @return Collection
22     */
23    #[\Override]
24    protected function parseData(mixed $data)
25    {
26        $itemList = new Collection();
27        foreach ($data['data'] as $item) {
28            $location = new Entity($item);
29            if ($location->isLocale($this->locale)) {
30                $itemList[$item['id']] = $location;
31            }
32        }
33        return $itemList;
34    }
35
36    /**
37     *
38     * @return Collection
39     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
40     */
41    public function fetchList(bool|string $service_csv = false, bool $mixLanguages = false)
42    {
43        $locationlist = $this->getItemList();
44        if (is_string($service_csv) && $service_csv !== '') {
45            $locationlist = new Collection(array_filter((array) $locationlist, function ($item) use ($service_csv) {
46                $location = new Entity($item);
47                return $location->containsService($service_csv);
48            }));
49        }
50        return $locationlist;
51    }
52
53    /**
54     *
55     * @return Collection
56     * @param bool $mixLanguages unused in file backend, kept for MySQL override compatibility
57     * @psalm-api
58     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
59     */
60    public function fetchFromCsv(mixed $location_csv, bool $mixLanguages = false)
61    {
62        $locationlist = new Collection();
63        foreach (explode(',', $location_csv) as $location_id) {
64            $location = $this->fetchId($location_id);
65            if ($location && $location->isLocale($this->locale)) {
66                $locationlist[$location_id] = $location;
67            }
68        }
69        return $locationlist;
70    }
71
72    /**
73     *
74     * @return \BO\Zmsdldb\Collection\Authorities
75     * @psalm-api
76     */
77    public function readSearchResultList(mixed $query, string $service_csv = '')
78    {
79        $locationlist = $this->fetchList($service_csv);
80        $locationlist = new Collection(array_filter((array) $locationlist, function ($item) use ($query) {
81            return false !== strpos($item['name'], $query);
82        }));
83        return $this->access()
84            ->fromAuthority()
85            ->fromLocationResults($locationlist);
86    }
87
88    /** @psalm-api */
89    public function fetchListByOffice(mixed $office): mixed
90    {
91        return $this->access()->fromAuthority()
92        ->readListByOfficePath($office)
93        ->removeEmptyAuthorities()
94        ->sortByName();
95    }
96}