Passed
Push — master ( f5f1b3...00795d )
by Robert
03:27
created

EngagementHistory   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Test Coverage

Coverage 65%

Importance

Changes 0
Metric Value
wmc 10
dl 0
loc 84
ccs 26
cts 40
cp 0.65
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A find() 0 7 1
A __construct() 0 7 2
B next() 0 24 3
A merge() 0 8 1
B prev() 0 24 3
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\Engagement;
9
use LivePersonInc\LiveEngageLaravel\Models\MetaData;
10
use LivePersonInc\LiveEngageLaravel\Models\Info;
11
use LivePersonInc\LiveEngageLaravel\Models\Visitor;
12
use LivePersonInc\LiveEngageLaravel\Models\Campaign;
13
14
class EngagementHistory extends Collection
15
{
16
	public $metaData;
17
18 2
	public function __construct(array $models = [])
19
	{
20
		$models = array_map(function($item) {
21 2
			return is_a($item, 'LivePersonInc\LiveEngageLaravel\Models\Engagement') ? $item : new Engagement((array) $item);
22 2
		}, $models);
23 2
		$this->metaData = new MetaData();
24 2
		parent::__construct($models);
25 2
	}
26
	
27
	public function find($engagementID)
28
	{
29
		$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

29
		$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...
30
			return $value->info->sessionId == $engagementID;
31
		});
32
		
33
		return $result->first();
34
	}
35
36 1
	public function next()
37
	{
38
		/** @scrutinizer ignore-call */
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::retrieveHistory($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->interactionHistoryRecords);
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
		/** @scrutinizer ignore-call */
66 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...
67
			/** @scrutinizer ignore-call */
68 1
			$prev = LiveEngage::retrieveHistory($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...
69 1
			if ($prev) {
70
		
71 1
				$prev->_metadata->start = $this->metaData->start;
72 1
				$prev->_metadata->end = $this->metaData->end;
73
		
74 1
				$meta = new MetaData((array) $prev->_metadata);
75
				
76 1
				$collection = new self($prev->interactionHistoryRecords);
77 1
				$collection->metaData = $meta;
78
				
79 1
				return $collection;
80
				
81
			} else {
82
				return false;
83
			}
84
		}
85
		
86
		return false;
87
		
88
	}
89
	
90
	public function merge($collection) {
91
		
92
		$meta = $collection->metaData;
93
		$collection = parent::merge($collection);
94
		$this->metaData = $meta;
95
		$collection->metaData = $meta;
96
		
97
		return $collection;
98
		
99
	}
100
}
101