Completed
Pull Request — master (#19)
by Tim
86:17 queued 20:58
created

Campaign   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 44
ccs 16
cts 18
cp 0.8889
rs 10
c 0
b 0
f 0
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getCampaignExpiration() 0 2 1
A isInActiveDateRange() 0 3 2
A selectBucket() 0 7 3
A getIdentifier() 0 2 1
A impressionThresholdReached() 0 2 1
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
	private $impressionThreshold;
16
17
	/**
18
	 * @var Bucket[]
19
	 */
20
	private $buckets;
21 7
22 7
	public function __construct( string $identifier, \DateTime $start, \DateTime $end, array $buckets, ImpressionThresholdInterface $impressionThreshold ) {
23 7
		$this->identifier = $identifier;
24 7
		$this->start = $start;
25 7
		$this->end = $end;
26 7
		$this->buckets = $buckets;
27
		$this->impressionThreshold = $impressionThreshold;
28 1
	}
29 1
30
	public function getIdentifier(): string {
31
		return $this->identifier;
32
	}
33
34
	public function getCampaignExpiration(): \DateTime {
35
		return $this->end;
36 4
	}
37 4
38 4
	public function isInActiveDateRange( \DateTime $time ): bool {
39
		return $time->getTimestamp() >= $this->start->getTimestamp() &&
40
			$time->getTimestamp() <= $this->end->getTimestamp();
41 3
	}
42 3
43 3
	public function selectBucket( ?string $bucketId, callable $fallbackSelectionStrategy ): Bucket {
44 3
		foreach ( $this->buckets as $bucket ) {
45
			if ( $bucket->getIdentifier() === $bucketId ) {
46
				return $bucket;
47 2
			}
48
		}
49
		return $fallbackSelectionStrategy( $this->buckets );
50
	}
51
52
	public function impressionThresholdReached( int $visitorImpressions ): bool {
53
		return $this->impressionThreshold->getIsOverThreshold( $visitorImpressions );
54
	}
55
}