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

ConversationHistory::find()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 2
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
	private $instance;
17
	public $metaData;
18
19
	public function __construct(array $models = [], LiveEngageLaravel $instance = null)
20
	{
21
		$this->instance = $instance;
22
		$this->metaData = new MetaData();
23
		parent::__construct($models);
24
	}
25
	
26
	public function find($engagementID)
27
	{
28
		$result = $this->filter(function($value, $key) use ($engagementID) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

28
		$result = $this->filter(function($value, /** @scrutinizer ignore-unused */ $key) use ($engagementID) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
29
			return $value->info->conversationId == $engagementID;
30
		});
31
		
32
		return $result->first();
33
	}
34
35
	public function next()
36
	{
37
		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...
38
			$next = LiveEngage::retrieveMsgHistory($this->metaData->start, $this->metaData->end, $this->metaData->next->href);
0 ignored issues
show
Bug introduced by
The method retrieveMsgHistory() does not exist on LivePersonInc\LiveEngage...cades\LiveEngageLaravel. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
			/** @scrutinizer ignore-call */ 
39
   $next = LiveEngage::retrieveMsgHistory($this->metaData->start, $this->metaData->end, $this->metaData->next->href);
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...
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...
39
			if ($next) {
40
		
41
				$meta = new MetaData((array) $next->_metadata);
42
				
43
				$results = array_map(function($item) {
44
					return new Conversation((array) $item);
45
				}, $next->conversationHistoryRecords);
46
				
47
				$collection = new self($results);
48
				$meta->start = $this->metaData->start;
49
				$meta->end = $this->metaData->end;
50
				$collection->metaData = $meta;
51
				
52
				return $collection;
53
				
54
			} else {
55
				return false;
56
			}
57
		}
58
	}
59
60
	public function prev()
61
	{
62
		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...
63
			$prev = LiveEngage::retrieveMsgHistory($this->metaData->start, $this->metaData->end, $this->metaData->prev->href);
0 ignored issues
show
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...
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...
64
			if ($prev) {
65
		
66
				$meta = new MetaData((array) $prev->_metadata);
67
				
68
				$results = array_map(function($item) {
69
					return new Conversation((array) $item);
70
				}, $prev->conversationHistoryRecords);
71
				
72
				$collection = new self($results);
73
				$meta->start = $this->metaData->start;
74
				$meta->end = $this->metaData->end;
75
				$collection->metaData = $meta;
76
				
77
				return $collection;
78
				
79
			} else {
80
				return false;
81
			}
82
		}
83
	}
84
	
85
	public function merge($collection) {
86
		
87
		$collection = parent::merge($collection);
88
		$this->metaData = $collection->metaData;
89
		
90
		return $collection;
91
		
92
	}
93
}
94