UpdateReplyMessage::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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
Bug introduced by
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 ignore-call  annotation

34
		return sprintf( '%s commented on one of your updates', /** @scrutinizer ignore-call */ bp_core_get_user_displayname( $this->data['user_id' ] ) );
Loading history...
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
Bug introduced by
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 ignore-call  annotation

44
			return /** @scrutinizer ignore-call */ add_query_arg(
Loading history...
45 1
				'type',
46 1
				$this->data['action'],
47 1
				bp_get_notifications_permalink( $this->data['user_id'] ) );
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

47
				/** @scrutinizer ignore-call */ bp_get_notifications_permalink( $this->data['user_id'] ) );
Loading history...
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
Bug introduced by
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 ignore-call  annotation

53
			/** @scrutinizer ignore-call */ bp_activity_get_permalink( $this->data['activity_id'] )
Loading history...
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
Bug introduced by
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 ignore-call  annotation

77
			/** @scrutinizer ignore-call */ esc_url( $this->url() ),
Loading history...
78 1
			esc_html( $this->message() )
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

78
			/** @scrutinizer ignore-call */ esc_html( $this->message() )
Loading history...
79
		);
80
	}
81
}
82