Completed
Push — master ( ce8b1d...cf9d14 )
by Tim
1086:28 queued 1023:05
created

TrafficImpressionThreshold::getIsOverThreshold()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 1
dl 0
loc 2
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 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
}