Passed
Push — master ( 7757e2...b19e1a )
by Robert
04:39
created

AgentParticipants::findById()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace LivePersonInc\LiveEngageLaravel\Collections;
4
5
use Illuminate\Support\Collection;
6
use LivePersonInc\LiveEngageLaravel\Models\Agent;
7
use LivePersonInc\LiveEngageLaravel\Models\MetaData;
8
9
class AgentParticipants extends Collection
10
{
11
	public $metaData;
12
	
13 1
	public function __construct(array $models = [])
14
	{
15
		
16
		$models = array_map(function($item) {
17 1
			return is_a($item, 'LivePersonInc\LiveEngageLaravel\Models\Agent') ? $item : new Agent((array) $item);
18 1
		}, $models);
19 1
		$this->metaData = new MetaData();
20 1
		parent::__construct($models);
21 1
	}
22
	
23
	public function state($state = 'ONLINE')
24
	{
25
		$result = $this->filter(function($value) use ($state) {
26
			return strtolower($value->currentStatus) == strtolower($state);
27
		});
28
		
29
		return $result;
30
	}
31
	
32
	public function findById($agentId)
33
	{
34
		$result = $this->filter(function($value) use ($agentId) {
35
			return strtolower($value->agentId) == $agentId;
36
		});
37
		
38
		return $result->first();
39
	}
40
}
41