Passed
Push — master ( a2c862...16044f )
by Robert
05:35
created

Conversation::__construct()   B

Complexity

Conditions 9
Paths 8

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 9

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 12
c 0
b 0
f 0
ccs 10
cts 10
cp 1
rs 8.0555
cc 9
nc 8
nop 1
crap 9
1
<?php
2
/**
3
 * Conversation
4
 *
5
 * @package LivePersonInc\LiveEngageLaravel\Models
6
 */
7
8
namespace LivePersonInc\LiveEngageLaravel\Models;
9
10
use Illuminate\Database\Eloquent\Model;
11
use LivePersonInc\LiveEngageLaravel\Collections\AgentParticipants;
12
use LivePersonInc\LiveEngageLaravel\Collections\ConsumerParticipants;
13
use LivePersonInc\LiveEngageLaravel\Collections\Transfers;
14
use LivePersonInc\LiveEngageLaravel\Collections\Transcript;
15
use LivePersonInc\LiveEngageLaravel\Collections\SDEs;
16
17
/**
18
 * Conversation class.
19
 * 
20
 * @extends Model
21
 */
22
class Conversation extends Model
23
{
24
	protected $guarded = [];
25
	
26
	protected $appends = [
27
		'textTranscript',
28
	];
29
	
30 2
	public function __construct(array $item)
31
	{
32 2
		$item['info'] = isset($item['info']) ? new MessagingInfo((array) $item['info']) : new MessagingInfo();
33 2
		$item['visitorInfo'] = isset($item['visitorInfo']) ? new Visitor((array) $item['visitorInfo']) : new Visitor();
34 2
		$item['campaign'] = isset($item['campaign']) ? new Campaign((array) $item['campaign']) : new Campaign();
35 2
		$item['transfers'] = new Transfers(isset($item['transfers']) ? $item['transfers'] : []);
36 2
		$item['agentParticipants'] = new AgentParticipants(isset($item['agentParticipants']) ? $item['agentParticipants'] : []);
37 2
		$item['consumerParticipants'] = new ConsumerParticipants(isset($item['consumerParticipants']) ? $item['consumerParticipants'] : []);
38 2
		$item['messageRecords'] = new Transcript(isset($item['messageRecords']) ? $item['messageRecords'] : [], $item['agentParticipants']);
39 2
		$item['sdes'] = new SDEs(isset($item['sdes']->events) ? $item['sdes']->events : []);
40
		
41 2
		parent::__construct($item);
42 2
	}
43
	
44
	/**
45
	 * @codeCoverageIgnore
46
	 */	
47
	public function getTextTranscriptAttribute()
48
	{
49
		return $this->messageRecords->textTranscript();
0 ignored issues
show
Bug introduced by
The property messageRecords does not seem to exist on LivePersonInc\LiveEngage...vel\Models\Conversation. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
50
	}
51
	
52
	/**
53
	 * @codeCoverageIgnore
54
	 */
55
	public function getExportAttribute()
56
	{
57
		$info = $this->info->attributes;
0 ignored issues
show
Bug introduced by
The property info does not seem to exist on LivePersonInc\LiveEngage...vel\Models\Conversation. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
58
		$info['transcript'] = $this->textTranscript;
59
		return ((object)$info);
60
	}
61
}
62