Message::getTextAttribute()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 6
c 1
b 1
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
cc 4
nc 4
nop 0
crap 4
1
<?php
2
/**
3
 * Message
4
 *
5
 * @package LivePersonInc\LiveEngageLaravel\Models
6
 */
7
8
namespace LivePersonInc\LiveEngageLaravel\Models;
9
10
use Carbon\Carbon;
11
use Illuminate\Database\Eloquent\Model;
12
13
class Message extends Model
14
{
15
	protected $guarded = [];
16
17
	protected $appends = [
18
		'plain_text',
19
		'text',
20
		'time',
21
		'rich_content'
22
	];
23
	
24 2
	public function getTextAttribute()
25
	{
26 2
		if ($this->type == 'TEXT_PLAIN') {
0 ignored issues
show
Bug introduced by
The property type does not seem to exist on LivePersonInc\LiveEngageLaravel\Models\Message. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
27 1
			return $this->messageData->msg->text;
0 ignored issues
show
Bug introduced by
The property messageData does not seem to exist on LivePersonInc\LiveEngageLaravel\Models\Message. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
28 1
		} elseif ($this->type == 'RICH_CONTENT') {
29
			return 'RICH_CONTENT'; // @codeCoverageIgnore
30
		} else {
31 1
			return isset($this->attributes['text']) ? $this->attributes['text'] : '';
32
		}
33
	}
34
	
35
	public function getRichContentAttribute()
36
	{
37
		if ($this->type == 'RICH_CONTENT') {
0 ignored issues
show
Bug introduced by
The property type does not seem to exist on LivePersonInc\LiveEngageLaravel\Models\Message. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
38
			return json_decode($this->messageData->richContent->content);
0 ignored issues
show
Bug introduced by
The property messageData does not seem to exist on LivePersonInc\LiveEngageLaravel\Models\Message. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
39
		} else {
40
			return 'RICH_CONTENT';
41
		}
42
	}
43
44 1
	public function getPlainTextAttribute()
45
	{
46 1
		return strip_tags($this->text);
47
	}
48
49 2
	public function getTimeAttribute()
50
	{
51 2
		return new Carbon($this->attributes['time']);
52
	}
53
54 2
	public function __toString()
55
	{
56 2
		return $this->text;
57
	}
58
}
59