chippyash/Matrix

View on GitHub

Showing 64 of 64 total issues

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

<?php
/*
 * Matrix library
 *
 * @author Ashley Kitson <akitson@zf4.biz>
Severity: Major
Found in src/Chippyash/Matrix/Transformation/Colreduce.php and 1 other location - About 1 day to fix
src/Chippyash/Matrix/Transformation/Colslice.php on lines 1..62

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

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
/*
 * Matrix library
 *
 * @author Ashley Kitson <akitson@zf4.biz>
Severity: Major
Found in src/Chippyash/Matrix/Transformation/Colslice.php and 1 other location - About 1 day to fix
src/Chippyash/Matrix/Transformation/Colreduce.php on lines 1..62

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

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

    protected function reflect(Matrix $mA, array $reflectionMatrix)
    {
        $a = $reflectionMatrix[0][0];
        $b = $reflectionMatrix[0][1];
        $c = $reflectionMatrix[1][0];
Severity: Major
Found in src/Chippyash/Matrix/Transformation/Reflect.php and 1 other location - About 5 hrs to fix
src/Chippyash/Matrix/Transformation/Rotate.php on lines 87..101

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

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

    protected function rotate(Matrix $mA, array $rotationMatrix)
    {
        $a = $rotationMatrix[0][0];
        $b = $rotationMatrix[0][1];
        $c = $rotationMatrix[1][0];
Severity: Major
Found in src/Chippyash/Matrix/Transformation/Rotate.php and 1 other location - About 5 hrs to fix
src/Chippyash/Matrix/Transformation/Reflect.php on lines 92..106

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

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

The class Matrix has an overall complexity of 57 which is very high. The configured complexity threshold is 50.
Open

class Matrix implements InvokableInterface
{
    /**
     * Namespaces for this library
     */
Severity: Minor
Found in src/Chippyash/Matrix/Matrix.php by phpmd

Function set has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

    public function set($row, $col, $data)
    {
        if ($row < 0 || $row > $this->rows()) {
            throw new VerticeOutOfBoundsException('row', $row);
        }
Severity: Minor
Found in src/Chippyash/Matrix/Traits/Mutability.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

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

    public function is(Matrix $mA)
    {
        if (!$mA->is('square')) {
            return false;
        }
Severity: Minor
Found in src/Chippyash/Matrix/Attribute/IsDiagonal.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

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

    protected function checkEntryEquality(Matrix $mB, $strict)
    {
        $dA = $this->toArray();
        $dB = $mB->toArray();
        $m = $this->rows();
Severity: Minor
Found in src/Chippyash/Matrix/Matrix.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 set has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function set($row, $col, $data)
    {
        if ($row < 0 || $row > $this->rows()) {
            throw new VerticeOutOfBoundsException('row', $row);
        }
Severity: Minor
Found in src/Chippyash/Matrix/Traits/Mutability.php - About 1 hr to fix

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

        protected function doTransform(Matrix $mA, $extra = null)
        {
            /** @noinspection PhpInternalEntityUsedInspection */
            $this->assertParameterIsArray($extra, 'Second operand is not an array');
    
    
    Severity: Minor
    Found in src/Chippyash/Matrix/Transformation/Resize.php - About 1 hr to fix

      Method is has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function is(Matrix $mA)
          {
              //empty matrix is ok
              if ($mA->is('empty')) {
                  return true;
      Severity: Minor
      Found in src/Chippyash/Matrix/Attribute/IsComplete.php - About 1 hr to fix

        Method doTransform has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function doTransform(Matrix $mA, $extra = null)
            {
                $this->assertMatrixIsComplete($mA);
        
                if ($mA->is('empty')) {
        Severity: Minor
        Found in src/Chippyash/Matrix/Transformation/Shift.php - About 1 hr to fix

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

              protected function doTransform(Matrix $mA, $extra = null)
              {
                  /** @noinspection PhpInternalEntityUsedInspection */
                  $this->assertParameterIsArray($extra, 'Second operand is not an array');
          
          
          Severity: Minor
          Found in src/Chippyash/Matrix/Transformation/Resize.php - About 55 mins to fix

          Cognitive Complexity

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

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

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

          Further reading

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

              public function __construct($source, $complete = false, $normalize= false, $normalizeDefault = null)
              {
                  if ($source instanceof Matrix) {
                      $this->store($source->toArray());
                      return;
          Severity: Minor
          Found in src/Chippyash/Matrix/Matrix.php - About 55 mins to fix

          Cognitive Complexity

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

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

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

          Further reading

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

              protected function doTransform(Matrix $mA, $extra = null)
              {
                  $this->assertMatrixIsComplete($mA);
          
                  if ($mA->is('empty')) {
          Severity: Minor
          Found in src/Chippyash/Matrix/Transformation/Transpose.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

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

              public function get($row, $col)
              {
                  if ($row < 0 || $row > $this->rows()) {
                      throw new VerticeOutOfBoundsException('row', $row);
                  }
          Severity: Minor
          Found in src/Chippyash/Matrix/Matrix.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

          The class Matrix has a coupling between objects value of 13. Consider to reduce the number of dependencies under 13.
          Open

          class Matrix implements InvokableInterface
          {
              /**
               * Namespaces for this library
               */
          Severity: Minor
          Found in src/Chippyash/Matrix/Matrix.php by phpmd

          CouplingBetweenObjects

          Since: 1.1.0

          A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

          Example

          class Foo {
              /**
               * @var \foo\bar\X
               */
              private $x = null;
          
              /**
               * @var \foo\bar\Y
               */
              private $y = null;
          
              /**
               * @var \foo\bar\Z
               */
              private $z = null;
          
              public function setFoo(\Foo $foo) {}
              public function setBar(\Bar $bar) {}
              public function setBaz(\Baz $baz) {}
          
              /**
               * @return \SplObjectStorage
               * @throws \OutOfRangeException
               * @throws \InvalidArgumentException
               * @throws \ErrorException
               */
              public function process(\Iterator $it) {}
          
              // ...
          }

          Source https://phpmd.org/rules/design.html#couplingbetweenobjects

          Avoid too many return statements within this method.
          Open

                      return $this->reduceRows($mA, abs($numRows));
          Severity: Major
          Found in src/Chippyash/Matrix/Transformation/Resize.php - About 30 mins to fix

            Missing class import via use statement (line '326', column '23').
            Open

                        throw new \InvalidArgumentException(self::ERR_INVALID_INVOKE_ARG);
            Severity: Minor
            Found in src/Chippyash/Matrix/Matrix.php by phpmd

            MissingImport

            Since: 2.7.0

            Importing all external classes in a file through use statements makes them clearly visible.

            Example

            function make() {
                return new \stdClass();
            }

            Source http://phpmd.org/rules/cleancode.html#MissingImport

            The method setDebug has a boolean flag argument $flag, which is a certain sign of a Single Responsibility Principle violation.
            Open

                public function setDebug($flag = true)
            Severity: Minor
            Found in src/Chippyash/Matrix/Traits/Debug.php by phpmd

            BooleanArgumentFlag

            Since: 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example

            class Foo {
                public function bar($flag = true) {
                }
            }

            Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

            Severity
            Category
            Status
            Source
            Language