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
|
|||
27 | 1 | return $this->messageData->msg->text; |
|
0 ignored issues
–
show
|
|||
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
|
|||
38 | return json_decode($this->messageData->richContent->content); |
||
0 ignored issues
–
show
|
|||
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 |
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.