qcminecraft/Carbon-Forum-F

View on GitHub
library/PHPAnalysis.class.php

Summary

Maintainability
F
2 wks
Test Coverage

Function StartAnalysis has a Cognitive Complexity of 142 (exceeds 5 allowed). Consider refactoring.
Open

    public function StartAnalysis($optimize = true)
    {
        if (!$this->isLoadDic) {
            $this->LoadDict();
        }
Severity: Minor
Found in library/PHPAnalysis.class.php - About 2 days 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 _optimize_result has a Cognitive Complexity of 132 (exceeds 5 allowed). Consider refactoring.
Open

    private function _optimize_result(&$smarr, $spos)
    {
        $newarr = array();
        $prePos = $spos - 1;
        $arlen  = count($smarr);
Severity: Minor
Found in library/PHPAnalysis.class.php - About 2 days to fix

Cognitive Complexity

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

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

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

Further reading

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

<?php
/*
 * 居于Unicode编码词典的php分词器
 *  1、只适用于php5,必要函数 iconv
 *  2、本程序是使用RMM逆向匹配算法进行分词的,词库需要特别编译,本类里提供了 MakeDict() 方法
Severity: Major
Found in library/PHPAnalysis.class.php - About 1 day to fix

    Method StartAnalysis has 151 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function StartAnalysis($optimize = true)
        {
            if (!$this->isLoadDic) {
                $this->LoadDict();
            }
    Severity: Major
    Found in library/PHPAnalysis.class.php - About 6 hrs to fix

      Method _optimize_result has 149 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function _optimize_result(&$smarr, $spos)
          {
              $newarr = array();
              $prePos = $spos - 1;
              $arlen  = count($smarr);
      Severity: Major
      Found in library/PHPAnalysis.class.php - About 5 hrs to fix

        Function _deep_analysis has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
        Open

            private function _deep_analysis(&$str, $ctype, $spos, $optimize = true)
            {
                
                //中文句子
                if ($ctype == 1) {
        Severity: Minor
        Found in library/PHPAnalysis.class.php - About 5 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 _deep_analysis_cn has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
        Open

            private function _deep_analysis_cn(&$str, $lastec, $spos, $slen, $optimize = true)
            {
                $quote1 = chr(0x20) . chr(0x1C);
                $tmparr = array();
                $hasw   = 0;
        Severity: Minor
        Found in library/PHPAnalysis.class.php - About 4 hrs to fix

        Cognitive Complexity

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

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

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

        Further reading

        PhpAnalysis has 24 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class PhpAnalysis
        {
            
            //hash算法选项
            public $mask_value = 0x000F; //Default:0xFFFF
        Severity: Minor
        Found in library/PHPAnalysis.class.php - About 2 hrs to fix

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

              private function _sort_finally_result()
              {
                  $newarr = array();
                  $i      = 0;
                  foreach ($this->simpleResult as $k => $v) {
          Severity: Minor
          Found in library/PHPAnalysis.class.php - About 2 hrs to fix

          Cognitive Complexity

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

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

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

          Further reading

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

              private function _deep_analysis_cn(&$str, $lastec, $spos, $slen, $optimize = true)
              {
                  $quote1 = chr(0x20) . chr(0x1C);
                  $tmparr = array();
                  $hasw   = 0;
          Severity: Major
          Found in library/PHPAnalysis.class.php - About 2 hrs to fix

            Method MakeDict has 49 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function MakeDict($source_file, $target_file = '')
                {
                    $target_file = ($target_file == '' ? $this->mainDicFile : $target_file);
                    $allk        = array();
                    $fp          = fopen($source_file, 'r');
            Severity: Minor
            Found in library/PHPAnalysis.class.php - About 1 hr to fix

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

                  private function _deep_analysis(&$str, $ctype, $spos, $optimize = true)
                  {
                      
                      //中文句子
                      if ($ctype == 1) {
              Severity: Minor
              Found in library/PHPAnalysis.class.php - About 1 hr to fix

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

                    public function SetSource($source, $source_charset = 'utf-8', $target_charset = 'utf-8')
                    {
                        $this->sourceCharSet = strtolower($source_charset);
                        $this->targetCharSet = strtolower($target_charset);
                        $this->simpleResult  = array();
                Severity: Minor
                Found in library/PHPAnalysis.class.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 GetFinallyResult has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function GetFinallyResult($spword = ' ', $word_meanings = false)
                    {
                        $rsstr = '';
                        foreach ($this->finallyResult as $v) {
                            if ($this->resultType == 2 && ($v['t'] == 3 || $v['t'] == 5)) {
                Severity: Minor
                Found in library/PHPAnalysis.class.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 LoadDict has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function LoadDict($maindic = '')
                    {
                        $startt   = microtime(true);
                        //正常读取文件
                        $dicAddon = $this->addonDicFile;
                Severity: Minor
                Found in library/PHPAnalysis.class.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 GetFinallyKeywords has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function GetFinallyKeywords($num = 10)
                    {
                        $n     = 0;
                        $arr   = $this->GetFinallyIndex();
                        $okstr = '';
                Severity: Minor
                Found in library/PHPAnalysis.class.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 GetFinallyIndex has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function GetFinallyIndex()
                    {
                        $rearr = array();
                        foreach ($this->finallyResult as $v) {
                            if ($this->resultType == 2 && ($v['t'] == 3 || $v['t'] == 5)) {
                Severity: Minor
                Found in library/PHPAnalysis.class.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 (($cn > 0x3FFF && $cn < 0x9FA6) || ($cn > 0xF8FF && $cn < 0xFA2D) || ($cn > 0xABFF && $cn < 0xD7A4) || ($cn > 0x3040 && $cn < 0x312B)) {
                                    if ($lastc != 1 && $onstr != '') {
                                        $this->simpleResult[$s]['w'] = $onstr;
                                        if ($lastc == 2) {
                                            if (!preg_match('/' . $notNumberMatch . '/i', iconv(UCS2, 'utf-8', $onstr)))
                Severity: Critical
                Found in library/PHPAnalysis.class.php - About 1 hr to fix

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

                      public function MakeDict($source_file, $target_file = '')
                      {
                          $target_file = ($target_file == '' ? $this->mainDicFile : $target_file);
                          $allk        = array();
                          $fp          = fopen($source_file, 'r');
                  Severity: Minor
                  Found in library/PHPAnalysis.class.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 LoadDict has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function LoadDict($maindic = '')
                      {
                          $startt   = microtime(true);
                          //正常读取文件
                          $dicAddon = $this->addonDicFile;
                  Severity: Minor
                  Found in library/PHPAnalysis.class.php - About 1 hr to fix

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

                        public function ExportDict($targetfile)
                        {
                            if (!$this->mainDicHand) {
                                $this->mainDicHand = fopen($this->mainDicFile, 'r');
                            }
                    Severity: Minor
                    Found in library/PHPAnalysis.class.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 (strlen($cw) == 2 && strlen($nw) == 2 && !isset($this->addonDic['s'][$cw]) && !isset($this->addonDic['t'][$cw]) && !isset($this->addonDic['a'][$cw]) && !isset($this->addonDic['s'][$nw]) && !isset($this->addonDic['c'][$nw])) {
                                        $newarr[$j] = $cw . $nw;
                                        //尝试检测第三个词
                                        if (isset($smarr[$i + 2]) && strlen($smarr[$i + 2]) == 2 && (isset($this->addonDic['a'][$smarr[$i + 2]]) || isset($this->addonDic['u'][$smarr[$i + 2]]))) {
                                            $newarr[$j] .= $smarr[$i + 2];
                    Severity: Major
                    Found in library/PHPAnalysis.class.php - About 1 hr to fix

                      Function _source_result_charset has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                          private function _source_result_charset()
                          {
                              if (preg_match("/^utf/", $this->targetCharSet)) {
                                  $rs = 1;
                              } else if (preg_match("/^gb/", $this->targetCharSet)) {
                      Severity: Minor
                      Found in library/PHPAnalysis.class.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

                      Avoid deeply nested control flow statements.
                      Open

                                              if ($this->IsWord($nfont . $nhead)) {
                                                  if (strlen($cw) > 2)
                                                      $j++;
                                                  $hasDiff    = true;
                                                  $newarr[$j] = $nfont . $nhead;
                      Severity: Major
                      Found in library/PHPAnalysis.class.php - About 45 mins to fix

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

                            private function _deep_analysis_cn(&$str, $lastec, $spos, $slen, $optimize = true)
                        Severity: Minor
                        Found in library/PHPAnalysis.class.php - About 35 mins to fix

                          Function GetWordInfos has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                              public function GetWordInfos($key, $type = 'word')
                              {
                                  if (!$this->mainDicHand) {
                                      $this->mainDicHand = fopen($this->mainDicFile, 'r');
                                  }
                          Severity: Minor
                          Found in library/PHPAnalysis.class.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 GetSimpleResult has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                              public function GetSimpleResult()
                              {
                                  $rearr = array();
                                  foreach ($this->simpleResult as $k => $v) {
                                      if (empty($v['w']))
                          Severity: Minor
                          Found in library/PHPAnalysis.class.php - About 25 mins to fix

                          Cognitive Complexity

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

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

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

                          Further reading

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

                                              if ($onstr != '') {
                                                  $this->simpleResult[$s]['w'] = $onstr;
                                                  if ($lastc == 2) {
                                                      if (!preg_match('/' . $notNumberMatch . '/i', iconv(UCS2, 'utf-8', $onstr)))
                                                          $lastc = 4;
                          Severity: Major
                          Found in library/PHPAnalysis.class.php and 1 other location - About 2 hrs to fix
                          library/PHPAnalysis.class.php on lines 335..345

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

                          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 ($onstr != '') {
                                                  $this->simpleResult[$s]['w'] = $onstr;
                                                  if ($lastc == 2) {
                                                      if (!preg_match('/' . $notNumberMatch . '/i', iconv(UCS2, 'utf-8', $onstr)))
                                                          $lastc = 4;
                          Severity: Major
                          Found in library/PHPAnalysis.class.php and 1 other location - About 2 hrs to fix
                          library/PHPAnalysis.class.php on lines 378..388

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

                          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