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

SiteNotification::getURL()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
ccs 0
cts 2
cp 0
crap 2
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