Fixed includes/class-wc-product-download.php PHPCS violations

This commit is contained in:
Claudio Sanches 2018-03-22 15:10:22 -03:00
parent 809ca5e0fc
commit 475e0c734f
1 changed files with 51 additions and 30 deletions

View File

@ -1,20 +1,22 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** /**
* Represents a file which can be downloaded. * Represents a file which can be downloaded.
* *
* @package WooCommerce/Classes
* @version 3.0.0 * @version 3.0.0
* @since 3.0.0 * @since 3.0.0
* @package WooCommerce/Classes */
* @author WooThemes
defined( 'ABSPATH' ) || exit;
/**
* Product download class.
*/ */
class WC_Product_Download implements ArrayAccess { class WC_Product_Download implements ArrayAccess {
/** /**
* Data array. * Data array.
*
* @since 3.0.0 * @since 3.0.0
* @var array * @var array
*/ */
@ -26,6 +28,7 @@ class WC_Product_Download implements ArrayAccess {
/** /**
* Returns all data for this object. * Returns all data for this object.
*
* @return array * @return array
*/ */
public function get_data() { public function get_data() {
@ -34,6 +37,7 @@ class WC_Product_Download implements ArrayAccess {
/** /**
* Get allowed mime types. * Get allowed mime types.
*
* @return array * @return array
*/ */
public function get_allowed_mime_types() { public function get_allowed_mime_types() {
@ -42,6 +46,7 @@ class WC_Product_Download implements ArrayAccess {
/** /**
* Get type of file path set. * Get type of file path set.
*
* @param string $file_path optional. * @param string $file_path optional.
* @return string absolute, relative, or shortcode. * @return string absolute, relative, or shortcode.
*/ */
@ -58,6 +63,7 @@ class WC_Product_Download implements ArrayAccess {
/** /**
* Get file type. * Get file type.
*
* @return string * @return string
*/ */
public function get_file_type() { public function get_file_type() {
@ -67,26 +73,29 @@ class WC_Product_Download implements ArrayAccess {
/** /**
* Get file extension. * Get file extension.
*
* @return string * @return string
*/ */
public function get_file_extension() { public function get_file_extension() {
$parsed_url = parse_url( $this->get_file(), PHP_URL_PATH ); $parsed_url = wp_parse_url( $this->get_file(), PHP_URL_PATH );
return pathinfo( $parsed_url, PATHINFO_EXTENSION ); return pathinfo( $parsed_url, PATHINFO_EXTENSION );
} }
/** /**
* Check if file is allowed. * Check if file is allowed.
*
* @return boolean * @return boolean
*/ */
public function is_allowed_filetype() { public function is_allowed_filetype() {
if ( 'relative' !== $this->get_type_of_file_path() ) { if ( 'relative' !== $this->get_type_of_file_path() ) {
return true; return true;
} }
return ! $this->get_file_extension() || in_array( $this->get_file_type(), $this->get_allowed_mime_types() ); return ! $this->get_file_extension() || in_array( $this->get_file_type(), $this->get_allowed_mime_types(), true );
} }
/** /**
* Validate file exists. * Validate file exists.
*
* @return boolean * @return boolean
*/ */
public function file_exists() { public function file_exists() {
@ -110,7 +119,8 @@ class WC_Product_Download implements ArrayAccess {
/** /**
* Set ID. * Set ID.
* @param string $value *
* @param string $value Download ID.
*/ */
public function set_id( $value ) { public function set_id( $value ) {
$this->data['id'] = wc_clean( $value ); $this->data['id'] = wc_clean( $value );
@ -118,7 +128,8 @@ class WC_Product_Download implements ArrayAccess {
/** /**
* Set name. * Set name.
* @param string $value *
* @param string $value Download name.
*/ */
public function set_name( $value ) { public function set_name( $value ) {
$this->data['name'] = wc_clean( $value ); $this->data['name'] = wc_clean( $value );
@ -126,8 +137,9 @@ class WC_Product_Download implements ArrayAccess {
/** /**
* Set previous_hash. * Set previous_hash.
*
* @deprecated 3.3.0 No longer using filename based hashing to keep track of files. * @deprecated 3.3.0 No longer using filename based hashing to keep track of files.
* @param string $value * @param string $value Previous hash.
*/ */
public function set_previous_hash( $value ) { public function set_previous_hash( $value ) {
wc_deprecated_function( __FUNCTION__, '3.3' ); wc_deprecated_function( __FUNCTION__, '3.3' );
@ -136,11 +148,12 @@ class WC_Product_Download implements ArrayAccess {
/** /**
* Set file. * Set file.
* @param string $value *
* @param string $value File.
*/ */
public function set_file( $value ) { public function set_file( $value ) {
switch ( $this->get_type_of_file_path( $value ) ) { switch ( $this->get_type_of_file_path( $value ) ) {
case 'absolute' : case 'absolute':
$this->data['file'] = esc_url_raw( $value ); $this->data['file'] = esc_url_raw( $value );
break; break;
default: default:
@ -157,6 +170,7 @@ class WC_Product_Download implements ArrayAccess {
/** /**
* Get id. * Get id.
*
* @return string * @return string
*/ */
public function get_id() { public function get_id() {
@ -165,6 +179,7 @@ class WC_Product_Download implements ArrayAccess {
/** /**
* Get name. * Get name.
*
* @return string * @return string
*/ */
public function get_name() { public function get_name() {
@ -173,6 +188,7 @@ class WC_Product_Download implements ArrayAccess {
/** /**
* Get previous_hash. * Get previous_hash.
*
* @deprecated 3.3.0 No longer using filename based hashing to keep track of files. * @deprecated 3.3.0 No longer using filename based hashing to keep track of files.
* @return string * @return string
*/ */
@ -183,6 +199,7 @@ class WC_Product_Download implements ArrayAccess {
/** /**
* Get file. * Get file.
*
* @return string * @return string
*/ */
public function get_file() { public function get_file() {
@ -196,13 +213,14 @@ class WC_Product_Download implements ArrayAccess {
*/ */
/** /**
* offsetGet * OffsetGet.
* @param string $offset *
* @param string $offset Offset.
* @return mixed * @return mixed
*/ */
public function offsetGet( $offset ) { public function offsetGet( $offset ) {
switch ( $offset ) { switch ( $offset ) {
default : default:
if ( is_callable( array( $this, "get_$offset" ) ) ) { if ( is_callable( array( $this, "get_$offset" ) ) ) {
return $this->{"get_$offset"}(); return $this->{"get_$offset"}();
} }
@ -212,13 +230,14 @@ class WC_Product_Download implements ArrayAccess {
} }
/** /**
* offsetSet * OffsetSet.
* @param string $offset *
* @param mixed $value * @param string $offset Offset.
* @param mixed $value Value.
*/ */
public function offsetSet( $offset, $value ) { public function offsetSet( $offset, $value ) {
switch ( $offset ) { switch ( $offset ) {
default : default:
if ( is_callable( array( $this, "set_$offset" ) ) ) { if ( is_callable( array( $this, "set_$offset" ) ) ) {
return $this->{"set_$offset"}( $value ); return $this->{"set_$offset"}( $value );
} }
@ -227,17 +246,19 @@ class WC_Product_Download implements ArrayAccess {
} }
/** /**
* offsetUnset * OffsetUnset.
* @param string $offset *
* @param string $offset Offset.
*/ */
public function offsetUnset( $offset ) {} public function offsetUnset( $offset ) {}
/** /**
* offsetExists * OffsetExists.
* @param string $offset *
* @param string $offset Offset.
* @return bool * @return bool
*/ */
public function offsetExists( $offset ) { public function offsetExists( $offset ) {
return in_array( $offset, array_keys( $this->data ) ); return in_array( $offset, array_keys( $this->data ), true );
} }
} }