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