AtMentionMessage   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 11.11 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 7
loc 63
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A toHtml() 0 5 1
A toArray() 0 4 1
A url() 0 2 1
A message() 6 6 2
A __construct() 0 2 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
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 %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
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( '%1$s mentioned you', /** @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 1
	public function url() {
43 1
		return bp_loggedin_user_domain() . bp_get_activity_slug() . '/mentions/';
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

43
		return bp_loggedin_user_domain() . /** @scrutinizer ignore-call */ bp_get_activity_slug() . '/mentions/';
Loading history...
Bug introduced by
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 ignore-call  annotation

43
		return /** @scrutinizer ignore-call */ bp_loggedin_user_domain() . bp_get_activity_slug() . '/mentions/';
Loading history...
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
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

66
			/** @scrutinizer ignore-call */ esc_url( $this->url() ),
Loading history...
67 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

67
			/** @scrutinizer ignore-call */ esc_html( $this->message() )
Loading history...
68
		);
69
	}
70
}
71