Lines
2.50%
1 / 40
Methods
14.28%
1 / 7
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| getNames | 0.00% | 0 / 4 | 0.00% | 0 / 1 | 6 | ||
| toSearchResultData | 0.00% | 0 / 8 | 0.00% | 0 / 1 | 20 | ||
| addSearchResultsData | 0.00% | 0 / 4 | 0.00% | 0 / 1 | 6 | ||
| sortByType | 0.00% | 0 / 6 | 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 | ||
| 15 | class SearchResults extends Base | |
| 16 | { | |
| 17 | /** | |
| 18 | * @psalm-api | |
| 19 | */ | |
| 20 | public function getNames(): array | |
| 21 | { | |
| 22 | $nameList = array(); | |
| 23 | foreach ($this as $item) { | |
| 24 | $nameList[$item->getId()] = $item->getName(); | |
| 25 | } | |
| 26 | return $nameList; | |
| 27 | } | |
| 28 | ||
| 29 | /** | |
| 30 | * @psalm-api | |
| 31 | */ | |
| 32 | public function toSearchResultData(): self | |
| 33 | { | |
| 34 | $list = new self(); | |
| 35 | foreach ($this as $results) { | |
| 36 | foreach ($results as $data) { | |
| 37 | if (count($data)) { | |
| 38 | $item = Entity::create($data); | |
| 39 | $list->append($item); | |
| 40 | } | |
| 41 | } | |
| 42 | $list; | |
| 43 | } | |
| 44 | return $list; | |
| 45 | } | |
| 46 | ||
| 47 | /** | |
| 48 | * @psalm-api | |
| 49 | * | |
| 50 | * @return null|static | |
| 51 | */ | |
| 52 | public function addSearchResultsData(mixed $data): static|null | |
| 53 | { | |
| 54 | if ($data) { | |
| 55 | $this->append($data); | |
| 56 | return $this; | |
| 57 | } | |
| 58 | return null; | |
| 59 | } | |
| 60 | ||
| 61 | /** | |
| 62 | * @psalm-api | |
| 63 | */ | |
| 64 | public function sortByType(array $order): self | |
| 65 | { | |
| 66 | $list = new self(); | |
| 67 | foreach ($order as $type) { | |
| 68 | foreach ($this as $item) { | |
| 69 | if ($item->getType() == $type) { | |
| 70 | $list->append($item); | |
| 71 | } | |
| 72 | } | |
| 73 | } | |
| 74 | return $list; | |
| 75 | } | |
| 76 | } |
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 | } |