SDEs::getSDE()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * SDEs
4
 *
5
 * @package LivePersonInc\LiveEngageLaravel\Collections
6
 */
7
8
namespace LivePersonInc\LiveEngageLaravel\Collections;
9
10
use Illuminate\Support\Collection;
11
use LivePersonInc\LiveEngageLaravel\Models\SDE;
12
13
/**
14
 * SDEs class.
15
 * 
16
 * @extends Collection
17
 */
18
class SDEs extends Collection
19
{
20
	/**
21
	 * __construct function.
22
	 * 
23
	 * @access public
24
	 * @param array $models (default: [])
25
	 * @return void
26
	 */
27
	public function __construct(array $models = [])
28
	{
29
		
30
		
31
		$models = array_map(function($item) {
32
			return is_a($item, 'LivePersonInc\LiveEngageLaravel\Models\SDE') ? $item : new SDE((array) $item);
33
		}, $models);
34
		
35
		parent::__construct($models);
36
	}
37
	
38
	/**
39
	 * getSDE function.
40
	 * 
41
	 * @access public
42
	 * @param mixed $type
43
	 * @return mixed
44
	 */
45
	public function getSDE($type)
46
	{
47
		
48
		$sorted = $this->sortByDesc(function($item) {
49
			return $item->serverTimeStamp;
50
		});
51
		
52
		return $sorted->firstWhere('sdeType', $type);
53
		
54
	}
55
	
56
}