HEX
Server: nginx
System: Linux pool195-106-36.bur.atomicsites.net 6.12.57+deb12-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.57-1~bpo12+1 (2025-11-17) x86_64
User: (0)
PHP: 8.3.31
Disabled: pcntl_fork
Upload Files
File: /wordpress/plugins/wp-cloud-client/beta/src/Handler/SyncProfileHandler.php
<?php

declare(strict_types=1);

namespace VPlugins\WPCloudClient\Handler;

use VPlugins\WPCloudClient\Integration\DiviHelper;
use VPlugins\WPCloudClient\Integration\WooCommerceHelper;

final class SyncProfileHandler extends AbstractHandler {

	/**
	 * Return the action name.
	 *
	 * @return string Action name.
	 */
	public function action(): string {
		return 'sync_profile';
	}

	/**
	 * Sync a profile to active integrations.
	 *
	 * @param array<string, mixed> $params Action parameters.
	 * @return array<string, mixed> Sync results per integration.
	 *
	 * @throws \InvalidArgumentException If profile parameter is invalid.
	 */
	public function execute( array $params ): array {
		$this->requireParams( $params, 'profile' );

		$profile = $params['profile'];

		if ( ! is_array( $profile ) || empty( $profile ) ) {
			throw new \InvalidArgumentException( 'profile must be a non-empty object' );
		}

		$result = [];

		$wcResult = WooCommerceHelper::syncProfile( $profile );
		if ( null !== $wcResult ) {
			$result['woocommerce'] = $wcResult;
		}

		$diviResult = DiviHelper::syncProfile( $profile );
		if ( null !== $diviResult ) {
			$result['divi'] = $diviResult;
		}

		if ( empty( $result ) ) {
			$result['message'] = 'No active integrations found (WooCommerce or Divi required)';
		}

		return $result;
	}
}