7declare( strict_types=1 );
11use InvalidArgumentException;
32 if ( $newSampleRate < 0.0 || $newSampleRate > 1.0 ) {
33 throw new InvalidArgumentException(
"Sample rate can only be between 0.0 and 1.0. Got: " . $newSampleRate );
45 if ( $sampleRate === 1.0 ) {
49 $randMax = mt_getrandmax();
50 foreach ( $samples as $sample ) {
51 if ( mt_rand() / $randMax < $sampleRate ) {
68 throw new InvalidArgumentException(
"Stats: Metric name cannot be empty." );
70 if ( !preg_match( self::RE_VALID_NAME_AND_LABEL_NAME, $name ) ) {
85 throw new InvalidArgumentException(
"Stats: Label key cannot be empty." );
87 if ( !preg_match( self::RE_VALID_NAME_AND_LABEL_NAME, $key ) ) {
93 if ( $value ===
"" ) {
94 throw new InvalidArgumentException(
"Stats: Label value cannot be empty." );
105 $normalizedEntities = [];
106 foreach ( $entities as $entity ) {
107 $normalizedEntities[] = self::normalizeString( $entity );
109 return $normalizedEntities;
126 $entity = preg_replace(
'/[^a-zA-Z0-9]+/',
'_', $entity );
127 return trim( $entity,
'_' );
134 private const E12 = [
135 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
179 throw new InvalidArgumentException(
'mean must be positive' );
182 throw new InvalidArgumentException(
'skip must be at least 1' );
185 $pos = (int)round( log10( $mean ) * 12 );
188 $pos -= ( $pos % $skip );
192 return array_map(
static function (
int $x ) use ( $pos, $skip ) {
193 $y = $pos + ( $x * $skip );
198 $decade = intdiv( $y - $rem, 12 );
201 return round( ( 10 ** $decade ) * self::E12[$rem], 1 - $decade );
204 -4, -3, -2, -1, 0, 1, 2, 3, 4
if(!defined('MW_SETUP_CALLBACK'))