Completed
Pull Request — master (#16)
by Tim
20:28 queued 17:45
created

Campaign   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 38
ccs 16
cts 18
cp 0.8889
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

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