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

Conversation::__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\AgentParticipants;
7
8
class Conversation extends Model
9
{
10
	protected $guarded = [];
11
	
12
	public function __construct(array $item)
13
	{
14
		if (isset($item['info'])) {
15
			$item['info'] = new MessagingInfo((array) $item['info']);
16
		}
17
18
		if (isset($item['visitorInfo'])) {
19
			$item['visitorInfo'] = new Visitor((array) $item['visitorInfo']);
20
		}
21
22
		if (isset($item['campaign'])) {
23
			$item['campaign'] = new Campaign((array) $item['campaign']);
24
		}
25
		parent::__construct($item);
26
	}
27
28
	public function getMessageRecordsAttribute()
29
	{
30
		$messages = [];
31
		foreach ($this->attributes['messageRecords'] as $line) {
32
			$messages[] = new Message((array) $line);
33
		}
34
35
		return collect($messages);
36
	}
37
38
	public function getAgentParticipantsAttribute()
39
	{
40
		$agents = [];
41
		foreach ($this->attributes['agentParticipants'] as $agent) {
42
			$agents[] = new MessagingAgent((array) $agent);
43
		}
44
45
		return new AgentParticipants($agents);
46
	}
47
}
48