Completed
Pull Request — master (#12)
by Tim
981:02 queued 919:01
created

TrafficImpressionThreshold   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A isImpressionLimitReached() 0 2 1
A getIsOverThreshold() 0 2 2
A isTrafficLimited() 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 TrafficImpressionThreshold implements ImpressionThresholdInterface {
11
12
	private $trafficLimit;
13
	private $seasonalLimit;
14
15
	public function __construct( float $trafficLimit, int $seasonalLimit ) {
16
		$this->trafficLimit = $trafficLimit;
17
		$this->seasonalLimit = $seasonalLimit;
18
	}
19
20
	public function getIsOverThreshold( int $visitorTotalImpressions ): bool {
21
		return $this->isTrafficLimited() || $this->isImpressionLimitReached( $visitorTotalImpressions );
22
	}
23
24
	private function isTrafficLimited(): bool {
25
		return ( random_int( 0, 100 ) / 100 ) <= $this->trafficLimit;
26
	}
27
28
	private function isImpressionLimitReached( int $impressions ): bool {
29
		return $impressions >= $this->seasonalLimit;
30
	}
31
}