Test Failed
Branch development (5e44f6)
by Robert
06:31
created

Conversation::extractEmail()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 4
c 2
b 0
f 0
dl 0
loc 6
ccs 0
cts 0
cp 0
rs 10
cc 2
nc 2
nop 0
crap 6
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
33 2
34 2
		$init = [
35 2
			'info'					=> [],
36 2
			'visitorInfo'			=> [],
37 2
			'campaign'				=> [],
38 2
			'transfers'				=> [],
39 2
			'agentParticipants'		=> [],
40
			'consumerParticipants'	=> [],
41 2
			'messageRecords'		=> [],
42 2
			'monitoring'			=> [],
43
			'sdes'					=> new SDE(),
44
			'unAuthSdes'			=> new SDE(),
45
		];
46
47
		$item = array_merge($init, $item);
48
49
		$item['info'] = new MessagingInfo((array) $item['info']);
50
		$item['monitoring'] = new MessagingInfo((array) $item['monitoring']);
51
		$item['visitorInfo'] = new Visitor((array) $item['visitorInfo']);
52
		$item['campaign'] = new Campaign((array) $item['campaign']);
53
		$item['transfers'] = new Transfers($item['transfers']);
54
		$item['agentParticipants'] = new AgentParticipants($item['agentParticipants']);
55
		$item['consumerParticipants'] = new ConsumerParticipants($item['consumerParticipants']);
56
		$item['messageRecords'] = new Transcript($item['messageRecords'], $item['agentParticipants']);
57
		$item['sdes'] = new SDEs($item['sdes']->events ?: []);
58
		$item['unAuthSdes'] = new SDEs($item['unAuthSdes']->events ?: []);
59
60
		parent::__construct($item);
61
	}
62
63
	/*public function getInfoAttribute()
64
	{
65
		return new MessagingInfo((array) $this->attributes['info']);
66
	}*/
67
68
	/**
69
	 * @codeCoverageIgnore
70
	 */
71
	public function getTextTranscriptAttribute()
72
	{
73
		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...
74
	}
75
76
	/**
77
	 * @codeCoverageIgnore
78
	 */
79
	public function getExportAttribute()
80
	{
81
		$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...
82
		$info['transcript'] = $this->textTranscript;
83
		return ((object)$info);
84
	}
85
86
	public function extractEmail()
87
	{
88
		$matches = [];
89
		$pattern = '/[.A-Za-z0-9_-]+@[A-Za-z0-9_-]+\.([A-Za-z0-9_-][.A-Za-z0-9_]+)/'; //regex for pattern of e-mail address
90
        preg_match_all($pattern, $this->textTranscript, $matches);
91
        return count($matches) ? $matches[0] : null;
92
	}
93
}
94