Passed
Branch master (c45254)
by Robert
03:51
created

Engagement   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 31
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTranscriptAttribute() 0 8 2
A __construct() 0 14 4
1
<?php
2
3
namespace LivePersonInc\LiveEngageLaravel\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use LivePersonInc\LiveEngageLaravel\Collections\Transcript;
7
8
class Engagement extends Model
9
{
10
	protected $guarded = [];
11
	protected $appends = [
12
		'transcript',
13
	];
14
	
15
	public function __construct(array $item)
16
	{
17
		if (isset($item['info'])) {
18
			$item['info'] = new Info((array) $item['info']);
19
		}
20
21
		if (isset($item['visitorInfo'])) {
22
			$item['visitorInfo'] = new Visitor((array) $item['visitorInfo']);
23
		}
24
25
		if (isset($item['campaign'])) {
26
			$item['campaign'] = new Campaign((array) $item['campaign']);
27
		}
28
		parent::__construct($item);
29
	}
30
31
	public function getTranscriptAttribute()
32
	{
33
		$messages = [];
34
		foreach ($this->attributes['transcript']->lines as $line) {
35
			$messages[] = new Message((array) $line);
36
		}
37
38
		return new Transcript($messages);
39
	}
40
}
41