bcit-ci/CodeIgniter

View on GitHub
system/libraries/Image_lib.php

Summary

Maintainability
F
1 wk
Test Coverage

File Image_lib.php has 941 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/Image_lib.php - About 2 days to fix

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

        public function initialize($props = array())
        {
            // Convert array elements into class variables
            if (count($props) > 0)
            {
    Severity: Minor
    Found in system/libraries/Image_lib.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 initialize has 123 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function initialize($props = array())
        {
            // Convert array elements into class variables
            if (count($props) > 0)
            {
    Severity: Major
    Found in system/libraries/Image_lib.php - About 4 hrs to fix

      Method text_watermark has 106 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function text_watermark()
          {
              if ( ! ($src_img = $this->image_create_gd()))
              {
                  return FALSE;
      Severity: Major
      Found in system/libraries/Image_lib.php - About 4 hrs to fix

        Function text_watermark has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
        Open

            public function text_watermark()
            {
                if ( ! ($src_img = $this->image_create_gd()))
                {
                    return FALSE;
        Severity: Minor
        Found in system/libraries/Image_lib.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

        CI_Image_lib has 25 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class CI_Image_lib {
        
            /**
             * PHP extension/library to use for image manipulation
             * Can be: imagemagick, netpbm, gd, gd2
        Severity: Minor
        Found in system/libraries/Image_lib.php - About 2 hrs to fix

          Method overlay_watermark has 67 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function overlay_watermark()
              {
                  if ( ! function_exists('imagecolortransparent'))
                  {
                      $this->set_error('imglib_gd_required');
          Severity: Major
          Found in system/libraries/Image_lib.php - About 2 hrs to fix

            Method image_process_gd has 60 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function image_process_gd($action = 'resize')
                {
                    $v2_override = FALSE;
            
                    // If the target width/height match the source, AND if the new file name is not equal to the old file name
            Severity: Major
            Found in system/libraries/Image_lib.php - About 2 hrs to fix

              Method image_process_netpbm has 60 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function image_process_netpbm($action = 'resize')
                  {
                      if ($this->library_path === '')
                      {
                          $this->set_error('imglib_libpath_invalid');
              Severity: Major
              Found in system/libraries/Image_lib.php - About 2 hrs to fix

                Function image_process_netpbm has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function image_process_netpbm($action = 'resize')
                    {
                        if ($this->library_path === '')
                        {
                            $this->set_error('imglib_libpath_invalid');
                Severity: Minor
                Found in system/libraries/Image_lib.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 image_mirror_gd has 51 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function image_mirror_gd()
                    {
                        if ( ! $src_img = $this->image_create_gd())
                        {
                            return FALSE;
                Severity: Major
                Found in system/libraries/Image_lib.php - About 2 hrs to fix

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

                      public function image_process_gd($action = 'resize')
                      {
                          $v2_override = FALSE;
                  
                          // If the target width/height match the source, AND if the new file name is not equal to the old file name
                  Severity: Minor
                  Found in system/libraries/Image_lib.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 image_mirror_gd has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function image_mirror_gd()
                      {
                          if ( ! $src_img = $this->image_create_gd())
                          {
                              return FALSE;
                  Severity: Minor
                  Found in system/libraries/Image_lib.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 image_save_gd has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function image_save_gd($resource)
                      {
                          switch ($this->image_type)
                          {
                              case 1:
                  Severity: Minor
                  Found in system/libraries/Image_lib.php - About 1 hr to fix

                    Method image_process_imagemagick has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function image_process_imagemagick($action = 'resize')
                        {
                            // Do we have a vaild library path?
                            if ($this->library_path === '')
                            {
                    Severity: Minor
                    Found in system/libraries/Image_lib.php - About 1 hr to fix

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

                          public function overlay_watermark()
                          {
                              if ( ! function_exists('imagecolortransparent'))
                              {
                                  $this->set_error('imglib_gd_required');
                      Severity: Minor
                      Found in system/libraries/Image_lib.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 image_create_gd has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public function image_create_gd($path = '', $image_type = '')
                          {
                              if ($path === '')
                              {
                                  $path = $this->full_src_path;
                      Severity: Minor
                      Found in system/libraries/Image_lib.php - About 1 hr to fix

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

                            public function get_image_properties($path = '', $return = FALSE)
                            {
                                // For now we require GD but we should
                                // find a way to determine this using IM or NetPBM
                        
                        
                        Severity: Minor
                        Found in system/libraries/Image_lib.php - About 1 hr to fix

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

                              public function image_reproportion()
                              {
                                  if (($this->width === 0 && $this->height === 0) OR $this->orig_width === 0 OR $this->orig_height === 0
                                      OR ( ! ctype_digit((string) $this->width) && ! ctype_digit((string) $this->height))
                                      OR ! ctype_digit((string) $this->orig_width) OR ! ctype_digit((string) $this->orig_height))
                          Severity: Minor
                          Found in system/libraries/Image_lib.php - About 1 hr to fix

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

                                public function image_save_gd($resource)
                                {
                                    switch ($this->image_type)
                                    {
                                        case 1:
                            Severity: Minor
                            Found in system/libraries/Image_lib.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 clear has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                public function clear()
                                {
                                    $props = array('thumb_marker', 'library_path', 'source_image', 'new_image', 'width', 'height', 'rotation_angle', 'x_axis', 'y_axis', 'wm_text', 'wm_overlay_path', 'wm_font_path', 'wm_shadow_color', 'source_folder', 'dest_folder', 'mime_type', 'orig_width', 'orig_height', 'image_type', 'size_str', 'full_src_path', 'full_dst_path');
                            
                                    foreach ($props as $val)
                            Severity: Minor
                            Found in system/libraries/Image_lib.php - About 1 hr to fix

                              Function image_process_imagemagick has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  public function image_process_imagemagick($action = 'resize')
                                  {
                                      // Do we have a vaild library path?
                                      if ($this->library_path === '')
                                      {
                              Severity: Minor
                              Found in system/libraries/Image_lib.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 image_reproportion has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  public function image_reproportion()
                                  {
                                      if (($this->width === 0 && $this->height === 0) OR $this->orig_width === 0 OR $this->orig_height === 0
                                          OR ( ! ctype_digit((string) $this->width) && ! ctype_digit((string) $this->height))
                                          OR ! ctype_digit((string) $this->orig_width) OR ! ctype_digit((string) $this->orig_height))
                              Severity: Minor
                              Found in system/libraries/Image_lib.php - About 55 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 size_calculator has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  public function size_calculator($vals)
                                  {
                                      if ( ! is_array($vals))
                                      {
                                          return;
                              Severity: Minor
                              Found in system/libraries/Image_lib.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/Image_lib.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

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

                                  Avoid too many return statements within this method.
                                  Open

                                                  return imagecreatefrompng($path);
                                  Severity: Major
                                  Found in system/libraries/Image_lib.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

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

                                      Avoid too many return statements within this method.
                                      Open

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

                                        Avoid too many return statements within this method.
                                        Open

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

                                          Avoid too many return statements within this method.
                                          Open

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

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

                                                public function image_create_gd($path = '', $image_type = '')
                                                {
                                                    if ($path === '')
                                                    {
                                                        $path = $this->full_src_path;
                                            Severity: Minor
                                            Found in system/libraries/Image_lib.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 image_display_gd has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                            Open

                                                public function image_display_gd($resource)
                                                {
                                                    // RFC 6266 allows for multibyte filenames, but only in UTF-8,
                                                    // so we have to make it conditional ...
                                                    $filename = basename(empty($this->new_image) ? $this->source_image : $this->new_image);
                                            Severity: Minor
                                            Found in system/libraries/Image_lib.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

                                                    else
                                                    {
                                                        for ($i = 0; $i < $width; $i++)
                                                        {
                                                            $top = 0;
                                            Severity: Major
                                            Found in system/libraries/Image_lib.php and 1 other location - About 2 hrs to fix
                                            system/libraries/Image_lib.php on lines 1067..1106

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

                                            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 ($this->rotation_angle === 'hor')
                                                    {
                                                        for ($i = 0; $i < $height; $i++)
                                                        {
                                                            $left = 0;
                                            Severity: Major
                                            Found in system/libraries/Image_lib.php and 1 other location - About 2 hrs to fix
                                            system/libraries/Image_lib.php on lines 1087..1106

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

                                            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