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;
135 $entity = preg_replace(
'/[^a-z\d]+/i',
'_', $entity );
136 return trim( $entity,
"_" );
if(!defined('MW_SETUP_CALLBACK'))