jaroslavtyc/drd-plus-stamina

View on GitHub

Showing 88 of 88 total issues

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

    public function I_can_ask_it_if_may_suffer_from_fatigue(): void
    {
        $fatigueBoundary = $this->createFatigueBoundary(5);
        $stamina = $this->createStaminaToTest($fatigueBoundary);
        self::assertFalse($stamina->maySufferFromFatigue($fatigueBoundary));
Severity: Major
Found in tests/Stamina/StaminaTest.php and 1 other location - About 1 day to fix
tests/Stamina/StaminaTest.php on lines 576..603

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

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 function I_can_ask_it_if_I_am_suffering_from_fatigue(): void
    {
        $fatigueBoundary = $this->createFatigueBoundary(5);
        $stamina = $this->createStaminaToTest($fatigueBoundary);
        self::assertFalse($stamina->mayHaveMalusFromFatigue($fatigueBoundary));
Severity: Major
Found in tests/Stamina/StaminaTest.php and 1 other location - About 1 day to fix
tests/Stamina/StaminaTest.php on lines 544..571

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

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

File StaminaTest.php has 437 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php declare(strict_types=1);

namespace DrdPlus\Tests\Stamina;

use DrdPlus\Properties\Derived\Endurance;
Severity: Minor
Found in tests/Stamina/StaminaTest.php - About 6 hrs to fix

    StaminaTest has 30 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class StaminaTest extends TestWithMockery
    {
        /**
         * @test
         */
    Severity: Minor
    Found in tests/Stamina/StaminaTest.php - About 3 hrs to fix

      The class StaminaTest has 30 non-getter- and setter-methods. Consider refactoring StaminaTest to keep number of methods under 25.
      Open

      class StaminaTest extends TestWithMockery
      {
          /**
           * @test
           */
      Severity: Minor
      Found in tests/Stamina/StaminaTest.php by phpmd

      TooManyMethods

      Since: 0.1

      A class with too many methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

      By default it ignores methods starting with 'get' or 'set'.

      The default was changed from 10 to 25 in PHPMD 2.3.

      Example

      Source https://phpmd.org/rules/codesize.html#toomanymethods

      The class StaminaTest has 21 public methods. Consider refactoring StaminaTest to keep number of public methods under 10.
      Open

      class StaminaTest extends TestWithMockery
      {
          /**
           * @test
           */
      Severity: Minor
      Found in tests/Stamina/StaminaTest.php by phpmd

      TooManyPublicMethods

      Since: 0.1

      A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

      By default it ignores methods starting with 'get' or 'set'.

      Example

      Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

      Stamina has 22 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class Stamina extends StrictObject
      {
          /**
           * @var Fatigue
           */
      Severity: Minor
      Found in Stamina/Stamina.php - About 2 hrs to fix

        Avoid excessively long variable names like $currentlyExpectedMalus. Keep variable name length under 20.
        Open

                    $currentlyExpectedMalus = max(0, min(3, (int)floor(($currentWillValue + $currentRollValue) / 5))) - 3; // 0; -1; -2; -3
        Severity: Minor
        Found in tests/Stamina/StaminaTest.php by phpmd

        LongVariable

        Since: 0.2

        Detects when a field, formal or local variable is declared with a long name.

        Example

        class Something {
            protected $reallyLongIntName = -3; // VIOLATION - Field
            public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                $otherReallyLongName = -5; // VIOLATION - Local
                for ($interestingIntIndex = 0; // VIOLATION - For
                     $interestingIntIndex < 10;
                     $interestingIntIndex++ ) {
                }
            }
        }

        Source https://phpmd.org/rules/naming.html#longvariable

        Avoid excessively long variable names like $rollOnWillAgainstMalus. Keep variable name length under 20.
        Open

            private function setMalusFromFatigue(RollOnWillAgainstMalus $rollOnWillAgainstMalus): MalusFromFatigue
        Severity: Minor
        Found in Stamina/Stamina.php by phpmd

        LongVariable

        Since: 0.2

        Detects when a field, formal or local variable is declared with a long name.

        Example

        class Something {
            protected $reallyLongIntName = -3; // VIOLATION - Field
            public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                $otherReallyLongName = -5; // VIOLATION - Local
                for ($interestingIntIndex = 0; // VIOLATION - For
                     $interestingIntIndex < 10;
                     $interestingIntIndex++ ) {
                }
            }
        }

        Source https://phpmd.org/rules/naming.html#longvariable

        Avoid excessively long variable names like $gridOfFatigueWithoutFatigueAtAll. Keep variable name length under 20.
        Open

                $gridOfFatigueWithoutFatigueAtAll = new GridOfFatigue($this->createStamina(0 /* no fatigue */));
        Severity: Minor
        Found in tests/Stamina/GridOfFatigueTest.php by phpmd

        LongVariable

        Since: 0.2

        Detects when a field, formal or local variable is declared with a long name.

        Example

        class Something {
            protected $reallyLongIntName = -3; // VIOLATION - Field
            public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                $otherReallyLongName = -5; // VIOLATION - Local
                for ($interestingIntIndex = 0; // VIOLATION - For
                     $interestingIntIndex < 10;
                     $interestingIntIndex++ ) {
                }
            }
        }

        Source https://phpmd.org/rules/naming.html#longvariable

        Avoid excessively long variable names like $reasonToRollAgainstMalusFromFatigue. Keep variable name length under 20.
        Open

            private $reasonToRollAgainstMalusFromFatigue;
        Severity: Minor
        Found in Stamina/Stamina.php by phpmd

        LongVariable

        Since: 0.2

        Detects when a field, formal or local variable is declared with a long name.

        Example

        class Something {
            protected $reallyLongIntName = -3; // VIOLATION - Field
            public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                $otherReallyLongName = -5; // VIOLATION - Local
                for ($interestingIntIndex = 0; // VIOLATION - For
                     $interestingIntIndex < 10;
                     $interestingIntIndex++ ) {
                }
            }
        }

        Source https://phpmd.org/rules/naming.html#longvariable

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

            public function I_can_use_fatigue_reason(): void
            {
                $fatigueReason = ReasonToRollAgainstMalusFromFatigue::getFatigueReason();
                self::assertInstanceOf(ReasonToRollAgainstMalusFromFatigue::class, $fatigueReason);
                self::assertTrue($fatigueReason->becauseOfFatigue());
        Severity: Major
        Found in tests/Stamina/ReasonToRollAgainstMalusFromFatigueTest.php and 1 other location - About 1 hr to fix
        tests/Stamina/ReasonToRollAgainstMalusFromFatigueTest.php on lines 24..33

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

        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 function I_can_use_rest_reason(): void
            {
                $restReason = ReasonToRollAgainstMalusFromFatigue::getRestReason();
                self::assertInstanceOf(ReasonToRollAgainstMalusFromFatigue::class, $restReason);
                self::assertTrue($restReason->becauseOfRest());
        Severity: Major
        Found in tests/Stamina/ReasonToRollAgainstMalusFromFatigueTest.php and 1 other location - About 1 hr to fix
        tests/Stamina/ReasonToRollAgainstMalusFromFatigueTest.php on lines 13..22

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

        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 calculateFilledHalfRowsFor has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            public function calculateFilledHalfRowsFor($fatigueValue, FatigueBoundary $fatigueBoundary): int
            {
                $fatiguePerRowMaximum = $this->getFatiguePerRowMaximum($fatigueBoundary);
                if ($fatiguePerRowMaximum % 2 === 0) { // odd
                    $filledHalfRows = SumAndRound::floor($fatigueValue / ($fatiguePerRowMaximum / 2));
        Severity: Minor
        Found in Stamina/GridOfFatigue.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 createActivity has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function createActivity(string $usedProperty)
            {
                $activity = $this->mockery(PropertyBasedActivity::class);
                $activity->shouldReceive('usesStrength')
                    ->zeroOrMoreTimes()
        Severity: Minor
        Found in tests/Stamina/MalusFromFatigueTest.php - About 1 hr to fix

          Method I_can_rest has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function I_can_rest(): void
              {
                  $fatigueBoundary = $this->createFatigueBoundary(7);
                  $stamina = $this->createStaminaToTest($fatigueBoundary);
                  self::assertSame(21, $stamina->getRemainingStaminaAmount($fatigueBoundary));
          Severity: Minor
          Found in tests/Stamina/StaminaTest.php - About 1 hr to fix

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

            class StaminaTest extends TestWithMockery
            {
                /**
                 * @test
                 */
            Severity: Minor
            Found in tests/Stamina/StaminaTest.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

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

            class Stamina extends StrictObject
            {
                /**
                 * @var Fatigue
                 */
            Severity: Minor
            Found in Stamina/Stamina.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 $activity;
            Severity: Major
            Found in tests/Stamina/MalusFromFatigueTest.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                              return PropertyCode::CHARISMA === $usedProperty;
              Severity: Major
              Found in tests/Stamina/MalusFromFatigueTest.php - About 30 mins to fix
                Severity
                Category
                Status
                Source
                Language