Issues (38)

src/Collections/ConversationHistory.php (2 issues)

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
15
/**
16
 * ConversationHistory class.
17
 * 
18
 * @extends Collection
19
 */
20
class ConversationHistory extends Collection
21
{
22
	use Pageable;
0 ignored issues
show
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...
23
	
24
	/**
25
	 * metaData
26
	 * 
27
	 * @var \LivePersonInc\LiveEngageLaravel\Models\MetaData
28
	 * @access public
29
	 */
30
	public $metaData;
31
	
32
	/**
33
	 * historyFunction
34
	 * 
35
	 * Required for the Pageable trait (default value: 'retrieveMsgHistory')
36
	 * 
37
	 * @var string
38
	 * @access protected
39
	 */
40
	protected $historyFunction = 'retrieveMsgHistory';
41
42
	/**
43
	 * __construct function.
44
	 * 
45
	 * @access public
46
	 * @param array $models (default: [])
47
	 * @return void
48
	 */
49 1
	public function __construct($models = [])
50
	{
51
		$models = array_map(function($item) {
52 1
			return is_a($item, 'LivePersonInc\LiveEngageLaravel\Models\Conversation') ? $item : new Conversation((array) $item);
53 1
		}, $models ?: []);
54 1
		$this->metaData = new MetaData();
55 1
		parent::__construct($models);
56 1
	}
57
	
58
	/**
59
	 * find function.
60
	 * 
61
	 * @access public
62
	 * @param mixed $engagementID
63
	 * @return Conversation
64
	 */
65 1
	public function find($engagementID)
66
	{
67
		$result = $this->filter(function($value) use ($engagementID) {
68 1
			return $value->info->conversationId == $engagementID;
69 1
		});
70
		
71 1
		return $result->first();
72
	}
73
	
74
	/**
75
	 * merge function.
76
	 * 
77
	 * @access public
78
	 * @param mixed $collection
79
	 * @return ConversationHistory
80
	 */
81 1
	public function merge($collection) {
82
		
83 1
		$meta = $collection->metaData;
84 1
		$collection = parent::merge($collection);
85 1
		$this->metaData = $meta;
86 1
		$collection->metaData = $meta;
87
		
88 1
		return $collection;
89
		
90
	}
91
	
92
	public function toArray()
93
	{
94
		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...
95
			return $conversation->export;
96
		});
97
	}
98
}
99