Passed
Push — master ( c0a3a7...3b84a4 )
by Jeroen
58:51
created

SiteNotification   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Test Coverage

Coverage 60.87%

Importance

Changes 0
Metric Value
dl 0
loc 75
ccs 14
cts 23
cp 0.6087
rs 10
c 0
b 0
f 0
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getURL() 0 2 1
A isRead() 0 2 1
A setURL() 0 3 2
A setActor() 0 2 1
A initializeAttributes() 0 3 1
A getActor() 0 7 2
A setRead() 0 2 1
1
<?php
2
/**
3
 * Site notification class
4
 */
5
6
class SiteNotification extends ElggObject {
7
8
	const HAS_ACTOR = "hasActor";
9
10
	/**
11
	 * {@inheritDoc}
12
	 */
13 2
	protected function initializeAttributes() {
14 2
		parent::initializeAttributes();
15 2
		$this->attributes['subtype'] = 'site_notification';
16 2
	}
17
18
	/**
19
	 * Get the actor involved in the notification
20
	 *
21
	 * @return ElggEntity|null
22
	 */
23
	public function getActor() {
24
		$actor = $this->getEntitiesFromRelationship(['relationship' => self::HAS_ACTOR]);
25
		if ($actor) {
26
			$actor = $actor[0];
27
		}
28
29
		return $actor;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $actor returns the type false which is incompatible with the documented return type null|ElggEntity.
Loading history...
30
	}
31
32
	/**
33
	 * Set the actor involved in the notification
34
	 *
35
	 * @param ElggEntity $entity Actor
36
	 *
37
	 * @return void
38
	 */
39 2
	public function setActor($entity) {
40 2
		$this->addRelationship($entity->guid, self::HAS_ACTOR);
41 2
	}
42
43
	/**
44
	 * {@inheritDoc}
45
	 */
46
	public function getURL() {
47
		return (string) $this->url;
48
	}
49
50
	/**
51
	 * Set the url for the notification
52
	 *
53
	 * @param string $url The URL for the notification link
54
	 *
55
	 * @return void
56
	 */
57 2
	public function setURL($url) {
58 2
		if ($url) {
59 2
			$this->url = $url;
0 ignored issues
show
Bug Best Practice introduced by
The property url does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
60
		}
61 2
	}
62
63
	/**
64
	 * Set the read status
65
	 *
66
	 * @param bool $read Has the notification been read
67
	 *
68
	 * @return void
69
	 */
70 2
	public function setRead($read) {
71 2
		$this->read = $read;
0 ignored issues
show
Bug Best Practice introduced by
The property read does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
72 2
	}
73
74
	/**
75
	 * Has the notification been read?
76
	 *
77
	 * @return bool
78
	 */
79
	public function isRead() {
80
		return (bool) $this->read;
81
	}
82
}
83