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

Engagement::__construct()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 8
cp 0
rs 9.2
c 0
b 0
f 0
cc 4
eloc 7
nc 8
nop 1
crap 20
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