1 | <?php |
||||
2 | |||||
3 | namespace Mamaduka\BpNotifications\Messages; |
||||
4 | |||||
5 | class UpdateReplyMessage 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 %d new replies', (int) $this->data['total'] ); |
|||
32 | } |
||||
33 | |||||
34 | 1 | return sprintf( '%s commented on one of your updates', 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 | 2 | public function url() { |
|||
43 | 2 | if ( $this->data['total'] > 1 ) { |
|||
44 | 1 | return add_query_arg( |
|||
0 ignored issues
–
show
The function
add_query_arg 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
![]() |
|||||
45 | 1 | 'type', |
|||
46 | 1 | $this->data['action'], |
|||
47 | 1 | bp_get_notifications_permalink( $this->data['user_id'] ) ); |
|||
0 ignored issues
–
show
The function
bp_get_notifications_permalink 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
![]() |
|||||
48 | } |
||||
49 | |||||
50 | 1 | return add_query_arg( |
|||
51 | 1 | 'nid', |
|||
52 | 1 | $this->data['id'], |
|||
53 | 1 | bp_activity_get_permalink( $this->data['activity_id'] ) |
|||
0 ignored issues
–
show
The function
bp_activity_get_permalink 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
![]() |
|||||
54 | ); |
||||
55 | } |
||||
56 | |||||
57 | /** |
||||
58 | * Get the array representation of the message. |
||||
59 | * |
||||
60 | * @return array |
||||
61 | */ |
||||
62 | 1 | public function toArray() { |
|||
63 | return [ |
||||
64 | 1 | 'text' => $this->message(), |
|||
65 | 1 | 'link' => $this->url(), |
|||
66 | ]; |
||||
67 | } |
||||
68 | |||||
69 | /** |
||||
70 | * Get the HTML representation of the message. |
||||
71 | * |
||||
72 | * @return string |
||||
73 | */ |
||||
74 | 1 | public function toHtml() { |
|||
75 | 1 | return sprintf( |
|||
76 | 1 | '<a href="%1$s">%2$s</a>', |
|||
77 | 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
![]() |
|||||
78 | 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
![]() |
|||||
79 | ); |
||||
80 | } |
||||
81 | } |
||||
82 |
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.