Passed
Pull Request — master (#16)
by Tonina
63:18
created

Bucket   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 31
rs 10
c 0
b 0
f 0
ccs 0
cts 11
cp 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getIdentifier() 0 2 1
A __construct() 0 4 1
A getLastBanner() 0 2 1
A getBanner() 0 5 2
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, array $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->identifier;
27
	}
28
29
	private function getLastBanner(): Banner {
30
		return $this->banners[count( $this->banners ) - 1];
31
	}
32
33
	/**
34
	 * Decides which banner to return based on visitor's impression count
35
	 */
36
	public function getBanner( int $visitorImpressionCount ): string {
37
		if ( $visitorImpressionCount >= count( $this->banners ) ) {
38
			return $this->getLastBanner()->getIdentifier();
39
		}
40
		return $this->banners[$visitorImpressionCount]->getIdentifier();
41
	}
42
}