Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
23.53% |
4 / 17 |
|
22.22% |
2 / 9 |
CRAP | |
0.00% |
0 / 1 |
| Settings | |
23.53% |
4 / 17 |
|
22.22% |
2 / 9 |
76.39 | |
0.00% |
0 / 1 |
| get_confirmed_arns | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| set_confirmed_arn | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| get_secret_key | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_endpoint | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_log_level | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| get_plugin_name | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_plugin_slug | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_plugin_basename | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| get_plugin_version | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Class implementing the required settings for the plugin. |
| 4 | * |
| 5 | * @link https://BrianHenry.ie |
| 6 | * @since 1.0.0 |
| 7 | * |
| 8 | * @package brianhenryie/bh-wp-aws-ses-bounce-handler |
| 9 | */ |
| 10 | |
| 11 | namespace BrianHenryIE\AWS_SES_Bounce_Handler\API; |
| 12 | |
| 13 | use BrianHenryIE\AWS_SES_Bounce_Handler\Admin\Admin_Assets; |
| 14 | use BrianHenryIE\AWS_SES_Bounce_Handler\Admin\Plugins_Page; |
| 15 | use BrianHenryIE\AWS_SES_Bounce_Handler\BH_WP_AWS_SES_Bounce_Handler; |
| 16 | use BrianHenryIE\AWS_SES_Bounce_Handler\Settings_Interface; |
| 17 | use BrianHenryIE\AWS_SES_Bounce_Handler\WP_Logger\Logger; |
| 18 | use BrianHenryIE\AWS_SES_Bounce_Handler\WP_Logger\Logger_Settings_Interface; |
| 19 | use BrianHenryIE\AWS_SES_Bounce_Handler\WP_Logger\Logger_Settings_Trait; |
| 20 | use Psr\Log\LogLevel; |
| 21 | |
| 22 | |
| 23 | /** |
| 24 | * The plugin settings. |
| 25 | */ |
| 26 | class Settings implements Settings_Interface, Logger_Settings_Interface { |
| 27 | use Logger_Settings_Trait; |
| 28 | |
| 29 | /** |
| 30 | * List of ARNs which have successfully been confirmed with AWS SNS. |
| 31 | * |
| 32 | * @return string[] |
| 33 | */ |
| 34 | public function get_confirmed_arns(): array { |
| 35 | return get_option( self::CONFIRMED_ARNS, array() ); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Add an ARN string to the list of confirmed ARNs and save the option. |
| 40 | * |
| 41 | * @param string $arn AWS SNS ARN. |
| 42 | */ |
| 43 | public function set_confirmed_arn( string $arn ): void { |
| 44 | $confirmed_arns = $this->get_confirmed_arns(); |
| 45 | $confirmed_arns[] = $arn; |
| 46 | update_option( self::CONFIRMED_ARNS, array_unique( $confirmed_arns ) ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Return the secret key autogenerated on plugin activation, which must be present in all |
| 51 | * requests or the REST endpoint will disregard them. |
| 52 | * |
| 53 | * @return string |
| 54 | */ |
| 55 | public function get_secret_key(): string { |
| 56 | return get_option( self::SECRET_KEY ); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * The full endpoint URL: https://brianhenry.ie/wp-json/brianhenryie/v1/aws-ses/?secret=autogend. |
| 61 | * |
| 62 | * @return string |
| 63 | */ |
| 64 | public function get_endpoint(): string { |
| 65 | return get_rest_url( null, 'brianhenryie/v1/aws-ses/?secret=' . $this->get_secret_key() ); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Get the log level saved in wp_options, default to `info` level. |
| 70 | * |
| 71 | * @see LogLevel |
| 72 | */ |
| 73 | public function get_log_level(): string { |
| 74 | $default_log_level = LogLevel::INFO; |
| 75 | $allowed_log_levels = array( |
| 76 | 'none', |
| 77 | LogLevel::ERROR, |
| 78 | LogLevel::WARNING, |
| 79 | LogLevel::NOTICE, |
| 80 | LogLevel::INFO, |
| 81 | LogLevel::DEBUG, |
| 82 | ); |
| 83 | $saved_log_level = get_option( Settings_Interface::LOG_LEVEL_OPTION_NAME, $default_log_level ); |
| 84 | return in_array( $saved_log_level, $allowed_log_levels, true ) ? $saved_log_level : $default_log_level; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * For friendly display. |
| 89 | * |
| 90 | * @see Logger_Settings_Interface |
| 91 | */ |
| 92 | public function get_plugin_name(): string { |
| 93 | return 'AWS SES Bounce Handler'; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * For filenames and URLs. |
| 98 | * |
| 99 | * @see Logger_Settings_Interface |
| 100 | */ |
| 101 | public function get_plugin_slug(): string { |
| 102 | return 'bh-wp-aws-ses-bounce-handler'; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Used to match on plugins.php, and to get the plugin URL when serving assets and displaying the settings page. |
| 107 | * |
| 108 | * @used-by BH_WP_AWS_SES_Bounce_Handler::define_admin_plugins_page_hooks() |
| 109 | * @used-by Plugins_Page::row_meta() |
| 110 | * @used-by Admin_Assets::enqueue_styles() |
| 111 | * @used-by Admin_Assets::enqueue_scripts() |
| 112 | * |
| 113 | * @see Logger_Settings_Interface |
| 114 | */ |
| 115 | public function get_plugin_basename(): string { |
| 116 | return defined( 'BH_WP_AWS_SES_BOUNCE_HANDLER_BASENAME' ) |
| 117 | ? BH_WP_AWS_SES_BOUNCE_HANDLER_BASENAME |
| 118 | : 'bh-wp-aws-ses-bounce-handler/bh-wp-aws-ses-bounce-handler.php'; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * The plugin version, as defined in the root plugin file's constant, or as a string here, presumably in sync. |
| 123 | * |
| 124 | * Used for versioning JS and CSS assets. |
| 125 | * |
| 126 | * @used-by Admin_Assets::enqueue_styles() |
| 127 | * @used-by Admin_Assets::enqueue_scripts() |
| 128 | * |
| 129 | * @see Logger_Settings_Interface |
| 130 | */ |
| 131 | public function get_plugin_version(): string { |
| 132 | return defined( 'BH_WP_AWS_SES_BOUNCE_HANDLER_VERSION' ) |
| 133 | ? BH_WP_AWS_SES_BOUNCE_HANDLER_VERSION |
| 134 | : '1.7.0'; |
| 135 | } |
| 136 | } |