Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
AbstractTransport | n/a |
0 / 0 |
n/a |
0 / 0 |
18 | n/a |
0 / 0 |
|||
getName | n/a |
0 / 0 |
0 | n/a |
0 / 0 |
|||||
getIdentifier | n/a |
0 / 0 |
0 | n/a |
0 / 0 |
|||||
send | n/a |
0 / 0 |
0 | n/a |
0 / 0 |
|||||
getHelpMessage | n/a |
0 / 0 |
9 | n/a |
0 / 0 |
|||||
getLabelMessage | n/a |
0 / 0 |
9 | n/a |
0 / 0 |
1 | <?php |
2 | |
3 | // {{{ License |
4 | // This file is part of GNU social - https://www.gnu.org/software/social |
5 | // |
6 | // GNU social is free software: you can redistribute it and/or modify |
7 | // it under the terms of the GNU Affero General Public License as published by |
8 | // the Free Software Foundation, either version 3 of the License, or |
9 | // (at your option) any later version. |
10 | // |
11 | // GNU social is distributed in the hope that it will be useful, |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | // GNU Affero General Public License for more details. |
15 | // |
16 | // You should have received a copy of the GNU Affero General Public License |
17 | // along with GNU social. If not, see <http://www.gnu.org/licenses/>. |
18 | // }}} |
19 | |
20 | /** |
21 | * Base class for Transports |
22 | * |
23 | * @package GNUsocial |
24 | * @category Util |
25 | * |
26 | * @author Hugo Sales <hugo@hsal.es> |
27 | * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org |
28 | * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later |
29 | */ |
30 | |
31 | namespace App\Util\Notification; |
32 | |
33 | use function App\Core\I18n\_m; |
34 | |
35 | /** |
36 | * @codeCoverageIgnore |
37 | */ |
38 | abstract class AbstractTransport |
39 | { |
40 | /** |
41 | * Get the display name of this transport |
42 | */ |
43 | abstract public function getName(): string; |
44 | |
45 | /** |
46 | * Get the identifier used in code for this transport |
47 | */ |
48 | abstract public function getIdentifier(): string; |
49 | |
50 | /** |
51 | * Send a given Notification through this transport |
52 | */ |
53 | abstract public function send(Notification $n): bool; |
54 | |
55 | /** |
56 | * Get the display help message for one of the Notification-constants type |
57 | */ |
58 | public function getHelpMessage(int $t): string |
59 | { |
60 | switch ($t) { |
61 | case Notification::NOTICE_BY_FOLLOWED: |
62 | return _m('Send me alerts of mentions by those I follow through {name}', ['{name}' => $this->getName()]); |
63 | case Notification::MENTION: |
64 | return _m('Send me alerts of mentions through {name}', ['{name}' => $this->getName()]); |
65 | case Notification::REPLY: |
66 | return _m('Send me alerts of replies to my notice through {name}', ['{name}' => $this->getName()]); |
67 | case Notification::FOLLOW: |
68 | return _m('Send me alerts of new follows through {name}', ['{name}' => $this->getName()]); |
69 | case Notification::FAVORITE: |
70 | return _m('Send me alerts of new favorites on my notices through {name}', ['{name}' => $this->getName()]); |
71 | case Notification::NUDGE: |
72 | return _m('Send me alerts when someone calls for my attention through {name}', ['{name}' => $this->getName()]); |
73 | case Notification::DM: |
74 | return _m('Send me alerts of new direct messages through {name}', ['{name}' => $this->getName()]); |
75 | default: |
76 | throw new \InvalidArgumentException('Given an invalid Notification constant value'); |
77 | } |
78 | } |
79 | |
80 | /** |
81 | * Get the display label message for one of the Notification-constants type |
82 | */ |
83 | public function getLabelMessage(int $t): string |
84 | { |
85 | switch ($t) { |
86 | case Notification::NOTICE_BY_FOLLOWED: |
87 | return _m('Notify me of new notices'); |
88 | case Notification::MENTION: |
89 | return _m('Notify me of mentions'); |
90 | case Notification::REPLY: |
91 | return _m('Notify me of replies'); |
92 | case Notification::FOLLOW: |
93 | return _m('Notify me of new follows'); |
94 | case Notification::FAVORITE: |
95 | return _m('Notify me of new favorites'); |
96 | case Notification::NUDGE: |
97 | return _m('Notify me when nudged'); |
98 | case Notification::DM: |
99 | return _m('Notify of new DMs'); |
100 | default: |
101 | throw new \InvalidArgumentException('Given an invalid Notification constant value'); |
102 | } |
103 | } |
104 | } |