| 1 |
<?php |
| 2 |
/** |
| 3 |
* WP-CLI affordances for the anonymous analytics identity. |
| 4 |
* |
| 5 |
* @package WCPOS\WooCommercePOS\CLI |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WCPOS\WooCommercePOS\CLI; |
| 9 |
|
| 10 |
use WCPOS\WooCommercePOS\Services\Anon_ID; |
| 11 |
|
| 12 |
/** |
| 13 |
* Manages the wcpos_anon_id analytics identifier. |
| 14 |
*/ |
| 15 |
class Anon_ID_Command { |
| 16 |
/** |
| 17 |
* Replaces the stored anonymous id with a fresh UUID. |
| 18 |
* |
| 19 |
* ## EXAMPLES |
| 20 |
* |
| 21 |
* wp wcpos anon-id rotate |
| 22 |
* |
| 23 |
* @param array $args Positional arguments (unused). |
| 24 |
* @param array $assoc_args Associative arguments (unused). |
| 25 |
*/ |
| 26 |
public function rotate( array $args, array $assoc_args ): void { |
| 27 |
$new = ( new Anon_ID() )->rotate(); |
| 28 |
$this->success( \sprintf( 'wcpos_anon_id rotated. New id: %s', $new ) ); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Deletes the stored anonymous id. A new one is generated on the next |
| 33 |
* landing-page load. |
| 34 |
* |
| 35 |
* ## EXAMPLES |
| 36 |
* |
| 37 |
* wp wcpos anon-id delete |
| 38 |
* |
| 39 |
* @param array $args Positional arguments (unused). |
| 40 |
* @param array $assoc_args Associative arguments (unused). |
| 41 |
*/ |
| 42 |
public function delete( array $args, array $assoc_args ): void { |
| 43 |
( new Anon_ID() )->delete(); |
| 44 |
$this->success( 'wcpos_anon_id deleted.' ); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Output seam — WP_CLI is absent in the unit-test container. |
| 49 |
* |
| 50 |
* @param string $message Success message. |
| 51 |
*/ |
| 52 |
protected function success( string $message ): void { |
| 53 |
// @phpstan-ignore-next-line -- WP_CLI exists only under the wp-cli runtime; unit tests override this seam. |
| 54 |
\WP_CLI::success( $message ); |
| 55 |
} |
| 56 |
} |
| 57 |
|