ElggBlog::canComment()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 12
loc 12
ccs 0
cts 10
cp 0
crap 12
rs 9.8666
c 0
b 0
f 0
1
<?php
2
/**
3
 * Extended class to override the time_created
4
 * 
5
 * @property string $status      The published status of the blog post (published, draft)
6
 * @property string $comments_on Whether commenting is allowed (Off, On)
7
 * @property string $excerpt     An excerpt of the blog post used when displaying the post
8
 */
9
class ElggBlog extends ElggObject {
10
11
	/**
12
	 * Set subtype to blog.
13
	 */
14
	protected function initializeAttributes() {
15
		parent::initializeAttributes();
16
17
		$this->attributes['subtype'] = "blog";
18
	}
19
20
	/**
21
	 * Can a user comment on this blog?
22
	 *
23
	 * @see ElggObject::canComment()
24
	 *
25
	 * @param int $user_guid User guid (default is logged in user)
26
	 * @return bool
27
	 * @since 1.8.0
28
	 */
29 View Code Duplication
	public function canComment($user_guid = 0) {
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
		$result = parent::canComment($user_guid);
31
		if ($result == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
32
			return $result;
33
		}
34
35
		if ($this->comments_on == 'Off') {
36
			return false;
37
		}
38
		
39
		return true;
40
	}
41
42
	/**
43
	 * Get the excerpt for this blog post
44
	 * 
45
	 * @param int $length Length of the excerpt (optional)
46
	 * @return string
47
	 * @since 1.9.0
48
	 */
49
	public function getExcerpt($length = 250) {
50
		if ($this->excerpt) {
51
			return $this->excerpt;
52
		} else {
53
			return elgg_get_excerpt($this->description, $length);
54
		}
55
	}
56
}