Total Complexity | 8 |
Total Lines | 72 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | abstract class Recipient |
||
8 | { |
||
9 | /** |
||
10 | * @return array|string |
||
11 | */ |
||
12 | abstract public function getTo(); |
||
13 | |||
14 | /** |
||
15 | * @return string |
||
16 | */ |
||
17 | abstract public function getMessage(): string; |
||
18 | |||
19 | /** |
||
20 | * @return bool |
||
21 | */ |
||
22 | abstract public function useIconv(): bool; |
||
23 | |||
24 | /** |
||
25 | * @return bool |
||
26 | */ |
||
27 | abstract public function asMulti(): bool; |
||
28 | |||
29 | /** |
||
30 | * @return array |
||
31 | */ |
||
32 | public function buildMessage(): array |
||
33 | { |
||
34 | $options = []; |
||
35 | |||
36 | if ($this->asMulti()) { |
||
37 | /** @var To $to */ |
||
38 | foreach ($this->getTo() as $to) { |
||
39 | $options['multi'][$to->getTo()] = $this->defineEncoding($to->getMessage()); |
||
40 | } |
||
41 | |||
42 | return $options; |
||
43 | } |
||
44 | |||
45 | $options['to'] = $this->collapseRecipients($this->getTo()); |
||
46 | $options['msg'] = $this->defineEncoding($this->getMessage()); |
||
47 | |||
48 | return $options; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @param string $message |
||
53 | * |
||
54 | * @return bool|false|string |
||
55 | */ |
||
56 | private function defineEncoding(string $message) |
||
57 | { |
||
58 | return $this->useIconv() ? $this->toIconv($message) : $message; |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @param $tos |
||
63 | * |
||
64 | * @return string |
||
65 | */ |
||
66 | private function collapseRecipients($tos): string |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * @param string $message |
||
73 | * |
||
74 | * @return bool|false|string |
||
75 | */ |
||
76 | private function toIconv(string $message) |
||
79 | } |
||
80 | } |
||
81 |