Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
50.00% |
9 / 18 |
|
14.29% |
1 / 7 |
CRAP | |
0.00% |
0 / 1 |
EditingStreak | |
50.00% |
9 / 18 |
|
14.29% |
1 / 7 |
19.12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
jsonSerialize | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
2 | |||
getStreakNumberOfDays | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getDatePeriod | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setDatePeriod | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTotalEditCountForPeriod | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setTotalEditCountForPeriod | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\UserImpact; |
4 | |
5 | use DatePeriod; |
6 | use JsonSerializable; |
7 | |
8 | /** |
9 | * Value object representing an editing streak. It has a start date, an end date, and a count of the total number |
10 | * of edits for this date range. |
11 | */ |
12 | class EditingStreak implements JsonSerializable { |
13 | |
14 | /** @var DatePeriod|null */ |
15 | private ?DatePeriod $datePeriod; |
16 | /** @var int */ |
17 | private int $totalEditCountForPeriod; |
18 | |
19 | /** |
20 | * @param DatePeriod|null $datePeriod |
21 | * @param int $totalEditCountForPeriod |
22 | */ |
23 | public function __construct( |
24 | ?DatePeriod $datePeriod = null, |
25 | int $totalEditCountForPeriod = 0 |
26 | ) { |
27 | $this->datePeriod = $datePeriod; |
28 | $this->totalEditCountForPeriod = $totalEditCountForPeriod; |
29 | } |
30 | |
31 | /** @inheritDoc */ |
32 | public function jsonSerialize(): array { |
33 | return $this->datePeriod ? |
34 | [ |
35 | 'datePeriod' => [ |
36 | 'start' => $this->datePeriod->getStartDate()->format( 'Y-m-d' ), |
37 | 'end' => $this->datePeriod->getEndDate()->format( 'Y-m-d' ), |
38 | 'days' => $this->getStreakNumberOfDays() |
39 | ], |
40 | 'totalEditCountForPeriod' => $this->totalEditCountForPeriod |
41 | ] : []; |
42 | } |
43 | |
44 | /** |
45 | * @return int |
46 | */ |
47 | public function getStreakNumberOfDays(): int { |
48 | return $this->datePeriod ? |
49 | $this->datePeriod->getEndDate()->diff( $this->datePeriod->getStartDate() )->days + 1 : |
50 | 0; |
51 | } |
52 | |
53 | /** |
54 | * @return DatePeriod|null |
55 | */ |
56 | public function getDatePeriod(): ?DatePeriod { |
57 | return $this->datePeriod; |
58 | } |
59 | |
60 | /** |
61 | * @param DatePeriod $datePeriod |
62 | */ |
63 | public function setDatePeriod( DatePeriod $datePeriod ): void { |
64 | $this->datePeriod = $datePeriod; |
65 | } |
66 | |
67 | /** |
68 | * @return int |
69 | */ |
70 | public function getTotalEditCountForPeriod(): int { |
71 | return $this->totalEditCountForPeriod; |
72 | } |
73 | |
74 | /** |
75 | * @param int $totalEditCountForPeriod |
76 | */ |
77 | public function setTotalEditCountForPeriod( int $totalEditCountForPeriod ): void { |
78 | $this->totalEditCountForPeriod = $totalEditCountForPeriod; |
79 | } |
80 | } |