Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
25.00% covered (danger)
25.00%
5 / 20
33.33% covered (danger)
33.33%
1 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
UseraccountList
25.00% covered (danger)
25.00%
5 / 20
33.33% covered (danger)
33.33%
1 / 3
52.19
0.00% covered (danger)
0.00%
0 / 1
 withRights
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 withoutDublicates
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 withAccessByWorkstation
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3namespace BO\Zmsentities\Collection;
4
5class UseraccountList extends Base
6{
7    const ENTITY_CLASS = '\BO\Zmsentities\UserAccount';
8
9    public function withRights($requiredRights)
10    {
11        $collection = new static();
12        foreach ($this as $useraccount) {
13            if ($useraccount->hasRights($requiredRights)) {
14                $collection[] = clone $useraccount;
15            }
16        }
17        return $collection;
18    }
19
20    public function withoutDublicates()
21    {
22        $collection = new self();
23        foreach ($this as $useraccount) {
24            if (! $collection->hasEntity($useraccount->getId())) {
25                $collection->addEntity(clone $useraccount);
26            }
27        }
28        return $collection;
29    }
30
31    public function withAccessByWorkstation($workstation)
32    {
33        $collection = new self();
34        $departmentList = $workstation->getDepartmentList();
35        foreach ($this as $useraccount) {
36            $accessedList = $departmentList->withAccess($useraccount);
37
38            if ($useraccount->hasRights(['department'])) {
39                $accessedList = $departmentList;
40            } else {
41                $accessedList = $departmentList->withAccess($useraccount);
42            }
43
44            if ($accessedList->count()) {
45                $collection->addEntity(clone $useraccount);
46            }
47        }
48        return $collection;
49    }
50}