Passed
Push — master ( b19e1a...9e97df )
by Robert
03:55
created

AgentParticipants::state()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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