File Media.php
has 328 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* WPDLib\FieldTypes\Media class
*
* @package WPDLib
Function verify_mime_types
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
protected function verify_mime_types( $accepted_types ) {
if ( 'all' === $accepted_types ) {
return array();
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function check_extension
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
protected function check_extension( $extension, $accepted_types = 'all' ) {
if ( 'all' == $accepted_types || ! $accepted_types ) {
return true;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function parse
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public function parse( $val, $formatted = false ) {
if ( 'url' === $this->args['store'] ) {
$val = FieldManager::format( $val, 'url', 'input' );
} else {
$val = absint( $val );
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function validate
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public function validate( $val = null ) {
if ( ! $val ) {
if ( 'url' === $this->args['store'] ) {
return '';
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method verify_mime_types
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function verify_mime_types( $accepted_types ) {
if ( 'all' === $accepted_types ) {
return array();
}
Method get_attachment_field
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function get_attachment_field( $id, $field = 'url' ) {
switch ( $field ) {
case 'id':
case 'ID':
return $id;
Function get_attachment_path
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
protected function get_attachment_path( $id, $mode = 'url', $size = false ) {
$url = wp_get_attachment_url( $id );
if ( $size ) {
$src = wp_get_attachment_image_src( $id, $size, false );
if ( is_array( $src ) ) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
return $orig_val;
Avoid too many return
statements within this method. Open
return get_attachment_link( $id );
Avoid too many return
statements within this method. Open
return $this->get_attachment_path( $id, $field );
Avoid too many return
statements within this method. Open
return $this->get_attachment_path( $id, 'url', substr( $field, 0, -4 ) );
Avoid too many return
statements within this method. Open
return $this->get_post_field( $id, 'post_content' );
Avoid too many return
statements within this method. Open
return wp_basename( get_attached_file( $id ) );
Avoid too many return
statements within this method. Open
return new WPError( 'invalid_media_mime_type', sprintf( __( 'The media item with ID %1$s is neither of the valid formats (%2$s).', 'wpdlib' ), $val, $valid_formats ) );
Avoid too many return
statements within this method. Open
return $this->get_attachment_field( $id, $args['field'] );
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return '';
Avoid too many return
statements within this method. Open
return $this->get_attachment_mime_type( $id, $field );
Avoid too many return
statements within this method. Open
return $this->get_attachment_path( $id, 'path', substr( $field, 0, -5 ) );
Avoid too many return
statements within this method. Open
return $id;
Avoid too many return
statements within this method. Open
return wp_mime_type_icon( $id );
Avoid too many return
statements within this method. Open
return true;
Function enqueue_assets
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function enqueue_assets() {
global $post;
if ( self::is_enqueued( __CLASS__ ) ) {
return array();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"