size = $size; $this->threshold = $threshold; } /** * Records one resolved client address. Requests with no address are not counted. * * @param Address|null $address Address. */ public function record( $address ) { if ( null === $address ) { return; } $value = $address->internal ? 1 : 0; if ( count( $this->window ) === $this->size ) { $this->internal -= $this->window[ $this->next ]; } $this->window[ $this->next ] = $value; $this->internal += $value; $this->next = ( $this->next + 1 ) % $this->size; } /** * True when the window is full and mostly internal. * * @return bool */ public function suspect() { return count( $this->window ) === $this->size && $this->internal >= $this->size * $this->threshold; } }