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