Bucket   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getLastBanner() 0 2 1
A getBanner() 0 5 2
A getIdentifier() 0 2 1
A __construct() 0 3 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\BannerServer\Entity\BannerSelection;
6
7
/**
8
 * @license GPL-2.0-or-later
9
 */
10
class Bucket {
11
12
	private string $identifier;
13
14
	/**
15
	 * @var Banner[]
16
	 */
17
	private array $banners = [];
18
19 5
	public function __construct( string $identifier, Banner $firstBanner, Banner ...$additionalBanners ) {
20 5
		$this->identifier = $identifier;
21 5
		$this->banners = array_merge( [ $firstBanner ], $additionalBanners );
22
	}
23
24 1
	public function getIdentifier(): string {
25 1
		return $this->identifier;
26
	}
27
28 1
	private function getLastBanner(): Banner {
29 1
		return $this->banners[count( $this->banners ) - 1];
30
	}
31
32
	/**
33
	 * Decides which banner to return based on visitor's impression count
34
	 *
35
	 * @param int $visitorImpressionCount
36
	 *
37
	 * @return string
38
	 */
39 4
	public function getBanner( int $visitorImpressionCount ): string {
40 4
		if ( $visitorImpressionCount >= count( $this->banners ) ) {
41 1
			return $this->getLastBanner()->getIdentifier();
42
		}
43 3
		return $this->banners[$visitorImpressionCount]->getIdentifier();
44
	}
45
}
46