|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ConferenceTools\Tickets\Domain\Service\Availability; |
|
4
|
|
|
|
|
5
|
|
|
use Carnage\Cqrs\Persistence\ReadModel\RepositoryInterface; |
|
6
|
|
|
use ConferenceTools\Tickets\Domain\Service\Configuration; |
|
7
|
|
|
use ConferenceTools\Tickets\Domain\ValueObject\DiscountCode; |
|
8
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
9
|
|
|
use Doctrine\Common\Collections\Collection; |
|
10
|
|
|
use Doctrine\Common\Collections\Criteria; |
|
11
|
|
|
use ConferenceTools\Tickets\Domain\ReadModel\Counts\TicketCounter; |
|
|
|
|
|
|
12
|
|
|
use ConferenceTools\Tickets\Domain\ValueObject\TicketType; |
|
13
|
|
|
use ConferenceTools\Tickets\Domain\Service\Availability\Filters\FilterInterface; |
|
14
|
|
|
|
|
15
|
|
|
class DiscountCodeAvailability |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var FilterInterface[] |
|
19
|
|
|
*/ |
|
20
|
|
|
private $filters; |
|
21
|
|
|
/** |
|
22
|
|
|
* @var RepositoryInterface |
|
23
|
|
|
*/ |
|
24
|
|
|
private $repository; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* TicketAvailability constructor. |
|
28
|
|
|
* @param RepositoryInterface $repository |
|
29
|
|
|
* @param FilterInterface[] $filters |
|
30
|
|
|
*/ |
|
31
|
4 |
|
public function __construct(RepositoryInterface $repository, FilterInterface ...$filters) |
|
32
|
|
|
{ |
|
33
|
4 |
|
$this->filters = $filters; |
|
34
|
4 |
|
$this->repository = $repository; |
|
35
|
4 |
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @return TicketCounter[]|Collection |
|
39
|
|
|
*/ |
|
40
|
4 |
|
public function fetchAllAvailableDiscountCodes() |
|
41
|
|
|
{ |
|
42
|
4 |
|
$tickets = $this->repository->matching(new Criteria()); |
|
43
|
|
|
|
|
44
|
4 |
|
return $this->reindex($this->filterSet($tickets)); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
4 |
|
private function filterSet(Collection $tickets): Collection |
|
48
|
|
|
{ |
|
49
|
4 |
|
foreach ($this->filters as $filter) { |
|
50
|
|
|
/** @var FilterInterface $tickets */ |
|
51
|
4 |
|
$tickets = $filter->filter($tickets); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
4 |
|
return $tickets; |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
4 |
|
private function reindex(Collection $discountCodes): Collection |
|
58
|
|
|
{ |
|
59
|
4 |
|
$result = []; |
|
60
|
4 |
|
foreach($discountCodes as $discountCode) { |
|
61
|
|
|
/** @var DiscountCode $discountCode */ |
|
62
|
4 |
|
$result[$discountCode->getCode()] = $discountCode; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
4 |
|
return new ArrayCollection($result); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
3 |
|
public function isAvailable(DiscountCode $discountCode) |
|
69
|
|
|
{ |
|
70
|
3 |
|
$discountCodes = $this->fetchAllAvailableDiscountCodes(); |
|
71
|
3 |
|
return isset($discountCodes[$discountCode->getCode()]); |
|
72
|
|
|
} |
|
73
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths