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

Conversation   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
dl 0
loc 38
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 4
A getAgentParticipantsAttribute() 0 8 2
A getMessageRecordsAttribute() 0 8 2
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