Passed
Push — master ( c79b4c...f5f1b3 )
by Robert
03:39
created

ConversationHistory::next()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3.0416

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 10
cts 12
cp 0.8333
rs 8.9713
c 0
b 0
f 0
cc 3
eloc 12
nc 3
nop 0
crap 3.0416
1
<?php
2
3
namespace LivePersonInc\LiveEngageLaravel\Collections;
4
5
use Illuminate\Support\Collection;
6
use LivePersonInc\LiveEngageLaravel\LiveEngageLaravel;
7
use LivePersonInc\LiveEngageLaravel\Facades\LiveEngageLaravel as LiveEngage;
8
use LivePersonInc\LiveEngageLaravel\Models\MetaData;
9
use LivePersonInc\LiveEngageLaravel\Models\Conversation;
10
use LivePersonInc\LiveEngageLaravel\Models\Info;
11
use LivePersonInc\LiveEngageLaravel\Models\Visitor;
12
use LivePersonInc\LiveEngageLaravel\Models\Campaign;
13
14
class ConversationHistory extends Collection
15
{
16
	public $metaData;
17
18 1
	public function __construct(array $models = [])
19
	{
20
		$models = array_map(function($item) {
21 1
			return is_a($item, 'LivePersonInc\LiveEngageLaravel\Models\Conversation') ? $item : new Conversation((array) $item);
22 1
		}, $models);
23 1
		$this->metaData = new MetaData();
24 1
		parent::__construct($models);
25 1
	}
26
	
27
	public function find($engagementID)
28
	{
29
		$result = $this->filter(function($value) use ($engagementID) {
30
			return $value->info->conversationId == $engagementID;
31
		});
32
		
33
		return $result->first();
34
	}
35
36 1
	public function next()
37
	{
38
		
39 1
		if ($this->metaData->next) {
0 ignored issues
show
Bug introduced by
The property next does not seem to exist on LivePersonInc\LiveEngageLaravel\Models\MetaData. 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...
40
			/** @scrutinizer ignore-call */
41 1
			$next = LiveEngage::retrieveMsgHistory($this->metaData->start, $this->metaData->end, $this->metaData->next->href);
0 ignored issues
show
Bug introduced by
The property end does not seem to exist on LivePersonInc\LiveEngageLaravel\Models\MetaData. 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...
Bug introduced by
The property start does not seem to exist on LivePersonInc\LiveEngageLaravel\Models\MetaData. 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...
42 1
			if ($next) {
43
		
44 1
				$next->_metadata->start = $this->metaData->start;
45 1
				$next->_metadata->end = $this->metaData->end;
46
		
47 1
				$meta = new MetaData((array) $next->_metadata);
48
				
49 1
				$collection = new self($next->conversationHistoryRecords);
50 1
				$collection->metaData = $meta;
51
				
52 1
				return $collection;
53
				
54
			} else {
55
				return false;
56
			}
57
		}
58
		
59
		return false;
60
		
61
	}
62
63 1
	public function prev()
64
	{
65 1
		if ($this->metaData->prev) {
0 ignored issues
show
Bug introduced by
The property prev does not seem to exist on LivePersonInc\LiveEngageLaravel\Models\MetaData. 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...
66
			/** @scrutinizer ignore-call */
67 1
			$prev = LiveEngage::retrieveMsgHistory($this->metaData->start, $this->metaData->end, $this->metaData->prev->href);
0 ignored issues
show
Bug introduced by
The property end does not seem to exist on LivePersonInc\LiveEngageLaravel\Models\MetaData. 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...
Bug introduced by
The property start does not seem to exist on LivePersonInc\LiveEngageLaravel\Models\MetaData. 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...
68 1
			if ($prev) {
69
		
70 1
				$prev->_metadata->start = $this->metaData->start;
71 1
				$prev->_metadata->end = $this->metaData->end;
72
		
73 1
				$meta = new MetaData((array) $prev->_metadata);
74
				
75 1
				$collection = new self($prev->conversationHistoryRecords);
76 1
				$collection->metaData = $meta;
77
				
78 1
				return $collection;
79
				
80
			} else {
81
				return false;
82
			}
83
		}
84
		
85
		return false;
86
		
87
	}
88
	
89
	public function merge($collection) {
90
		
91
		$meta = $collection->metaData;
92
		$collection = parent::merge($collection);
93
		$this->metaData = $meta;
94
		$collection->metaData = $meta;
95
		
96
		return $collection;
97
		
98
	}
99
}
100