Lines
2.70%
1 / 37
Methods
12.50%
1 / 8
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| containsLocation | 0.00% | 0 / 5 | 0.00% | 0 / 1 | 12 | ||
| getIds | 0.00% | 0 / 4 | 0.00% | 0 / 1 | 6 | ||
| getNames | 0.00% | 0 / 4 | 0.00% | 0 / 1 | 6 | ||
| getCSV | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| isLocale | 0.00% | 0 / 5 | 0.00% | 0 / 1 | 20 | ||
| [BO\Zmsdldb\Collection\Base] offsetSet | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [BO\Zmsdldb\Collection\Base] sortByName | 0.00% | 0 / 5 | 0.00% | 0 / 1 | 2 | ||
| [BO\Zmsdldb\Collection\Base] sortWithCollator | 0.00% | 0 / 12 | 0.00% | 0 / 1 | 6 | ||
| 13 | class Services extends Base | |
| 14 | { | |
| 15 | /** | |
| 16 | * @param null|string $locationCsv | |
| 17 | */ | |
| 18 | public function containsLocation(string|null $locationCsv = null): self | |
| 19 | { | |
| 20 | $list = new self(); | |
| 21 | foreach ($this as $service) { | |
| 22 | if ($service->containsLocation($locationCsv)) { | |
| 23 | $list->append($service); | |
| 24 | } | |
| 25 | } | |
| 26 | return $list; | |
| 27 | } | |
| 28 | ||
| 29 | public function getIds(): array | |
| 30 | { | |
| 31 | $idList = array(); | |
| 32 | foreach ($this as $service) { | |
| 33 | $idList[] = $service['id']; | |
| 34 | } | |
| 35 | return $idList; | |
| 36 | } | |
| 37 | ||
| 38 | /** | |
| 39 | * @psalm-api | |
| 40 | */ | |
| 41 | public function getNames(): array | |
| 42 | { | |
| 43 | $nameList = array(); | |
| 44 | foreach ($this as $service) { | |
| 45 | $nameList[$service['id']] = $service['name']; | |
| 46 | } | |
| 47 | return $nameList; | |
| 48 | } | |
| 49 | ||
| 50 | /** | |
| 51 | * @psalm-api | |
| 52 | */ | |
| 53 | public function getCSV(): string | |
| 54 | { | |
| 55 | return implode(',', $this->getIds()); | |
| 56 | } | |
| 57 | ||
| 58 | /** | |
| 59 | * @psalm-api | |
| 60 | * | |
| 61 | * @return null|self | |
| 62 | */ | |
| 63 | public function isLocale(mixed $locale): self|null | |
| 64 | { | |
| 65 | $list = new self(); | |
| 66 | foreach ($this as $service) { | |
| 67 | if ($service->isLocale($locale)) { | |
| 68 | $list->append($service); | |
| 69 | } | |
| 70 | } | |
| 71 | return (count($list)) ? $list : null; | |
| 72 | } | |
| 73 | } |
Inherited from BO\Zmsdldb\Collection\Base
| 19 | public function offsetSet(mixed $key, mixed $value): void | |
| 20 | { | |
| 21 | parent::offsetSet($key, $value); | |
| 22 | } |
| 24 | public function sortByName(): static | |
| 25 | { | |
| 26 | $itemList = clone $this; | |
| 27 | $itemList->uasort(function ($a, $b) { | |
| 28 | return strcmp(Sorter::toSortableString($a->getName()), Sorter::toSortableString($b->getName())); | |
| 29 | }); | |
| 30 | return $itemList; | |
| 31 | } |
| 36 | public function sortWithCollator(string $field = 'name', string $locale = 'de'): static | |
| 37 | { | |
| 38 | $collator = collator_create($locale); | |
| 39 | if ($collator === null) { | |
| 40 | throw new \RuntimeException('Could not create collator for locale ' . $locale); | |
| 41 | } | |
| 42 | $collator->setStrength(\Collator::QUATERNARY); | |
| 43 | $collator->setAttribute(\Collator::QUATERNARY, \Collator::ON); | |
| 44 | $collator->setAttribute(\Collator::CASE_FIRST, \Collator::ON); | |
| 45 | $collator->setAttribute(\Collator::NUMERIC_COLLATION, \Collator::ON); | |
| 46 | ||
| 47 | $itemList = clone $this; | |
| 48 | $itemList->uasort(function ($itemA, $itemB) use ($collator, $field) { | |
| 49 | return collator_compare($collator, $itemA[$field], $itemB[$field]); | |
| 50 | }); | |
| 51 | return $itemList; | |
| 52 | } |