luyadev/yii-helpers

View on GitHub
src/helpers/XLSXWriter.php

Summary

Maintainability
F
1 wk
Test Coverage
D
60%

File XLSXWriter.php has 1038 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace luya\yii\helpers;

use ZipArchive;
Severity: Major
Found in src/helpers/XLSXWriter.php - About 2 days to fix

    Function numberFormatStandardized has a Cognitive Complexity of 55 (exceeds 5 allowed). Consider refactoring.
    Open

        private static function numberFormatStandardized($num_format)
        {
            if ($num_format == 'money') {
                $num_format = 'dollar';
            }
    Severity: Minor
    Found in src/helpers/XLSXWriter.php - About 1 day to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function styleFontIndexes has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function styleFontIndexes()
        {
            static $border_allowed = ['left', 'right', 'top', 'bottom'];
            static $border_style_allowed = [
                'thin',
    Severity: Minor
    Found in src/helpers/XLSXWriter.php - About 7 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

    XLSXWriter has 41 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class XLSXWriter
    {
        //https://www.ecma-international.org/publications/standards/Ecma-376.htm
        //http://officeopenxml.com/SSstyles.php
        //------------------------------------------------------------------
    Severity: Minor
    Found in src/helpers/XLSXWriter.php - About 5 hrs to fix

      Method writeStylesXML has 123 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function writeStylesXML()
          {
              $r = $this->styleFontIndexes();
              $fills = $r['fills'];
              $fonts = $r['fonts'];
      Severity: Major
      Found in src/helpers/XLSXWriter.php - About 4 hrs to fix

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

            protected function writeStylesXML()
            {
                $r = $this->styleFontIndexes();
                $fills = $r['fills'];
                $fonts = $r['fonts'];
        Severity: Minor
        Found in src/helpers/XLSXWriter.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

        Method styleFontIndexes has 102 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function styleFontIndexes()
            {
                static $border_allowed = ['left', 'right', 'top', 'bottom'];
                static $border_style_allowed = [
                    'thin',
        Severity: Major
        Found in src/helpers/XLSXWriter.php - About 4 hrs to fix

          Method initializeSheet has 96 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function initializeSheet(
                  $sheet_name,
                  $col_widths = [],
                  $auto_filter = false,
                  $freeze_rows = false,
          Severity: Major
          Found in src/helpers/XLSXWriter.php - About 3 hrs to fix

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

                public static function convert_date_time($date_input) //thanks to Excel::Writer::XLSX::Worksheet.pm (perl)
                {
                    $days = 0;    # Number of days since epoch
                    $seconds = 0;    # Time expressed as fraction of 24h hours in seconds
                    $year = $month = $day = 0;
            Severity: Major
            Found in src/helpers/XLSXWriter.php - About 2 hrs to fix

              Method numberFormatStandardized has 55 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private static function numberFormatStandardized($num_format)
                  {
                      if ($num_format == 'money') {
                          $num_format = 'dollar';
                      }
              Severity: Major
              Found in src/helpers/XLSXWriter.php - About 2 hrs to fix

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

                    protected function writeCell(
                        XLSXWriter_BuffererWriter &$file,
                        $row_number,
                        $column_number,
                        $value,
                Severity: Minor
                Found in src/helpers/XLSXWriter.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 writeToFile has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function writeToFile($filename)
                    {
                        foreach ($this->sheets as $sheet_name => $sheet) {
                            $this->finalizeSheet($sheet_name);//making sure all footers have been written
                        }
                Severity: Minor
                Found in src/helpers/XLSXWriter.php - About 1 hr to fix

                  Method writeSheetRow has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function writeSheetRow($sheet_name, array $row, $row_options = null)
                      {
                          if (empty($sheet_name)) {
                              return;
                          }
                  Severity: Minor
                  Found in src/helpers/XLSXWriter.php - About 1 hr to fix

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

                        public static function convert_date_time($date_input) //thanks to Excel::Writer::XLSX::Worksheet.pm (perl)
                        {
                            $days = 0;    # Number of days since epoch
                            $seconds = 0;    # Time expressed as fraction of 24h hours in seconds
                            $year = $month = $day = 0;
                    Severity: Minor
                    Found in src/helpers/XLSXWriter.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 determineNumberFormatType has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        private static function determineNumberFormatType($num_format)
                        {
                            $num_format = preg_replace("/\[(Black|Blue|Cyan|Green|Magenta|Red|White|Yellow)\]/i", "", $num_format);
                            if ($num_format == 'GENERAL') {
                                return 'n_auto';
                    Severity: Minor
                    Found in src/helpers/XLSXWriter.php - About 1 hr to fix

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

                          private static function determineNumberFormatType($num_format)
                          {
                              $num_format = preg_replace("/\[(Black|Blue|Cyan|Green|Magenta|Red|White|Yellow)\]/i", "", $num_format);
                              if ($num_format == 'GENERAL') {
                                  return 'n_auto';
                      Severity: Minor
                      Found in src/helpers/XLSXWriter.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 writeSheetHeader has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public function writeSheetHeader($sheet_name, array $header_types, $col_options = null)
                          {
                              if (empty($sheet_name) || empty($header_types) || !empty($this->sheets[$sheet_name])) {
                                  return;
                              }
                      Severity: Minor
                      Found in src/helpers/XLSXWriter.php - About 1 hr to fix

                        Method finalizeSheet has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            protected function finalizeSheet($sheet_name)
                            {
                                if (empty($sheet_name) || $this->sheets[$sheet_name]->finalized) {
                                    return;
                                }
                        Severity: Minor
                        Found in src/helpers/XLSXWriter.php - About 1 hr to fix

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

                              protected function buildWorkbookXML()
                              {
                                  $i = 0;
                                  $workbook_xml = "";
                                  $workbook_xml .= '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' . "\n";
                          Severity: Minor
                          Found in src/helpers/XLSXWriter.php - About 1 hr to fix

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

                                protected function initializeSheet(
                                    $sheet_name,
                                    $col_widths = [],
                                    $auto_filter = false,
                                    $freeze_rows = false,
                            Severity: Minor
                            Found in src/helpers/XLSXWriter.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

                            Consider simplifying this complex logical expression.
                            Open

                                        if ($ignore_until == '' && ($c == ' ' || $c == '-' || $c == '(' || $c == ')') && ($i == 0 || $num_format[$i - 1] != '_')) {
                                            $escaped .= "\\" . $c;
                                        } else {
                                            $escaped .= $c;
                                        }
                            Severity: Major
                            Found in src/helpers/XLSXWriter.php - About 1 hr to fix

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

                                  public function writeToFile($filename)
                                  {
                                      foreach ($this->sheets as $sheet_name => $sheet) {
                                          $this->finalizeSheet($sheet_name);//making sure all footers have been written
                                      }
                              Severity: Minor
                              Found in src/helpers/XLSXWriter.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

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

                                      XLSXWriter_BuffererWriter &$file,
                                      $row_number,
                                      $column_number,
                                      $value,
                                      $num_format_type,
                              Severity: Minor
                              Found in src/helpers/XLSXWriter.php - About 45 mins to fix

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

                                    public function markMergedCell($sheet_name, $start_cell_row, $start_cell_column, $end_cell_row, $end_cell_column)
                                Severity: Minor
                                Found in src/helpers/XLSXWriter.php - About 35 mins to fix

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

                                          $sheet_name,
                                          $col_widths = [],
                                          $auto_filter = false,
                                          $freeze_rows = false,
                                          $freeze_columns = false
                                  Severity: Minor
                                  Found in src/helpers/XLSXWriter.php - About 35 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                return 'n_datetime';
                                    Severity: Major
                                    Found in src/helpers/XLSXWriter.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                  return 'n_numeric';
                                      Severity: Major
                                      Found in src/helpers/XLSXWriter.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                    return 'n_date';
                                        Severity: Major
                                        Found in src/helpers/XLSXWriter.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                  return 'n_auto';
                                          Severity: Major
                                          Found in src/helpers/XLSXWriter.php - About 30 mins to fix

                                            Avoid too many return statements within this method.
                                            Open

                                                    return $days + $seconds;
                                            Severity: Major
                                            Found in src/helpers/XLSXWriter.php - About 30 mins to fix

                                              Avoid too many return statements within this method.
                                              Open

                                                          return 'n_numeric';
                                              Severity: Major
                                              Found in src/helpers/XLSXWriter.php - About 30 mins to fix

                                                Avoid too many return statements within this method.
                                                Open

                                                            return 0;
                                                Severity: Major
                                                Found in src/helpers/XLSXWriter.php - About 30 mins to fix

                                                  Avoid too many return statements within this method.
                                                  Open

                                                              return 'n_date';
                                                  Severity: Major
                                                  Found in src/helpers/XLSXWriter.php - About 30 mins to fix

                                                    Avoid too many return statements within this method.
                                                    Open

                                                                return 0;
                                                    Severity: Major
                                                    Found in src/helpers/XLSXWriter.php - About 30 mins to fix

                                                      Avoid too many return statements within this method.
                                                      Open

                                                                  return 'n_date';
                                                      Severity: Major
                                                      Found in src/helpers/XLSXWriter.php - About 30 mins to fix

                                                        Avoid too many return statements within this method.
                                                        Open

                                                                    return 'n_numeric';
                                                        Severity: Major
                                                        Found in src/helpers/XLSXWriter.php - About 30 mins to fix

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

                                                              public function writeSheetHeader($sheet_name, array $header_types, $col_options = null)
                                                              {
                                                                  if (empty($sheet_name) || empty($header_types) || !empty($this->sheets[$sheet_name])) {
                                                                      return;
                                                                  }
                                                          Severity: Minor
                                                          Found in src/helpers/XLSXWriter.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 finalizeSheet has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                          Open

                                                              protected function finalizeSheet($sheet_name)
                                                              {
                                                                  if (empty($sheet_name) || $this->sheets[$sheet_name]->finalized) {
                                                                      return;
                                                                  }
                                                          Severity: Minor
                                                          Found in src/helpers/XLSXWriter.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 (isset($style['color']) && is_string($style['color']) && $style['color'][0] == '#') {
                                                                          $v = substr($style['color'], 1, 6);
                                                                          $v = strlen($v) == 3 ? $v[0] . $v[0] . $v[1] . $v[1] . $v[2] . $v[2] : $v;// expand cf0 => ccff00
                                                                          $font['color'] = "FF" . strtoupper($v);
                                                                      }
                                                          Severity: Major
                                                          Found in src/helpers/XLSXWriter.php and 1 other location - About 3 hrs to fix
                                                          src/helpers/XLSXWriter.php on lines 524..528

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

                                                          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 (isset($style['border-color']) && is_string($style['border-color']) && $style['border-color'][0] == '#') {
                                                                              $v = substr($style['border-color'], 1, 6);
                                                                              $v = strlen($v) == 3 ? $v[0] . $v[0] . $v[1] . $v[1] . $v[2] . $v[2] : $v;// expand cf0 => ccff00
                                                                              $border_value['color'] = "FF" . strtoupper($v);
                                                                          }
                                                          Severity: Major
                                                          Found in src/helpers/XLSXWriter.php and 1 other location - About 3 hrs to fix
                                                          src/helpers/XLSXWriter.php on lines 579..583

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

                                                          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