provider_key = $this->sanitize_key_like_value( $provider_key ); $this->status = $this->sanitize_status( $status ); $this->plan = $plan; } /** * Create inactive status. * * @param string $provider_key Provider key. */ public static function inactive( string $provider_key ): self { return new self( $provider_key, self::STATUS_INACTIVE, LicensePlan::free() ); } /** * Create active status for future tests and providers. * * @param string $provider_key Provider key. * @param LicensePlan $plan Plan. */ public static function active( string $provider_key, LicensePlan $plan ): self { return new self( $provider_key, self::STATUS_ACTIVE, $plan ); } /** * Whether status is active. */ public function is_active(): bool { return self::STATUS_ACTIVE === $this->status && $this->plan->is_pro(); } /** * Get provider key. */ public function get_provider_key(): string { return $this->provider_key; } /** * Get status value. */ public function get_status(): string { return $this->status; } /** * Get plan. */ public function get_plan(): LicensePlan { return $this->plan; } /** * Sanitize a key-like value. * * @param string $value Value. */ private function sanitize_key_like_value( string $value ): string { return strtolower( preg_replace( '/[^a-zA-Z0-9_-]/', '', $value ) ?? '' ); } /** * Sanitize status. * * @param string $status Status. */ private function sanitize_status( string $status ): string { $status = strtolower( trim( $status ) ); return in_array( $status, array( self::STATUS_ACTIVE, self::STATUS_INACTIVE, self::STATUS_UNKNOWN ), true ) ? $status : self::STATUS_UNKNOWN; } }