20declare( strict_types=1 );
24use InvalidArgumentException;
45 if ( $newSampleRate < 0.0 || $newSampleRate > 1.0 ) {
46 throw new InvalidArgumentException(
"Sample rate can only be between 0.0 and 1.0. Got: " . $newSampleRate );
58 if ( $sampleRate === 1.0 ) {
62 $randMax = mt_getrandmax();
63 foreach ( $samples as $sample ) {
64 if ( mt_rand() / $randMax < $sampleRate ) {
81 throw new InvalidArgumentException(
"Stats: Metric name cannot be empty." );
83 if ( !preg_match( self::RE_VALID_NAME_AND_LABEL_NAME, $name ) ) {
98 throw new InvalidArgumentException(
"Stats: Label key cannot be empty." );
100 if ( !preg_match( self::RE_VALID_NAME_AND_LABEL_NAME, $key ) ) {
106 if ( $value ===
"" ) {
107 throw new InvalidArgumentException(
"Stats: Label value cannot be empty." );
118 $normalizedEntities = [];
119 foreach ( $entities as $entity ) {
120 $normalizedEntities[] = self::normalizeString( $entity );
122 return $normalizedEntities;
139 $entity = preg_replace(
'/[^a-zA-Z0-9]+/',
'_', $entity );
140 return trim( $entity,
'_' );
147 private const E12 = [
148 1.0, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2, 10.0
192 throw new InvalidArgumentException(
'mean must be positive' );
195 throw new InvalidArgumentException(
'skip must be at least 1' );
198 $pos = (int)round( log10( $mean ) * 12 );
201 $pos -= ( $pos % $skip );
205 return array_map(
static function ( $x ) use ( $pos, $skip ) {
206 $y = $pos + ( $x * $skip );
211 $decade = intdiv( $y - $rem, 12 );
214 return round( ( 10 ** $decade ) * self::E12[$rem], 1 - $decade );
217 -4, -3, -2, -1, 0, 1, 2, 3, 4
if(!defined('MW_SETUP_CALLBACK'))