CaffGeek/MBACNationals

View on GitHub
Web.Admin/2014/wordpress/wp-admin/includes/file.php

Summary

Maintainability
F
1 wk
Test Coverage

Function request_filesystem_credentials has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
Open

function request_filesystem_credentials($form_post, $type = '', $error = false, $context = false) {
    $req_cred = apply_filters('request_filesystem_credentials', '', $form_post, $type, $error, $context);
    if ( '' !== $req_cred )
        return $req_cred;

Severity: Minor
Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 1 day 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

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

<?php
/**
 * File contains all the administration image manipulation functions.
 *
 * @package WordPress
Severity: Major
Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 1 day to fix

    Function unzip_file has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
    Open

    function unzip_file($file, $to) {
        global $wp_filesystem;
    
        if ( ! $wp_filesystem || !is_object($wp_filesystem) )
            return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
    Severity: Minor
    Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 6 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

    Method request_filesystem_credentials has 133 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function request_filesystem_credentials($form_post, $type = '', $error = false, $context = false) {
        $req_cred = apply_filters('request_filesystem_credentials', '', $form_post, $type, $error, $context);
        if ( '' !== $req_cred )
            return $req_cred;
    
    
    Severity: Major
    Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 5 hrs to fix

      Function wp_handle_upload has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

      function wp_handle_upload( &$file, $overrides = false, $time = null ) {
          // The default error handler.
          if (! function_exists( 'wp_handle_upload_error' ) ) {
              function wp_handle_upload_error( &$file, $message ) {
                  return array( 'error'=>$message );
      Severity: Minor
      Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 3 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 copy_dir has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

      function copy_dir($from, $to) {
          global $wp_filesystem;
      
          $dirlist = $wp_filesystem->dirlist($from);
      
      
      Severity: Minor
      Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 3 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 wp_handle_sideload has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

      function wp_handle_sideload( &$file, $overrides = false ) {
          // The default error handler.
          if (! function_exists( 'wp_handle_upload_error' ) ) {
              function wp_handle_upload_error( &$file, $message ) {
                  return array( 'error'=>$message );
      Severity: Minor
      Found in Web.Admin/2014/wordpress/wp-admin/includes/file.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 list_files has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

      function list_files( $folder = '', $levels = 100 ) {
          if( empty($folder) )
              return false;
      
          if( ! $levels )
      Severity: Minor
      Found in Web.Admin/2014/wordpress/wp-admin/includes/file.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

      Method wp_handle_upload has 58 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function wp_handle_upload( &$file, $overrides = false, $time = null ) {
          // The default error handler.
          if (! function_exists( 'wp_handle_upload_error' ) ) {
              function wp_handle_upload_error( &$file, $message ) {
                  return array( 'error'=>$message );
      Severity: Major
      Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 2 hrs to fix

        Method wp_handle_sideload has 56 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function wp_handle_sideload( &$file, $overrides = false ) {
            // The default error handler.
            if (! function_exists( 'wp_handle_upload_error' ) ) {
                function wp_handle_upload_error( &$file, $message ) {
                    return array( 'error'=>$message );
        Severity: Major
        Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 2 hrs to fix

          Method unzip_file has 47 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function unzip_file($file, $to) {
              global $wp_filesystem;
          
              if ( ! $wp_filesystem || !is_object($wp_filesystem) )
                  return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
          Severity: Minor
          Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 1 hr to fix

            Function get_filesystem_method has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

            function get_filesystem_method($args = array(), $context = false) {
                $method = defined('FS_METHOD') ? FS_METHOD : false; //Please ensure that this is either 'direct', 'ssh', 'ftpext' or 'ftpsockets'
            
                if( ! $method && function_exists('getmyuid') && function_exists('fileowner') ){
                    if ( !$context )
            Severity: Minor
            Found in Web.Admin/2014/wordpress/wp-admin/includes/file.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

            Function WP_Filesystem has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

            function WP_Filesystem( $args = false, $context = false ) {
                global $wp_filesystem;
            
                require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
            
            
            Severity: Minor
            Found in Web.Admin/2014/wordpress/wp-admin/includes/file.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 WP_Filesystem has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function WP_Filesystem( $args = false, $context = false ) {
                global $wp_filesystem;
            
                require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
            
            
            Severity: Minor
            Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 1 hr to fix

              Consider simplifying this complex logical expression.
              Open

                  if ( ! $error &&
                          (
                              ( !empty($credentials['password']) && !empty($credentials['username']) && !empty($credentials['hostname']) ) ||
                              ( 'ssh' == $credentials['connection_type'] && !empty($credentials['public_key']) && !empty($credentials['private_key']) )
                          ) ) {
              Severity: Major
              Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 1 hr to fix

                Avoid too many return statements within this method.
                Open

                        return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) );
                Severity: Major
                Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                              return $upload_error_handler( $file, __( 'File type does not meet security guidelines. Try another.' ));
                  Severity: Major
                  Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                    return new WP_Error('copy_failed', __('Could not copy file'), $to . $file['filename']);
                    Severity: Major
                    Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                              return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) );
                      Severity: Major
                      Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                return $upload_error_handler( $file, $uploads['error'] );
                        Severity: Major
                        Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                      return $upload_error_handler( $file, __( 'File type does not meet security guidelines. Try another.' ));
                          Severity: Major
                          Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                                    return new WP_Error('mkdir_failed', __('Could not create directory'), $tmppath);
                            Severity: Major
                            Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                      return $upload_error_handler( $file, __( 'Specified file failed upload test.' ));
                              Severity: Major
                              Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                    return true;
                                Severity: Major
                                Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                      return $return;
                                  Severity: Major
                                  Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                        return $tmpfname;
                                    Severity: Major
                                    Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                          return true;
                                      Severity: Major
                                      Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                            return apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ) );
                                        Severity: Major
                                        Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                  return $upload_error_handler( $file, $uploads['error'] );
                                          Severity: Major
                                          Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 30 mins to fix

                                            Avoid too many return statements within this method.
                                            Open

                                                    return new WP_Error('http_404', trim($response['response']['message']));
                                            Severity: Major
                                            Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php - About 30 mins to fix

                                              Identical blocks of code found in 2 locations. Consider refactoring.
                                              Open

                                                  if ( $test_type ) {
                                                      $wp_filetype = wp_check_filetype( $file['name'], $mimes );
                                              
                                                      extract( $wp_filetype );
                                              
                                              
                                              Severity: Major
                                              Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php and 1 other location - About 2 hrs to fix
                                              Web.Admin/2014/wordpress/wp-admin/includes/file.php on lines 287..302

                                              Duplicated Code

                                              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                              Tuning

                                              This issue has a mass of 133.

                                              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                              Refactorings

                                              Further Reading

                                              Identical blocks of code found in 2 locations. Consider refactoring.
                                              Open

                                                  if ( $test_type ) {
                                                      $wp_filetype = wp_check_filetype( $file['name'], $mimes );
                                              
                                                      extract( $wp_filetype );
                                              
                                              
                                              Severity: Major
                                              Found in Web.Admin/2014/wordpress/wp-admin/includes/file.php and 1 other location - About 2 hrs to fix
                                              Web.Admin/2014/wordpress/wp-admin/includes/file.php on lines 395..408

                                              Duplicated Code

                                              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                              Tuning

                                              This issue has a mass of 133.

                                              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                              Refactorings

                                              Further Reading

                                              There are no issues that match your filters.

                                              Category
                                              Status