Lines 0.00% 0 / 12
Functions and Methods 0.00% 0 / 1
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
MailtemplateList 0.00% 0 / 12 0.00% 0 / 1 12 0.00% 0 / 1
 prioritizeByName 0.00% 0 / 12 0.00% 0 / 1 12
1<?php
2
3namespace BO\Zmsentities\Collection;
4
5/**
6 * @extends Base<\BO\Zmsentities\Mailtemplate>
7 */
8class MailtemplateList extends Base
9{
10    public const string ENTITY_CLASS = '\BO\Zmsentities\Mailtemplate';
11
12    public function prioritizeByName(array $priorityNames): static
13    {
14        $prioritized = [];
15        $others = [];
16
17        foreach ($this as $key => $mailtemplate) {
18            $name = $mailtemplate->name;
19            if (in_array($name, $priorityNames)) {
20                $index = array_search($name, $priorityNames);
21                $prioritized[$index] = $mailtemplate;
22            } else {
23                $others[$key] = $mailtemplate;
24            }
25        }
26
27        ksort($prioritized);
28
29        $mergedList = array_merge($prioritized, $others);
30
31        $this->exchangeArray($mergedList);
32
33        return $this;
34    }
35}