Completed
Pull Request — master (#36)
by Gabriel
64:04
created

Visitor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getBucketIdentifier() 0 2 1
A __construct() 0 4 1
A getTotalImpressionCount() 0 2 1
A getCategories() 0 2 1
A inCategory() 0 2 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\BannerServer\Entity;
6
7
/**
8
 * @license GNU GPL v2+
9
 */
10
class Visitor {
11
12
	private $totalImpressionCount = 0;
13
	private $bucketIdentifier;
14
	private $activeCategories;
15
16
	/**
17
	 * @param int $totalImpressionCount How many banners the visitor has seen overall
18
	 * @param string|null $bucketIdentifier Last bucket identifier of the visitor (to put recurring visitors in the same buckets, but only per-campaign)
19
	 * @param string ...$activeCategories Categories the user has interacted with (close button, donation, etc)
20
	 */
21
	public function __construct( int $totalImpressionCount, ?string $bucketIdentifier, string ...$activeCategories ) {
22
		$this->totalImpressionCount = $totalImpressionCount;
23
		$this->bucketIdentifier = $bucketIdentifier;
24
		$this->activeCategories = $activeCategories;
25
	}
26
27
	public function getTotalImpressionCount(): int {
28
		return $this->totalImpressionCount;
29
	}
30
31
	public function getBucketIdentifier(): ?string {
32
		return $this->bucketIdentifier;
33
	}
34
35
	public function inCategory( string $categoryName ): bool {
36
		return in_array( $categoryName, $this->activeCategories, true );
37
	}
38
39
	/**
40
	 * @return string[]
41
	 */
42
	public function getCategories(): array {
43
		return $this->activeCategories;
44
	}
45
}