mossadal/math-parser

View on GitHub

Showing 188 of 188 total issues

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

    public function visitFunctionNode(FunctionNode $node)
    {
        $inner = $node->getOperand()->accept($this);

        switch ($node->getName()) {
Severity: Minor
Found in src/MathParser/Interpreting/RationalEvaluator.php - About 1 hr to fix

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

        public function __toString()
        {
            // TODO: use Number:: helper functions.
    
            $realAsRational = Rational::fromFloat($this->x);
    Severity: Minor
    Found in src/MathParser/Extensions/Complex.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 handleExpression has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function handleExpression($node)
        {
            if ($node instanceof FunctionNode) throw new ParenthesisMismatchException($node->getOperator());
            if ($node instanceof SubExpressionNode) throw new ParenthesisMismatchException($node->getOperator());
    
    
    Severity: Minor
    Found in src/MathParser/Parsing/Parser.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 __construct has 40 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function __construct()
        {
            $this->add(new TokenDefinition('/\d+[,\.]\d+/', TokenType::RealNumber));
            $this->add(new TokenDefinition('/\d+/', TokenType::PosInt));
    
    
    Severity: Minor
    Found in src/MathParser/Lexing/ComplexLexer.php - About 1 hr to fix

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

          private function numericFactors($leftOperand, $rightOperand)
          {
              if ($this->isNumeric($rightOperand)) {
                  if ($rightOperand->getValue() == 0) return new IntegerNode(0);
                  if ($rightOperand->getValue() == 1) return $leftOperand;

      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 visitExpressionNode has 39 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function visitExpressionNode(ExpressionNode $node)
          {
      
              $operator = $node->getOperator();
              $left = $node->getLeft();
      Severity: Minor
      Found in src/MathParser/Interpreting/LaTeXPrinter.php - About 1 hr to fix

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

            public function visitFunctionNode(FunctionNode $node)
            {
                $inner = $node->getOperand()->accept($this);
                $arg = $node->getOperand();
        
        
        Severity: Minor
        Found in src/MathParser/Interpreting/Differentiator.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 ifactor has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function ifactor($n)
            {
        
                // max_n = 2^31-1 = 2147483647
                $d = 2;
        Severity: Minor
        Found in src/MathParser/Interpreting/RationalEvaluator.php - About 1 hr to fix

          Method visitExpressionNode has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function visitExpressionNode(ExpressionNode $node)
              {
                  $operator = $node->getOperator();
          
                  $a = $node->getLeft()->accept($this);
          Severity: Minor
          Found in src/MathParser/Interpreting/RationalEvaluator.php - About 1 hr to fix

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

                public function visitFunctionNode(FunctionNode $node)
                {
                    $functionName = $node->getName();
            
                    $operand = $node->getOperand()->accept($this);
            Severity: Minor
            Found in src/MathParser/Interpreting/LaTeXPrinter.php - About 1 hr to fix

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

              <?php 
              
              namespace MathParser;
              
              /*
              Severity: Major
              Found in src/MathParser/ComplexMathParser.php and 1 other location - About 1 hr to fix
              src/MathParser/RationalMathParser.php on lines 1..61

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

              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

              <?php 
              
              namespace MathParser;
              
              use MathParser\Lexing\StdMathLexer;
              Severity: Major
              Found in src/MathParser/RationalMathParser.php and 1 other location - About 1 hr to fix
              src/MathParser/ComplexMathParser.php on lines 1..43

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

              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

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

                  private function numericExponent($leftOperand, $rightOperand)
                  {
                      // 0^0 throws an exception
                      if ($this->isNumeric($leftOperand) && $this->isNumeric($rightOperand)) {
                          if ($leftOperand->getValue() == 0 && $rightOperand->getValue() == 0)

              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 __construct has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  function __construct($left, $operator = null, $right = null)
                  {
                      $this->left = $this->sanitize($left);
                      $this->operator = $operator;
                      $this->right = $this->sanitize($right);
              Severity: Minor
              Found in src/MathParser/Parsing/Nodes/ExpressionNode.php - About 1 hr to fix

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

                    public static function fromFloat($float, $tolerance=1e-7)
                    {
                        if (is_string($float) && preg_match('~^\-?\d+([,|.]\d+)?$~', $float)) {
                            $float = floatval(str_replace(',','.',$float));
                        }
                Severity: Minor
                Found in src/MathParser/Extensions/Rational.php - About 1 hr to fix

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

                      public function parenthesize(Node $node, ExpressionNode $cutoff, $prepend = '', $conservative = false)
                      {
                          $text = $node->accept($this);
                  
                          if ($node instanceof ExpressionNode) {
                  Severity: Minor
                  Found in src/MathParser/Interpreting/ASCIIPrinter.php - About 1 hr to fix

                    Method rpow has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        private function rpow($a, $b)
                        {
                            if ($b->getDenominator() == 1) {
                                $n = $b->getNumerator();
                                if ($n >= 0) {
                    Severity: Minor
                    Found in src/MathParser/Interpreting/RationalEvaluator.php - About 1 hr to fix

                      Method handleExpression has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          protected function handleExpression($node)
                          {
                              if ($node instanceof FunctionNode) throw new ParenthesisMismatchException($node->getOperator());
                              if ($node instanceof SubExpressionNode) throw new ParenthesisMismatchException($node->getOperator());
                      
                      
                      Severity: Minor
                      Found in src/MathParser/Parsing/Parser.php - About 1 hr to fix

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

                            public function visitExpressionNode(ExpressionNode $node)
                            {
                                $operator = $node->getOperator();
                        
                                $leftValue = $node->getLeft()->accept($this);
                        Severity: Minor
                        Found in src/MathParser/Interpreting/Evaluator.php - About 1 hr to fix

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

                              public function visitExpressionNode(ExpressionNode $node)
                              {
                                  $operator = $node->getOperator();
                                  $left = $node->getLeft();
                                  $right = $node->getRight();
                          Severity: Minor
                          Found in src/MathParser/Interpreting/ASCIIPrinter.php - About 1 hr to fix
                            Severity
                            Category
                            Status
                            Source
                            Language