felixarntz/wpdlib

View on GitHub
inc/WPDLib/FieldTypes/Media.php

Summary

Maintainability
D
3 days
Test Coverage

File Media.php has 328 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * WPDLib\FieldTypes\Media class
 *
 * @package WPDLib
Severity: Minor
Found in inc/WPDLib/FieldTypes/Media.php - About 3 hrs to fix

    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();
                }
    
    
    Severity: Minor
    Found in inc/WPDLib/FieldTypes/Media.php - About 2 hrs to fix

    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;
                }
    
    
    Severity: Minor
    Found in inc/WPDLib/FieldTypes/Media.php - About 2 hrs to fix

    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 );
    Severity: Minor
    Found in inc/WPDLib/FieldTypes/Media.php - About 2 hrs to fix

    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 '';
                    }
    Severity: Minor
    Found in inc/WPDLib/FieldTypes/Media.php - About 1 hr to fix

    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();
                }
    
    
    Severity: Minor
    Found in inc/WPDLib/FieldTypes/Media.php - About 1 hr to fix

      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;
      Severity: Minor
      Found in inc/WPDLib/FieldTypes/Media.php - About 1 hr to fix

        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 ) ) {
        Severity: Minor
        Found in inc/WPDLib/FieldTypes/Media.php - About 1 hr to fix

        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;
        Severity: Major
        Found in inc/WPDLib/FieldTypes/Media.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                              return get_attachment_link( $id );
          Severity: Major
          Found in inc/WPDLib/FieldTypes/Media.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                                return $this->get_attachment_path( $id, $field );
            Severity: Major
            Found in inc/WPDLib/FieldTypes/Media.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                                      return $this->get_attachment_path( $id, 'url', substr( $field, 0, -4 ) );
              Severity: Major
              Found in inc/WPDLib/FieldTypes/Media.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                                    return $this->get_post_field( $id, 'post_content' );
                Severity: Major
                Found in inc/WPDLib/FieldTypes/Media.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                                      return wp_basename( get_attached_file( $id ) );
                  Severity: Major
                  Found in inc/WPDLib/FieldTypes/Media.php - About 30 mins to fix

                    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 ) );
                    Severity: Major
                    Found in inc/WPDLib/FieldTypes/Media.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                          return $this->get_attachment_field( $id, $args['field'] );
                      Severity: Major
                      Found in inc/WPDLib/FieldTypes/Media.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                    return false;
                        Severity: Major
                        Found in inc/WPDLib/FieldTypes/Media.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                              return '';
                          Severity: Major
                          Found in inc/WPDLib/FieldTypes/Media.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                                return $this->get_attachment_mime_type( $id, $field );
                            Severity: Major
                            Found in inc/WPDLib/FieldTypes/Media.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                                      return $this->get_attachment_path( $id, 'path', substr( $field, 0, -5 ) );
                              Severity: Major
                              Found in inc/WPDLib/FieldTypes/Media.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                            return $id;
                                Severity: Major
                                Found in inc/WPDLib/FieldTypes/Media.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                                      return wp_mime_type_icon( $id );
                                  Severity: Major
                                  Found in inc/WPDLib/FieldTypes/Media.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                        return true;
                                    Severity: Major
                                    Found in inc/WPDLib/FieldTypes/Media.php - About 30 mins to fix

                                      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();
                                      Severity: Minor
                                      Found in inc/WPDLib/FieldTypes/Media.php - About 25 mins to fix

                                      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

                                      There are no issues that match your filters.

                                      Category
                                      Status