| Total Complexity | 9 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Coverage | 88.89% |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | class Campaign { |
||
| 13 | |||
| 14 | private $identifier; |
||
| 15 | private $start; |
||
| 16 | private $end; |
||
| 17 | private $rng; |
||
| 18 | private $displayRatio; |
||
| 19 | |||
| 20 | /** |
||
| 21 | 7 | * @var Bucket[] |
|
| 22 | 7 | */ |
|
| 23 | 7 | private $buckets; |
|
| 24 | 7 | ||
| 25 | 7 | public function __construct( |
|
| 41 | 3 | } |
|
| 42 | 3 | ||
| 43 | 3 | public function getIdentifier(): string { |
|
| 44 | 3 | return $this->identifier; |
|
| 45 | } |
||
| 46 | |||
| 47 | 2 | public function getEnd(): \DateTime { |
|
| 48 | return $this->end; |
||
| 49 | } |
||
| 50 | |||
| 51 | public function isInActiveDateRange( \DateTime $time ): bool { |
||
| 52 | return $time->getTimestamp() >= $this->start->getTimestamp() && |
||
| 53 | $time->getTimestamp() <= $this->end->getTimestamp(); |
||
| 54 | } |
||
| 55 | |||
| 56 | public function selectBucket( ?string $bucketId ): Bucket { |
||
| 57 | foreach ( $this->buckets as $bucket ) { |
||
| 58 | if ( $bucket->getIdentifier() === $bucketId ) { |
||
| 59 | return $bucket; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | return $this->buckets[$this->rng->getRandomInteger( 0, count( $this->buckets ) - 1 )]; |
||
| 63 | } |
||
| 64 | |||
| 65 | public function isRatioLimited(): bool { |
||
| 67 | } |
||
| 68 | } |