exception(); } return $state; } public function email_address( mixed $email ): string { if ( '' === $email ) { return $email; } if ( ! is_string( $email ) || false === is_email( $email ) ) { throw SettingRefusal::NotAnEmail->exception(); } return $email; } /** @return list */ public function skipped_hosts( mixed $hosts ): array { if ( ! is_array( $hosts ) || ! array_is_list( $hosts ) ) { throw SettingRefusal::NotAHostList->exception(); } $normalized_hosts = array(); foreach ( $hosts as $typed_host ) { $normalized_hosts[] = $this->skipped_host( $typed_host ); } return array_values( array_unique( $normalized_hosts ) ); } public function clock_time( mixed $time ): string { if ( ! is_string( $time ) || 1 !== preg_match( self::CLOCK_TIME_PATTERN, $time ) ) { throw SettingRefusal::NotAClockTime->exception(); } return $time; } public function pause_milliseconds( mixed $pause ): int { return $this->whole_number_within( $pause, self::PAUSE_MINIMUM_MILLISECONDS, self::PAUSE_MAXIMUM_MILLISECONDS, SettingRefusal::PauseOutOfRange ); } public function batch_size( mixed $batch_size ): int { return $this->whole_number_within( $batch_size, self::BATCH_MINIMUM_SIZE, self::BATCH_MAXIMUM_SIZE, SettingRefusal::BatchSizeOutOfRange ); } private function whole_number_within( mixed $number, int $minimum, int $maximum, SettingRefusal $refusal ): int { $is_within_range = is_int( $number ) && $number >= $minimum && $number <= $maximum; if ( ! $is_within_range ) { throw $refusal->exception(); } return $number; } private function skipped_host( mixed $typed_host ): string { $host_parts = array(); $address = is_string( $typed_host ) ? strtolower( trim( $typed_host ) ) : ''; if ( 1 !== preg_match( self::HOST_PATTERN, $address, $host_parts ) ) { throw SettingRefusal::NotAHostList->exception(); } return $host_parts[ self::HOST_GROUP ]; } }