Debian Codegraph @

includes/libs/WRStats/LimitCondition.php

raw symbols SCIP
1 <?php
2
3 namespace Wikimedia\WRStats;
4
5 /**
6 * @since 1.39
7 * @newable
8 */
9 class LimitCondition {
10 /** @var int The maximum number of events */
11 public $limit;
12 /** @var float|int The number of seconds over which the number of events may occur */
13 public $window;
14
15 /**
16 * @param int|float|string $limit The maximum number of events
17 * @param int|float|string $window The number of seconds over which the
18 * number of events may occur
19 */
20 public function __construct( $limit, $window ) {
21 $this->limit = (int)$limit;
22 $this->window = +$window;
23 if ( $this->window <= 0 ) {
24 throw new WRStatsError( 'Condition window must be positive' );
25 }
26 }
27
28 /**
29 * Get the condition as a number of events per second
30 *
31 * @return float|int
32 */
33 public function perSecond() {
34 return $this->limit / $this->window;
35 }
36 }