1 | <?php |
||||||
2 | |||||||
3 | namespace Mamaduka\BpNotifications\Messages; |
||||||
4 | |||||||
5 | class AtMentionMessage implements Message { |
||||||
6 | |||||||
7 | /** |
||||||
8 | * Notification message data. |
||||||
9 | * |
||||||
10 | * @var array |
||||||
11 | */ |
||||||
12 | protected $data; |
||||||
13 | |||||||
14 | /** |
||||||
15 | * Create a new message instance. |
||||||
16 | * |
||||||
17 | * @param array $data |
||||||
18 | * @return void |
||||||
19 | */ |
||||||
20 | 1 | public function __construct( array $data = [] ) { |
|||||
21 | 1 | $this->data = $data; |
|||||
22 | 1 | } |
|||||
23 | |||||||
24 | /** |
||||||
25 | * Get message text. |
||||||
26 | * |
||||||
27 | * @return string |
||||||
28 | */ |
||||||
29 | 2 | View Code Duplication | public function message() { |
||||
0 ignored issues
–
show
|
|||||||
30 | 2 | if ( $this->data['total'] > 1 ) { |
|||||
31 | 1 | return sprintf( 'You have %1$d new mentions', (int) $this->data['total'] ); |
|||||
32 | } |
||||||
33 | |||||||
34 | 1 | return sprintf( '%1$s mentioned you', bp_core_get_user_displayname( $this->data['user_id' ] ) ); |
|||||
0 ignored issues
–
show
The function
bp_core_get_user_displayname was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
35 | } |
||||||
36 | |||||||
37 | /** |
||||||
38 | * Get message URL. |
||||||
39 | * |
||||||
40 | * @return string |
||||||
41 | */ |
||||||
42 | 1 | public function url() { |
|||||
43 | 1 | return bp_loggedin_user_domain() . bp_get_activity_slug() . '/mentions/'; |
|||||
0 ignored issues
–
show
The function
bp_get_activity_slug was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() The function
bp_loggedin_user_domain was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
44 | } |
||||||
45 | |||||||
46 | /** |
||||||
47 | * Get the array representation of the message. |
||||||
48 | * |
||||||
49 | * @return array |
||||||
50 | */ |
||||||
51 | 1 | public function toArray() { |
|||||
52 | return [ |
||||||
53 | 1 | 'text' => $this->message(), |
|||||
54 | 1 | 'link' => $this->url(), |
|||||
55 | ]; |
||||||
56 | } |
||||||
57 | |||||||
58 | /** |
||||||
59 | * Get the HTML representation of the message. |
||||||
60 | * |
||||||
61 | * @return string |
||||||
62 | */ |
||||||
63 | 1 | public function toHtml() { |
|||||
64 | 1 | return sprintf( |
|||||
65 | 1 | '<a href="%1$s">%2$s</a>', |
|||||
66 | 1 | esc_url( $this->url() ), |
|||||
0 ignored issues
–
show
The function
esc_url was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
67 | 1 | esc_html( $this->message() ) |
|||||
0 ignored issues
–
show
The function
esc_html was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
68 | ); |
||||||
69 | } |
||||||
70 | } |
||||||
71 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.