| Conditions | 3 |
| Paths | 1 |
| Total Lines | 28 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 17 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php |
||
| 28 | 10 | public function filter(Collection $tickets): Collection |
|
| 29 | { |
||
| 30 | 10 | $configuration = $this->configuration; |
|
| 31 | |||
| 32 | 10 | $identifiers = $tickets->map(function(TicketCounter $ticketCounter) { |
|
| 33 | 10 | return $ticketCounter->getTicketType()->getIdentifier(); |
|
| 34 | 10 | }); |
|
| 35 | |||
| 36 | //Filter out tickets which have an availability period in the past. |
||
| 37 | 10 | $p = function(string $identifier) use ($configuration) { |
|
| 38 | 10 | $metadata = $configuration->getTicketMetadata($identifier); |
|
| 39 | |||
| 40 | 10 | return !($metadata->expiredOn(new \DateTime())); |
|
| 41 | 10 | }; |
|
| 42 | 10 | $identifiers = $identifiers->filter($p); |
|
| 43 | |||
| 44 | 10 | $p = function(TicketCounter $ticket) use ($configuration, $identifiers) { |
|
| 45 | 10 | $metadata = $configuration->getTicketMetadata($ticket->getTicketType()->getIdentifier()); |
|
| 46 | |||
| 47 | 10 | foreach ($metadata->getAfterSoldOut() as $identifier) { |
|
| 48 | 10 | if ($identifiers->contains($identifier)) { |
|
| 49 | 10 | return false; |
|
| 50 | } |
||
| 51 | } |
||
| 52 | |||
| 53 | 10 | return true; |
|
| 54 | 10 | }; |
|
| 55 | return $tickets->filter($p); |
||
| 56 | } |
||
| 57 | } |