plugins/ssh/classes/yf_ssh.class.php

Summary

Maintainability
F
1 wk
Test Coverage

File yf_ssh.class.php has 554 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

/**
 * SSH Client (based on SSH2 PHP extension).
 *
Severity: Major
Found in plugins/ssh/classes/yf_ssh.class.php - About 1 day to fix

    Function connect has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

        public function connect($server_info = [])
        {
            if ( ! $this->_INIT_OK || ! $server_info) {
                return false;
            }
    Severity: Minor
    Found in plugins/ssh/classes/yf_ssh.class.php - About 4 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

    yf_ssh has 32 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class yf_ssh
    {
        // TODO: chained mode like in form and table, mass actions on one server, array of servers, named group(s) of servers:
        // ssh('s23.dev')->exec('service memcached restart');
        // ssh('s23*.dev')->exec('service memcached restart');
    Severity: Minor
    Found in plugins/ssh/classes/yf_ssh.class.php - About 4 hrs to fix

      Function _skip_by_pattern has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

          public function _skip_by_pattern($path = '', $_type = 'f', $pattern_include = '', $pattern_exclude = '')
          {
              if ( ! $path) {
                  return false;
              }
      Severity: Minor
      Found in plugins/ssh/classes/yf_ssh.class.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 _perm_str2num has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

          public function _perm_str2num($perm = '')
          {
              $perm_len = strlen(trim($perm));
              if ($perm_len > 10 && $perm_len < 9) {
                  return false;
      Severity: Minor
      Found in plugins/ssh/classes/yf_ssh.class.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

      Method connect has 73 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function connect($server_info = [])
          {
              if ( ! $this->_INIT_OK || ! $server_info) {
                  return false;
              }
      Severity: Major
      Found in plugins/ssh/classes/yf_ssh.class.php - About 2 hrs to fix

        Method _init_sftp_phpseclib has 65 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function _init_sftp_phpseclib($server_info = [])
            {
                if ( ! $this->DRIVER == 'phpseclib') {
                    return false;
                }
        Severity: Major
        Found in plugins/ssh/classes/yf_ssh.class.php - About 2 hrs to fix

          Function _init_sftp_phpseclib has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
          Open

              public function _init_sftp_phpseclib($server_info = [])
              {
                  if ( ! $this->DRIVER == 'phpseclib') {
                      return false;
                  }
          Severity: Minor
          Found in plugins/ssh/classes/yf_ssh.class.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 shell_exec has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
          Open

              public function shell_exec($server_info = [], $cmd = '')
              {
                  if ( ! $this->_INIT_OK || ! $cmd || ! $server_info) {
                      return false;
                  }
          Severity: Minor
          Found in plugins/ssh/classes/yf_ssh.class.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 exec has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

              public function exec($server_info = [], $cmd = '')
              {
                  if ( ! $this->_INIT_OK || ! $cmd || ! $server_info) {
                      return false;
                  }
          Severity: Minor
          Found in plugins/ssh/classes/yf_ssh.class.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 shell_exec has 48 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function shell_exec($server_info = [], $cmd = '')
              {
                  if ( ! $this->_INIT_OK || ! $cmd || ! $server_info) {
                      return false;
                  }
          Severity: Minor
          Found in plugins/ssh/classes/yf_ssh.class.php - About 1 hr to fix

            Method exec has 46 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function exec($server_info = [], $cmd = '')
                {
                    if ( ! $this->_INIT_OK || ! $cmd || ! $server_info) {
                        return false;
                    }
            Severity: Minor
            Found in plugins/ssh/classes/yf_ssh.class.php - About 1 hr to fix

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

                  public function _skip_by_pattern($path = '', $_type = 'f', $pattern_include = '', $pattern_exclude = '')
                  {
                      if ( ! $path) {
                          return false;
                      }
              Severity: Minor
              Found in plugins/ssh/classes/yf_ssh.class.php - About 1 hr to fix

                Method _perm_str2num has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function _perm_str2num($perm = '')
                    {
                        $perm_len = strlen(trim($perm));
                        if ($perm_len > 10 && $perm_len < 9) {
                            return false;
                Severity: Minor
                Found in plugins/ssh/classes/yf_ssh.class.php - About 1 hr to fix

                  Method download_dir has 6 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      public function download_dir($server_info = [], $remote_dir = '', $local_dir = '', $pattern_include = '', $pattern_exclude = '', $level = null)
                  Severity: Minor
                  Found in plugins/ssh/classes/yf_ssh.class.php - About 45 mins to fix

                    Method scan_dir has 6 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        public function scan_dir($server_info = [], $start_dir = '', $pattern_include = '', $pattern_exclude = '', $level = 0, $single_file = '')
                    Severity: Minor
                    Found in plugins/ssh/classes/yf_ssh.class.php - About 45 mins to fix

                      Method upload_dir has 6 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                          public function upload_dir($server_info = [], $local_dir = '', $remote_dir = '', $pattern_include = '', $pattern_exclude = '', $level = null)
                      Severity: Minor
                      Found in plugins/ssh/classes/yf_ssh.class.php - About 45 mins to fix

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

                            public function mkdir($server_info = [], $dir_name = '', $dir_mode = 755, $create_index_htmls = 0, $start_folder = '')
                        Severity: Minor
                        Found in plugins/ssh/classes/yf_ssh.class.php - About 35 mins to fix

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

                              public function mkdir_m($server_info = [], $dir_name = '', $dir_mode = 755, $create_index_htmls/*!not implemented here!*/ = 0, $start_folder = '/')
                          Severity: Minor
                          Found in plugins/ssh/classes/yf_ssh.class.php - About 35 mins to fix

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

                                public function chown($server_info = [], $path = '', $new_owner = '', $new_group = '', $recursively = false)
                            Severity: Minor
                            Found in plugins/ssh/classes/yf_ssh.class.php - About 35 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                      return false;
                              Severity: Major
                              Found in plugins/ssh/classes/yf_ssh.class.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                            return false;
                                Severity: Major
                                Found in plugins/ssh/classes/yf_ssh.class.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                          return false;
                                  Severity: Major
                                  Found in plugins/ssh/classes/yf_ssh.class.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                    return false;
                                    Severity: Major
                                    Found in plugins/ssh/classes/yf_ssh.class.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                  return $con;
                                      Severity: Major
                                      Found in plugins/ssh/classes/yf_ssh.class.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                        return false;
                                        Severity: Major
                                        Found in plugins/ssh/classes/yf_ssh.class.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                  return $data;
                                          Severity: Major
                                          Found in plugins/ssh/classes/yf_ssh.class.php - About 30 mins to fix

                                            Avoid too many return statements within this method.
                                            Open

                                                            return true;
                                            Severity: Major
                                            Found in plugins/ssh/classes/yf_ssh.class.php - About 30 mins to fix

                                              Avoid too many return statements within this method.
                                              Open

                                                          return false;
                                              Severity: Major
                                              Found in plugins/ssh/classes/yf_ssh.class.php - About 30 mins to fix

                                                Avoid too many return statements within this method.
                                                Open

                                                                return false;
                                                Severity: Major
                                                Found in plugins/ssh/classes/yf_ssh.class.php - About 30 mins to fix

                                                  Avoid too many return statements within this method.
                                                  Open

                                                          return false;
                                                  Severity: Major
                                                  Found in plugins/ssh/classes/yf_ssh.class.php - About 30 mins to fix

                                                    Avoid too many return statements within this method.
                                                    Open

                                                                return $this->_sftp_connected[$_SERVER_ID];
                                                    Severity: Major
                                                    Found in plugins/ssh/classes/yf_ssh.class.php - About 30 mins to fix

                                                      Avoid too many return statements within this method.
                                                      Open

                                                              return $data;
                                                      Severity: Major
                                                      Found in plugins/ssh/classes/yf_ssh.class.php - About 30 mins to fix

                                                        Avoid too many return statements within this method.
                                                        Open

                                                                            return false;
                                                        Severity: Major
                                                        Found in plugins/ssh/classes/yf_ssh.class.php - About 30 mins to fix

                                                          Avoid too many return statements within this method.
                                                          Open

                                                                      return $con;
                                                          Severity: Major
                                                          Found in plugins/ssh/classes/yf_ssh.class.php - About 30 mins to fix

                                                            Avoid too many return statements within this method.
                                                            Open

                                                                                return true;
                                                            Severity: Major
                                                            Found in plugins/ssh/classes/yf_ssh.class.php - About 30 mins to fix

                                                              Avoid too many return statements within this method.
                                                              Open

                                                                          return false;
                                                              Severity: Major
                                                              Found in plugins/ssh/classes/yf_ssh.class.php - About 30 mins to fix

                                                                Avoid too many return statements within this method.
                                                                Open

                                                                            return false;
                                                                Severity: Major
                                                                Found in plugins/ssh/classes/yf_ssh.class.php - About 30 mins to fix

                                                                  Avoid too many return statements within this method.
                                                                  Open

                                                                                  return true;
                                                                  Severity: Major
                                                                  Found in plugins/ssh/classes/yf_ssh.class.php - About 30 mins to fix

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

                                                                        public function _init()
                                                                        {
                                                                            if ( ! $this->DRIVER) {
                                                                                $this->DRIVER = 'phpseclib';
                                                                            }
                                                                    Severity: Minor
                                                                    Found in plugins/ssh/classes/yf_ssh.class.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

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

                                                                                if ( ! $use_pswd) {
                                                                                    $key = new Crypt_RSA();
                                                                                    if ($server_info['ssh_key_pswd']) {
                                                                                        $key->setPassword($server_info['ssh_key_pswd']); // password for key
                                                                                    }
                                                                    Severity: Major
                                                                    Found in plugins/ssh/classes/yf_ssh.class.php and 1 other location - About 2 hrs to fix
                                                                    plugins/ssh/classes/yf_ssh.class.php on lines 255..266

                                                                    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 125.

                                                                    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

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

                                                                            if ( ! $use_pswd) {
                                                                                $key = new Crypt_RSA();
                                                                                if ($server_info['ssh_key_pswd']) {
                                                                                    $key->setPassword($server_info['ssh_key_pswd']); // password for key
                                                                                }
                                                                    Severity: Major
                                                                    Found in plugins/ssh/classes/yf_ssh.class.php and 1 other location - About 2 hrs to fix
                                                                    plugins/ssh/classes/yf_ssh.class.php on lines 163..174

                                                                    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 125.

                                                                    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