PHPCS all the things

This commit is contained in:
Allen Snook 2018-09-26 16:35:01 -07:00
parent 677c205ad2
commit cb7a5b3607
3 changed files with 40 additions and 29 deletions

View File

@ -4,20 +4,25 @@
*
* The WooCommerce admin notes class gets admin notes data from storage and checks validity.
*
* @package WooCommerce Admin/Classes
*/
defined( 'ABSPATH' ) || exit;
/**
* WC_Admin_Note class.
*/
class WC_Admin_Note extends WC_Data {
// Note types
const E_WC_ADMIN_NOTE_ERROR = 'error';
const E_WC_ADMIN_NOTE_WARNING = 'warning';
const E_WC_ADMIN_NOTE_UPDATE = 'update'; // i.e. a new version is available
// Note types.
const E_WC_ADMIN_NOTE_ERROR = 'error';
const E_WC_ADMIN_NOTE_WARNING = 'warning';
const E_WC_ADMIN_NOTE_UPDATE = 'update'; // i.e. a new version is available.
const E_WC_ADMIN_NOTE_INFORMATIONAL = 'info';
// Note status codes
// Note status codes.
const E_WC_ADMIN_NOTE_UNACTIONED = 'unactioned';
const E_WC_ADMIN_NOTE_ACTIONED = 'actioned';
const E_WC_ADMIN_NOTE_ACTIONED = 'actioned';
/**
* This is the name of this object type.
@ -265,7 +270,7 @@ class WC_Admin_Note extends WC_Data {
* @param string $name Note name.
*/
public function set_name( $name ) {
// Don't allow empty names
// Don't allow empty names.
if ( empty( $name ) ) {
$this->error( 'admin_note_invalid_data', __( 'The admin note name prop cannot be empty.', 'woocommerce' ) );
}
@ -287,6 +292,7 @@ class WC_Admin_Note extends WC_Data {
$this->error(
'admin_note_invalid_data',
sprintf(
/* translators: %s: admin note type. */
__( 'The admin note type prop (%s) is not one of the supported types.', 'woocommerce' ),
$type
)
@ -329,8 +335,8 @@ class WC_Admin_Note extends WC_Data {
*/
public function set_content( $content ) {
$allowed_html = array(
'br' => array(),
'em' => array(),
'br' => array(),
'em' => array(),
'strong' => array(),
);
@ -359,12 +365,12 @@ class WC_Admin_Note extends WC_Data {
/**
* Set note data for potential re-localization.
*
* @param object $data Note data.
* @param object $content_data Note data.
*/
public function set_content_data( $content_data ) {
$allowed_type = false;
// Make sure $content_data is stdClass Object or an array
// Make sure $content_data is stdClass Object or an array.
if ( ! ( $content_data instanceof stdClass ) ) {
$this->error( 'admin_note_invalid_data', __( 'The admin note content_data prop must be an instance of stdClass.', 'woocommerce' ) );
}
@ -386,6 +392,7 @@ class WC_Admin_Note extends WC_Data {
$this->error(
'admin_note_invalid_data',
sprintf(
/* translators: %s: admin note status property. */
__( 'The admin note status prop (%s) is not one of the supported statuses.', 'woocommerce' ),
$status
)
@ -432,9 +439,13 @@ class WC_Admin_Note extends WC_Data {
/**
* Add an action to the note
*
* @param string $name Label name (not presented to user).
* @param string $label Note label (e.g. presented as button label).
* @param string $query Note query (for redirect).
*/
public function add_action( $name, $label, $query ) {
$name = wc_clean( $name );
$name = wc_clean( $name );
$label = wc_clean( $label );
$query = wc_clean( $query );
@ -456,7 +467,7 @@ class WC_Admin_Note extends WC_Data {
'query' => $query,
);
$note_actions = $this->get_prop( 'actions', 'edit' );
$note_actions = $this->get_prop( 'actions', 'edit' );
$note_actions[] = (object) $action;
$this->set_prop( 'actions', $note_actions );
}

View File

@ -2,6 +2,7 @@
/**
* Handles storage and retrieval of admin notes
*
* @package WooCommerce Admin/Classes
*/
if ( ! defined( 'ABSPATH' ) ) {

View File

@ -1,5 +1,4 @@
<?php
/**
* WC_Admin_Note_Data_Store class file.
*
@ -15,7 +14,7 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
/**
* Method to create a new note in the database.
*
* @param WC_Admin_Note
* @param WC_Admin_Note $note Admin note.
*/
public function create( &$note ) {
$date_created = current_time( 'timestamp', 1 );
@ -24,14 +23,14 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
global $wpdb;
$note_to_be_inserted = array(
'name' => $note->get_name(),
'type' => $note->get_type(),
'locale' => $note->get_locale(),
'title' => $note->get_title(),
'content' => $note->get_content(),
'icon' => $note->get_icon(),
'status' => $note->get_status(),
'source' => $note->get_source(),
'name' => $note->get_name(),
'type' => $note->get_type(),
'locale' => $note->get_locale(),
'title' => $note->get_title(),
'content' => $note->get_content(),
'icon' => $note->get_icon(),
'status' => $note->get_status(),
'source' => $note->get_source(),
);
$note_to_be_inserted['content_data'] = wp_json_encode( $note->get_content_data(), JSON_FORCE_OBJECT );
@ -51,7 +50,8 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
/**
* Method to read a note.
*
* @param WC_Admin_Note
* @param WC_Admin_Note $note Admin note.
* @throws Exception Throws exception when invalid data is found.
*/
public function read( &$note ) {
global $wpdb;
@ -98,7 +98,7 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
/**
* Updates a note in the database.
*
* @param WC_Admin_Note
* @param WC_Admin_Note $note Admin note.
*/
public function update( &$note ) {
global $wpdb;
@ -130,8 +130,8 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
/**
* Deletes a note from the database.
*
* @param WC_Admin_Note
* @param array $args Array of args to pass to the delete method (not used).
* @param WC_Admin_Note $note Admin note.
* @param array $args Array of args to pass to the delete method (not used).
*/
public function delete( &$note, $args = array() ) {
$note_id = $note->get_id();
@ -147,8 +147,7 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
/**
* Read actions from the database.
*
* @param WC_Admin_Note $note Note object.
*
* @param WC_Admin_Note $note Admin note.
*/
private function read_actions( &$note ) {
global $wpdb;