Completed
Pull Request — master (#15)
by Tim
17:33 queued 14:46
created

Bucket::getBanner()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 6
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 Bucket {
11
12
	private $identifier;
13
14
	/**
15
	 * @var Banner[]
16
	 */
17
	private $banners = [];
18
19
	public function __construct( string $identifier, Banner $mainBanner, Banner ...$otherBanners ) {
20
		$this->identifier = $identifier;
21
		$this->banners[] = $mainBanner;
22
		array_push( $this->banners, $otherBanners );
23
	}
24
25
	public function getIdentifier(): string {
26
		return $this->getIdentifier();
27
	}
28
29
	/**
30
	 * Returns banner for given impression count
31
	 * If impression count is over banner sequence, returns last banner in sequence
32
	 */
33
	public function getBanner( int $visitorImpressions ): string {
34
		if ( isset( $this->banners[$visitorImpressions] ) ) {
35
			return $this->banners[$visitorImpressions]->getIdentifier();
36
		}
37
		return $this->banners[count( $this->banners ) - 1]->getIdentifier();
38
	}
39
}