rilwis/meta-box

View on GitHub
inc/fields/file.php

Summary

Maintainability
C
1 day
Test Coverage

File file.php has 305 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
defined( 'ABSPATH' ) || die;

/**
 * The file upload file which allows users to upload files via the default HTML <input type="file">.
Severity: Minor
Found in inc/fields/file.php - About 3 hrs to fix

    Method file_html has 45 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected static function file_html( $file, $index, $field ) {
            $i18n_delete = apply_filters( 'rwmb_file_delete_string', _x( 'Delete', 'file upload', 'meta-box' ) );
            $i18n_edit   = apply_filters( 'rwmb_file_edit_string', _x( 'Edit', 'file upload', 'meta-box' ) );
            $attributes  = self::get_attributes( $field, $file );
    
    
    Severity: Minor
    Found in inc/fields/file.php - About 1 hr to fix

      Method html has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function html( $meta, $field ) {
              $meta      = array_filter( (array) $meta );
              $i18n_more = apply_filters( 'rwmb_file_add_string', _x( '+ Add new file', 'file upload', 'meta-box' ), $field );
              $html      = self::get_uploaded_files( $meta, $field );
      
      
      Severity: Minor
      Found in inc/fields/file.php - About 1 hr to fix

        Method ajax_delete_file has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function ajax_delete_file() {
                $request  = rwmb_request();
                $field_id = (string) $request->filter_post( 'field_id' );
                $type     = str_contains( $request->filter_post( 'field_name' ), '[' ) ? 'child' : 'top';
                check_ajax_referer( "rwmb-delete-file_{$field_id}" );
        Severity: Minor
        Found in inc/fields/file.php - About 1 hr to fix

          Method clone_value has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              public static function clone_value( $new, $old, $object_id, $field, $data_source = null ) {
          Severity: Minor
          Found in inc/fields/file.php - About 35 mins to fix

            Function transform has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                protected static function transform( $input_name ) {
                    // @codingStandardsIgnoreStart
                    foreach ( $_FILES[ $input_name ] as $key => $list ) {
                        foreach ( $list as $index => $value ) {
                            $file_key = "{$input_name}_{$index}";
            Severity: Minor
            Found in inc/fields/file.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

            Function value has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                public static function value( $new, $old, $post_id, $field ) {
                    $input = $field['index'] ?? $field['input_name'];
            
                    // @codingStandardsIgnoreLine
                    if ( empty( $input ) || empty( $_FILES[ $input ] ) ) {
            Severity: Minor
            Found in inc/fields/file.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