Test Failed
Branch master (19e1ba)
by Robert
02:23
created

ConversationHistory::find()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace LivePersonInc\LiveEngageLaravel\Collections;
4
5
use Illuminate\Support\Collection;
6
use LivePersonInc\LiveEngageLaravel\LiveEngageLaravel;
7
use LivePersonInc\LiveEngageLaravel\Models\Conversation;
8
9
class ConversationHistory extends Collection
10
{
11
    private $instance;
12
13
    public function __construct(array $models = [], LiveEngageLaravel $instance = null)
14
    {
15
        $this->instance = $instance;
16
17
        parent::__construct($models);
18
    }
19
    
20
    public function find($engagementID)
21
    {
22
	    $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

22
	    $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...
23
		    return $value->info->conversationId == $engagementID;
24
	    });
25
	    
26
	    return $result->first();
27
    }
28
29
    public function next()
30
    {
31
        if (! $this->instance) {
32
            return false;
33
        }
34
35
        $instance = $this->instance;
36
37
        $next = $instance->retrieveMsgHistory($instance->start, $instance->end, $instance->next);
0 ignored issues
show
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 $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 $next is declared private in LivePersonInc\LiveEngageLaravel\LiveEngageLaravel. Since you implement __get, consider adding a @property or @property-read.
Loading history...
38
        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...
39
            $instance->next = $next->_metadata->next->href;
40
41
            $history = [];
42
            foreach ($next->conversationHistoryRecords as $item) {
0 ignored issues
show
Bug introduced by
The property conversationHistoryRecords does not seem to exist on GuzzleHttp\Exception\ConnectException.
Loading history...
43
                $history[] = new Conversation((array) $item);
44
            }
45
46
            return $this->merge(new self($history));
47
        } else {
48
            return false;
49
        }
50
    }
51
52
    public function prev()
53
    {
54
        if (! $this->instance) {
55
            return false;
56
        }
57
58
        $instance = $this->instance;
59
60
        $prev = $instance->retrieveMsgHistory($instance->start, $instance->end, $instance->prev);
0 ignored issues
show
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 $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...
61
        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...
62
            $instance->prev = $prev->_metadata->prev->href;
63
64
            $history = [];
65
            foreach ($next->conversationHistoryRecords as $item) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $next seems to be never defined.
Loading history...
66
                $history[] = new Conversation((array) $item);
67
            }
68
69
            return $this->merge(new self($history));
70
        } else {
71
            return false;
72
        }
73
    }
74
}
75