mossadal/math-parser

View on GitHub
src/MathParser/Extensions/Complex.php

Summary

Maintainability
D
3 days
Test Coverage

Complex has 36 functions (exceeds 20 allowed). Consider refactoring.
Open

class Complex
{
    /**
     * float $x real part
     */
Severity: Minor
Found in src/MathParser/Extensions/Complex.php - About 4 hrs to fix

    Function parse has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function parse($value)
        {
            if ($value instanceof Complex) return $value;
            if ($value instanceof Rational) return new Complex($value.p/$value.q, 0);
    
    
    Severity: Minor
    Found in src/MathParser/Extensions/Complex.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

    File Complex.php has 271 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    /*
     * @package     Complex
     * @author      Frank Wikström <frank@mossadal.se>
     * @copyright   2016 Frank Wikström
    Severity: Minor
    Found in src/MathParser/Extensions/Complex.php - About 2 hrs to fix

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

          public static function parse($value)
          {
              if ($value instanceof Complex) return $value;
              if ($value instanceof Rational) return new Complex($value.p/$value.q, 0);
      
      
      Severity: Major
      Found in src/MathParser/Extensions/Complex.php - About 2 hrs 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

        Avoid too many return statements within this method.
        Open

                return $z;
        Severity: Major
        Found in src/MathParser/Extensions/Complex.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                  return "$real${imag}i";
          Severity: Major
          Found in src/MathParser/Extensions/Complex.php - About 30 mins to fix

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

                private static function powi($z, $n) {
                    if ($n < 0) return static::div(1,static::powi($z, -$n));
            
                    if ($n == 0) return new Complex(1,0);
            
            
            Severity: Minor
            Found in src/MathParser/Extensions/Complex.php - About 25 mins to fix

            Cognitive Complexity

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

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

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

            Further reading

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

                public static function tanh($z) {
                    if (!($z instanceof Complex)) $z = static::parse($z);
            
                    $d = sinh($z->x)*sinh($z->x) + cos($z->y)*cos($z->y);
                    return static::create(sinh($z->x)*cosh($z->x)/$d, sin($z->y)*cos($z->y)/$d);
            Severity: Major
            Found in src/MathParser/Extensions/Complex.php and 1 other location - About 3 hrs to fix
            src/MathParser/Extensions/Complex.php on lines 417..422

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

            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

                public static function tan($z) {
                    if (!($z instanceof Complex)) $z = static::parse($z);
            
                    $d = cos($z->x)*cos($z->x) + sinh($z->y)*sinh($z->y);
                    return static::create(sin($z->x)*cos($z->x)/$d, sinh($z->y)*cosh($z->y)/$d);
            Severity: Major
            Found in src/MathParser/Extensions/Complex.php and 1 other location - About 3 hrs to fix
            src/MathParser/Extensions/Complex.php on lines 583..588

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

            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 3 locations. Consider refactoring.
            Open

                 public static function sinh($z) {
                    if (!($z instanceof Complex)) $z = static::parse($z);
            
                    return static::create(sinh($z->x)*cos($z->y), cosh($z->x)*sin($z->y));
                }
            Severity: Minor
            Found in src/MathParser/Extensions/Complex.php and 2 other locations - About 30 mins to fix
            src/MathParser/Extensions/Complex.php on lines 387..391
            src/MathParser/Extensions/Complex.php on lines 568..572

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

            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 3 locations. Consider refactoring.
            Open

                public static function cosh($z) {
                    if (!($z instanceof Complex)) $z = static::parse($z);
            
                    return static::create(cosh($z->x)*cos($z->y), sinh($z->x)*sin($z->y));
                }
            Severity: Minor
            Found in src/MathParser/Extensions/Complex.php and 2 other locations - About 30 mins to fix
            src/MathParser/Extensions/Complex.php on lines 387..391
            src/MathParser/Extensions/Complex.php on lines 553..557

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

            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 3 locations. Consider refactoring.
            Open

                public static function sin($z) {
                    if (!($z instanceof Complex)) $z = static::parse($z);
            
                    return static::create(sin($z->x)*cosh($z->y), cos($z->x)*sinh($z->y));
                }
            Severity: Minor
            Found in src/MathParser/Extensions/Complex.php and 2 other locations - About 30 mins to fix
            src/MathParser/Extensions/Complex.php on lines 553..557
            src/MathParser/Extensions/Complex.php on lines 568..572

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

            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