Test Failed
Branch master (901d12)
by Robert
06:03
created

EngagementHistory::prev()   C

Complexity

Conditions 7
Paths 11

Size

Total Lines 33
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 18
nc 11
nop 0
1
<?php
2
3
namespace LivePersonInc\LiveEngageLaravel\Collections;
4
5
use Illuminate\Support\Collection;
6
use LivePersonInc\LiveEngageLaravel\LiveEngageLaravel;
7
use LivePersonInc\LiveEngageLaravel\Models\Engagement;
8
use LivePersonInc\LiveEngageLaravel\Models\Info;
9
use LivePersonInc\LiveEngageLaravel\Models\Visitor;
10
use LivePersonInc\LiveEngageLaravel\Models\Campaign;
11
12
class EngagementHistory extends Collection
13
{
14
    private $instance;
15
16
    public function __construct(array $models = [], LiveEngageLaravel $instance = null)
17
    {
18
        $this->instance = $instance;
19
20
        return parent::__construct($models);
0 ignored issues
show
Bug introduced by
Are you sure the usage of parent::__construct($models) targeting Illuminate\Support\Collection::__construct() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
21
    }
22
    
23
    public function find($engagementID)
24
    {
25
	    $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

25
	    $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...
26
		    return $value->info->sessionId == $engagementID;
27
	    });
28
	    
29
	    return $result->first();
30
    }
31
32
    public function next()
33
    {
34
        if (! $this->instance) {
35
            return false;
36
        }
37
38
        $instance = $this->instance;
39
40
        $next = $instance->retrieveHistory($instance->start, $instance->end, $instance->next);
0 ignored issues
show
Bug Best Practice introduced by
The property $end is declared private in LivePersonInc\LiveEngageLaravel\LiveEngageLaravel. Since you implement __get, consider adding a @property or @property-read.
Loading history...
Bug Best Practice introduced by
The property $start is declared private in LivePersonInc\LiveEngageLaravel\LiveEngageLaravel. Since you implement __get, consider adding a @property or @property-read.
Loading history...
Bug Best Practice introduced by
The property $next is declared private in LivePersonInc\LiveEngageLaravel\LiveEngageLaravel. Since you implement __get, consider adding a @property or @property-read.
Loading history...
41
        if (property_exists($next->_metadata, 'next')) {
0 ignored issues
show
Bug introduced by
The property _metadata does not seem to exist on GuzzleHttp\Exception\ConnectException.
Loading history...
42
            $instance->next = $next->_metadata->next->href;
43
44
            $history = [];
45
            foreach ($next->interactionHistoryRecords as $item) {
0 ignored issues
show
Bug introduced by
The property interactionHistoryRecords does not seem to exist on GuzzleHttp\Exception\ConnectException.
Loading history...
46
	            
47
                if (property_exists($item, 'info')) {
48
	                $item->info = new Info((array) $item->info);
49
	            }
50
	
51
	            if (property_exists($item, 'visitorInfo')) {
52
	                $item->visitorInfo = new Visitor((array) $item->visitorInfo);
53
	            }
54
	
55
	            if (property_exists($item, 'campaign')) {
56
	                $item->campaign = new Campaign((array) $item->campaign);
57
	            }
58
	
59
	            $history[] = new Engagement((array) $item);
60
            }
61
62
            return $this->merge(new EngagementHistory($history));
63
        } else {
64
            return false;
65
        }
66
    }
67
68
    public function prev()
69
    {
70
        if (! $this->instance) {
71
            return false;
72
        }
73
74
        $instance = $this->instance;
75
76
        $prev = $instance->retrieveHistory($instance->start, $instance->end, $instance->prev);
0 ignored issues
show
Bug Best Practice introduced by
The property $end is declared private in LivePersonInc\LiveEngageLaravel\LiveEngageLaravel. Since you implement __get, consider adding a @property or @property-read.
Loading history...
Bug Best Practice introduced by
The property $prev is declared private in LivePersonInc\LiveEngageLaravel\LiveEngageLaravel. Since you implement __get, consider adding a @property or @property-read.
Loading history...
Bug Best Practice introduced by
The property $start is declared private in LivePersonInc\LiveEngageLaravel\LiveEngageLaravel. Since you implement __get, consider adding a @property or @property-read.
Loading history...
77
        if (property_exists($prev->_metadata, 'prev')) {
0 ignored issues
show
Bug introduced by
The property _metadata does not seem to exist on GuzzleHttp\Exception\ConnectException.
Loading history...
78
            $instance->prev = $prev->_metadata->prev->href;
79
80
            $history = [];
81
            foreach ($next->interactionHistoryRecords as $item) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $next seems to be never defined.
Loading history...
82
	            
83
                if (property_exists($item, 'info')) {
84
	                $item->info = new Info((array) $item->info);
85
	            }
86
	
87
	            if (property_exists($item, 'visitorInfo')) {
88
	                $item->visitorInfo = new Visitor((array) $item->visitorInfo);
89
	            }
90
	
91
	            if (property_exists($item, 'campaign')) {
92
	                $item->campaign = new Campaign((array) $item->campaign);
93
	            }
94
	
95
	            $history[] = new Engagement((array) $item);
96
            }
97
98
            return $this->merge(new self($history));
99
        } else {
100
            return false;
101
        }
102
    }
103
}
104