Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
33 / 33 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
DayoffList | |
100.00% |
33 / 33 |
|
100.00% |
7 / 7 |
19 | |
100.00% |
1 / 1 |
hasEntityByDate | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
getByDate | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
getEntityByName | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
withTimestampFromDateformat | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
2 | |||
testDatesInYear | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
withNew | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
isNewerThan | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | namespace BO\Zmsentities\Collection; |
4 | |
5 | class DayoffList extends Base |
6 | { |
7 | const ENTITY_CLASS = '\BO\Zmsentities\Dayoff'; |
8 | |
9 | public function hasEntityByDate($date) |
10 | { |
11 | return $this->getByDate($date) ? true : false; |
12 | } |
13 | |
14 | public function getByDate($date) |
15 | { |
16 | $date = (new \BO\Zmsentities\Helper\DateTime($date))->format('Y-m-d'); |
17 | foreach ($this as $entity) { |
18 | if ($entity->getDateTime()->format('Y-m-d') == $date) { |
19 | return $entity; |
20 | } |
21 | } |
22 | return false; |
23 | } |
24 | |
25 | public function getEntityByName($name) |
26 | { |
27 | $result = null; |
28 | foreach ($this as $entity) { |
29 | if ($entity->name == $name) { |
30 | $result = $entity; |
31 | } |
32 | } |
33 | return $result; |
34 | } |
35 | |
36 | public function withTimestampFromDateformat($fromFormat = 'd.m.Y') |
37 | { |
38 | $collection = new self(); |
39 | foreach ($this as $data) { |
40 | $entity = new \BO\Zmsentities\Dayoff($data); // if source is an array |
41 | $entity = clone $entity; |
42 | $entity->setTimestampFromDateformat($fromFormat); |
43 | $collection->addEntity($entity); |
44 | } |
45 | return $collection; |
46 | } |
47 | |
48 | public function testDatesInYear($year) |
49 | { |
50 | foreach ($this as $data) { |
51 | $entity = new \BO\Zmsentities\Dayoff($data); // if source is an array |
52 | $entityYear = (new \DateTimeImmutable())->setTimestamp($entity->date)->format('Y'); |
53 | if ($entityYear != $year) { |
54 | throw new \BO\Zmsentities\Exception\DayoffWrongYear(); |
55 | } |
56 | } |
57 | return true; |
58 | } |
59 | |
60 | public function withNew(DayoffList $dayoffList) |
61 | { |
62 | $list = new self(); |
63 | foreach ($dayoffList as $entity) { |
64 | if (! $this->hasEntityByDate($entity->getDateTime())) { |
65 | $list->addEntity($entity); |
66 | } |
67 | } |
68 | return $list; |
69 | } |
70 | |
71 | /** |
72 | * Check if dayoff is newer than given time |
73 | * |
74 | * @return bool |
75 | */ |
76 | public function isNewerThan(\DateTimeInterface $dateTime, $filterByAvailability = null, $now = null) |
77 | { |
78 | foreach ($this as $dayoff) { |
79 | if ($dayoff->isNewerThan($dateTime, $filterByAvailability, $now)) { |
80 | return true; |
81 | } |
82 | } |
83 | return false; |
84 | } |
85 | } |