Completed
Pull Request — master (#18)
by Tonina
93:06 queued 90:11
created

Campaign::impressionThresholdReached()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\BannerServer\Entity\BannerSelection;
6
7
/**
8
 * @license GNU GPL v2+
9
 */
10
class Campaign {
11
12
	private $identifier;
13
	private $start;
14
	private $end;
15
16
	/**
17
	 * @var Bucket[]
18
	 */
19
	private $buckets;
20
21
	public function __construct( string $identifier, \DateTime $start, \DateTime $end, array $buckets ) {
22
		$this->identifier = $identifier;
23
		$this->start = $start;
24
		$this->end = $end;
25
		$this->buckets = $buckets;
26
	}
27
28
	public function getIdentifier(): string {
29
		return $this->identifier;
30
	}
31
32
	public function isInActiveDateRange( \DateTime $time ): bool {
33
		return $time->getTimestamp() > $this->start->getTimestamp() &&
34
			$time->getTimestamp() < $this->end->getTimestamp();
35
	}
36
37
	public function selectBucket( ?string $bucketId, callable $fallbackSelectionStrategy ): Bucket {
38
		foreach ( $this->buckets as $bucket ) {
39
			if ( $bucket->getIdentifier() === $bucketId ) {
40
				return $bucket;
41
			}
42
		}
43
		return $fallbackSelectionStrategy( $this->buckets );
44
	}
45
}