pinterest-for-woocommerce icon indicating copy to clipboard operation
pinterest-for-woocommerce copied to clipboard

Add getter/setter for Crypto key, narrow down purpose of Crypto class.

Open ksere opened this issue 3 years ago • 0 comments

There's increased coupling between pinterest_data option, Crypto class, and main plugin class. I think it would be clearer and simpler if:

  • Main plugin class is responsible for all option saving/loading and naming/structure of options.
  • Options structure and key names are clearly documented (in a comment) in one place.
  • Crypto class has a single purpose - generating keys and encrypting/decrypting data.

(more context / details below)

It's a little messy having this class AND Crypto.php responsible for saving to crypto_encoded_key option.

I think it would be clearer if Pinterest_For_Woocommerce was solely responsible for saving/loading options. So something like:

  • Pinterest_For_Woocommerce exposes save_crypto_key() get_crypto_key().
  • These are called from Crypto, so it doesn't directly create/manage any options itself (all options are managed by main plugin class in one place).
  • Pinterest_For_Woocommerce ::clear_token() clears out everything using named methods rather than hard-coding option name.

There are a few alternative approaches that would be fine too IMO, the main feedback I have is that the option names/ownership should be contained within one class (ideally within one method).

Alternatives:

  • Pinterest_For_Woocommerce has a getter/setter method for key and token, since they are typically set and cleared at the same time. Pinterest_For_WooCommerce calls Crypto class as needed to encode/decode, and is the only client of it.
  • Crypto owns the token option, and exposes a method for Pinterest_For_Woocommerce to get access to token (or just to clear it).

Originally posted by @haszari in https://github.com/saucal/pinterest-for-woocommerce/pull/83#discussion_r667556050

ksere avatar Jul 13 '21 16:07 ksere