Test Failed
Branch development (1f4e65)
by Robert
11:57
created

ConversationHistory::closeReason()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 9
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * ConversationHistory
4
 *
5
 * @package LivePersonInc\LiveEngageLaravel\Collections
6
 */
7
8
namespace LivePersonInc\LiveEngageLaravel\Collections;
9
10
use Illuminate\Support\Collection;
11
use LivePersonInc\LiveEngageLaravel\Models\MetaData;
12
use LivePersonInc\LiveEngageLaravel\Models\Conversation;
13
use LivePersonInc\LiveEngageLaravel\Traits\Pageable;
14
use LivePersonInc\LiveEngageLaravel\Traits\Timeable;
15
16
/**
17
 * ConversationHistory class.
18
 * 
19
 * @extends Collection
20
 */
21
class ConversationHistory extends Collection
22
{
23
	use Pageable, Timeable;
0 ignored issues
show
introduced by
The trait LivePersonInc\LiveEngageLaravel\Traits\Timeable requires some properties which are not provided by LivePersonInc\LiveEngage...ons\ConversationHistory: $info, $minutes, $seconds
Loading history...
introduced by
The trait LivePersonInc\LiveEngageLaravel\Traits\Pageable requires some properties which are not provided by LivePersonInc\LiveEngage...ons\ConversationHistory: $_metadata, $prev, $next, $records, $href
Loading history...
24
	
25
	/**
26
	 * metaData
27
	 * 
28
	 * @var \LivePersonInc\LiveEngageLaravel\Models\MetaData
29
	 * @access public
30
	 */
31
	public $metaData;
32
	
33
	/**
34
	 * historyFunction
35
	 * 
36
	 * Required for the Pageable trait (default value: 'retrieveMsgHistory')
37
	 * 
38
	 * @var string
39
	 * @access protected
40
	 */
41
	protected $historyFunction = 'retrieveMsgHistory';
42
43
	/**
44
	 * __construct function.
45
	 * 
46
	 * @access public
47
	 * @param array $models (default: [])
48
	 * @return void
49 1
	 */
50
	public function __construct($models = [])
51
	{
52 1
		$models = array_map(function($item) {
53 1
			return is_a($item, 'LivePersonInc\LiveEngageLaravel\Models\Conversation') ? $item : new Conversation((array) $item);
54 1
		}, $models ?: []);
55 1
		$this->metaData = new MetaData();
56 1
		parent::__construct($models);
57
	}
58
	
59
	/**
60
	 * closeReason function.
61
	 * 
62
	 * @access public
63
	 * @param mixed $reason
64
	 * @return void
65
	 */
66
	public function closeReason()
67
	{
68
		$reasons = func_get_args();
69
		
70
		$result = $this->filter(function($value) use ($reasons) {
71
			return in_array($value->info->closeReason, $reasons);
72
		});
73
		
74
		return $result;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result returns the type LivePersonInc\LiveEngage...ons\ConversationHistory which is incompatible with the documented return type void.
Loading history...
75
	}
76
	
77
	/**
78
	 * find function.
79
	 * 
80
	 * @access public
81
	 * @param mixed $engagementID
82
	 * @return Conversation
83
	 */
84
	public function find($engagementID)
85
	{
86
		$result = $this->filter(function($value) use ($engagementID) {
87
			return $value->info->conversationId == $engagementID;
88
		});
89
		
90
		return $result->first();
91
	}
92
	
93
	/**
94
	 * merge function.
95
	 * 
96
	 * @access public
97
	 * @param mixed $collection
98
	 * @return ConversationHistory
99
	 */
100
	public function merge($collection) {
101
		
102
		$meta = $collection->metaData;
103
		$collection = parent::merge($collection);
104
		$this->metaData = $meta;
105
		$collection->metaData = $meta;
106
		
107
		return $collection;
108
		
109
	}
110
	
111
	public function toArray()
112
	{
113
		return $this->map(function($conversation) {
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->map(function(...) { /* ... */ }) returns the type LivePersonInc\LiveEngage...ons\ConversationHistory which is incompatible with the return type mandated by Illuminate\Contracts\Support\Arrayable::toArray() of array.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
114
			return $conversation->export;
115
		});
116
	}
117
}
118