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

TrafficImpressionThreshold::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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