bcit-ci/CodeIgniter

View on GitHub
system/libraries/Email.php

Summary

Maintainability
F
1 wk
Test Coverage

File Email.php has 1234 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * CodeIgniter
 *
 * An open source application development framework for PHP
Severity: Major
Found in system/libraries/Email.php - About 3 days to fix

    CI_Email has 61 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class CI_Email {
    
        /**
         * Used as the User-Agent and X-Mailer headers' value.
         *
    Severity: Major
    Found in system/libraries/Email.php - About 1 day to fix

      Method _build_message has 126 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function _build_message()
          {
              if ($this->wordwrap === TRUE && $this->mailtype !== 'html')
              {
                  $this->_body = $this->word_wrap($this->_body);
      Severity: Major
      Found in system/libraries/Email.php - About 5 hrs to fix

        Function _build_message has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function _build_message()
            {
                if ($this->wordwrap === TRUE && $this->mailtype !== 'html')
                {
                    $this->_body = $this->word_wrap($this->_body);
        Severity: Minor
        Found in system/libraries/Email.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 _send_command has 57 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function _send_command($cmd, $data = '')
            {
                switch ($cmd)
                {
                    case 'hello':
        Severity: Major
        Found in system/libraries/Email.php - About 2 hrs to fix

          Function _prep_quoted_printable has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function _prep_quoted_printable($str)
              {
                  // ASCII code numbers for "safe" characters that can always be
                  // used literally, without encoding, as described in RFC 2049.
                  // https://www.ietf.org/rfc/rfc2049.txt
          Severity: Minor
          Found in system/libraries/Email.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 word_wrap has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

              public function word_wrap($str, $charlim = NULL)
              {
                  // Set the character limit, if not already present
                  if (empty($charlim))
                  {
          Severity: Minor
          Found in system/libraries/Email.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 _send_with_smtp has 54 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function _send_with_smtp()
              {
                  if ($this->smtp_host === '')
                  {
                      $this->_set_error_message('lang:email_no_hostname');
          Severity: Major
          Found in system/libraries/Email.php - About 2 hrs to fix

            Method word_wrap has 52 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function word_wrap($str, $charlim = NULL)
                {
                    // Set the character limit, if not already present
                    if (empty($charlim))
                    {
            Severity: Major
            Found in system/libraries/Email.php - About 2 hrs to fix

              Method _prep_quoted_printable has 51 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function _prep_quoted_printable($str)
                  {
                      // ASCII code numbers for "safe" characters that can always be
                      // used literally, without encoding, as described in RFC 2049.
                      // https://www.ietf.org/rfc/rfc2049.txt
              Severity: Major
              Found in system/libraries/Email.php - About 2 hrs to fix

                Function _send_with_smtp has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                Open

                    protected function _send_with_smtp()
                    {
                        if ($this->smtp_host === '')
                        {
                            $this->_set_error_message('lang:email_no_hostname');
                Severity: Minor
                Found in system/libraries/Email.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 _prep_q_encoding has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    protected function _prep_q_encoding($str)
                    {
                        $str = str_replace(array("\r", "\n"), '', $str);
                
                        if ($this->charset === 'UTF-8')
                Severity: Minor
                Found in system/libraries/Email.php - About 1 hr to fix

                  Function _send_command has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                  Open

                      protected function _send_command($cmd, $data = '')
                      {
                          switch ($cmd)
                          {
                              case 'hello':
                  Severity: Minor
                  Found in system/libraries/Email.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 _smtp_authenticate has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      protected function _smtp_authenticate()
                      {
                          if ( ! $this->_smtp_auth)
                          {
                              return TRUE;
                  Severity: Minor
                  Found in system/libraries/Email.php - About 1 hr to fix

                    Function _prep_q_encoding has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                    Open

                        protected function _prep_q_encoding($str)
                        {
                            $str = str_replace(array("\r", "\n"), '', $str);
                    
                            if ($this->charset === 'UTF-8')
                    Severity: Minor
                    Found in system/libraries/Email.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 _send_data has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                    Open

                        protected function _send_data($data)
                        {
                            $data .= $this->newline;
                            for ($written = $timestamp = 0, $length = self::strlen($data); $written < $length; $written += $result)
                            {
                    Severity: Minor
                    Found in system/libraries/Email.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 batch_bcc_send has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function batch_bcc_send()
                        {
                            $float = $this->bcc_batch_size - 1;
                            $set = '';
                            $chunk = array();
                    Severity: Minor
                    Found in system/libraries/Email.php - About 1 hr to fix

                      Method _smtp_connect has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          protected function _smtp_connect()
                          {
                              if (is_resource($this->_smtp_connect))
                              {
                                  return TRUE;
                      Severity: Minor
                      Found in system/libraries/Email.php - About 1 hr to fix

                        Method send has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            public function send($auto_clear = TRUE)
                            {
                                if ( ! isset($this->_headers['From']))
                                {
                                    $this->_set_error_message('lang:email_no_from');
                        Severity: Minor
                        Found in system/libraries/Email.php - About 1 hr to fix

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

                              public function batch_bcc_send()
                              {
                                  $float = $this->bcc_batch_size - 1;
                                  $set = '';
                                  $chunk = array();
                          Severity: Minor
                          Found in system/libraries/Email.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 _send_data has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              protected function _send_data($data)
                              {
                                  $data .= $this->newline;
                                  for ($written = $timestamp = 0, $length = self::strlen($data); $written < $length; $written += $result)
                                  {
                          Severity: Minor
                          Found in system/libraries/Email.php - About 1 hr to fix

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

                                public function attach($file, $disposition = '', $newname = NULL, $mime = '')
                                {
                                    if ($mime === '')
                                    {
                                        if (strpos($file, '://') === FALSE && ! file_exists($file))
                            Severity: Minor
                            Found in system/libraries/Email.php - About 1 hr to fix

                              Method from has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  public function from($from, $name = '', $return_path = NULL)
                                  {
                                      if (preg_match('/\<(.*)\>/', $from, $match))
                                      {
                                          $from = $match[1];
                              Severity: Minor
                              Found in system/libraries/Email.php - About 1 hr to fix

                                Function send has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    public function send($auto_clear = TRUE)
                                    {
                                        if ( ! isset($this->_headers['From']))
                                        {
                                            $this->_set_error_message('lang:email_no_from');
                                Severity: Minor
                                Found in system/libraries/Email.php - About 45 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 from has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    public function from($from, $name = '', $return_path = NULL)
                                    {
                                        if (preg_match('/\<(.*)\>/', $from, $match))
                                        {
                                            $from = $match[1];
                                Severity: Minor
                                Found in system/libraries/Email.php - About 45 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 _smtp_authenticate has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    protected function _smtp_authenticate()
                                    {
                                        if ( ! $this->_smtp_auth)
                                        {
                                            return TRUE;
                                Severity: Minor
                                Found in system/libraries/Email.php - About 45 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 _write_headers has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    protected function _write_headers()
                                    {
                                        if ($this->protocol === 'mail')
                                        {
                                            if (isset($this->_headers['Subject']))
                                Severity: Minor
                                Found in system/libraries/Email.php - About 35 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 initialize has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    public function initialize(array $config = array())
                                    {
                                        $this->clear();
                                
                                        foreach ($config as $key => $val)
                                Severity: Minor
                                Found in system/libraries/Email.php - About 35 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 attach has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    public function attach($file, $disposition = '', $newname = NULL, $mime = '')
                                    {
                                        if ($mime === '')
                                        {
                                            if (strpos($file, '://') === FALSE && ! file_exists($file))
                                Severity: Minor
                                Found in system/libraries/Email.php - About 35 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

                                Avoid too many return statements within this method.
                                Open

                                            return FALSE;
                                Severity: Major
                                Found in system/libraries/Email.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                          return TRUE;
                                  Severity: Major
                                  Found in system/libraries/Email.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                    return FALSE;
                                    Severity: Major
                                    Found in system/libraries/Email.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                  return FALSE;
                                      Severity: Major
                                      Found in system/libraries/Email.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                return TRUE;
                                        Severity: Major
                                        Found in system/libraries/Email.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                          return FALSE;
                                          Severity: Major
                                          Found in system/libraries/Email.php - About 30 mins to fix

                                            Avoid too many return statements within this method.
                                            Open

                                                        return FALSE;
                                            Severity: Major
                                            Found in system/libraries/Email.php - About 30 mins to fix

                                              Avoid too many return statements within this method.
                                              Open

                                                          return FALSE;
                                              Severity: Major
                                              Found in system/libraries/Email.php - About 30 mins to fix

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

                                                    public function reply_to($replyto, $name = '')
                                                    {
                                                        if (preg_match('/\<(.*)\>/', $replyto, $match))
                                                        {
                                                            $replyto = $match[1];
                                                Severity: Minor
                                                Found in system/libraries/Email.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

                                                    public function valid_email($email)
                                                    {
                                                        if (function_exists('idn_to_ascii') && preg_match('#\A([^@]+)@(.+)\z#', $email, $matches))
                                                        {
                                                            $domain = defined('INTL_IDNA_VARIANT_UTS46')
                                                Severity: Major
                                                Found in system/libraries/Email.php and 1 other location - About 2 hrs to fix
                                                system/libraries/Form_validation.php on lines 1239..1254

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

                                                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 (preg_match_all('|\{unwrap\}(.+?)\{/unwrap\}|s', $str, $matches))
                                                        {
                                                            for ($i = 0, $c = count($matches[0]); $i < $c; $i++)
                                                            {
                                                                $unwrap[] = $matches[1][$i];
                                                Severity: Major
                                                Found in system/libraries/Email.php and 1 other location - About 1 hr to fix
                                                system/helpers/text_helper.php on lines 463..470

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

                                                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