jaroslavtyc/drd-plus-stamina

View on GitHub
tests/Stamina/StaminaTest.php

Summary

Maintainability
F
4 days
Test Coverage

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

      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

        Avoid using static access to class '\DrdPlus\Stamina\ReasonToRollAgainstMalusFromFatigue' in method 'I_should_roll_against_malus_from_fatigue_because_of_new_fatigue'.
        Open

                self::assertSame(ReasonToRollAgainstMalusFromFatigue::getFatigueReason(), $stamina->getReasonToRollAgainstMalusFromFatigue());
        Severity: Minor
        Found in tests/Stamina/StaminaTest.php by phpmd

        StaticAccess

        Since: 1.4.0

        Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

        Example

        class Foo
        {
            public function bar()
            {
                Bar::baz();
            }
        }

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

        Avoid using static access to class '\DrdPlus\Stamina\ReasonToRollAgainstMalusFromFatigue' in method 'I_should_roll_against_malus_from_fatigue_because_of_rest'.
        Open

                self::assertSame(ReasonToRollAgainstMalusFromFatigue::getRestReason(), $stamina->getReasonToRollAgainstMalusFromFatigue());
        Severity: Minor
        Found in tests/Stamina/StaminaTest.php by phpmd

        StaticAccess

        Since: 1.4.0

        Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

        Example

        class Foo
        {
            public function bar()
            {
                Bar::baz();
            }
        }

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

        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

        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

        The method I_should_roll_against_malus_from_fatigue_because_of_new_fatigue is not named in camelCase.
        Open

            public function I_should_roll_against_malus_from_fatigue_because_of_new_fatigue(int $willValue, int $rollValue, int $expectedMalus): void
            {
                $fatigueBoundary = $this->createFatigueBoundary(10);
                $stamina = $this->createStaminaToTest($fatigueBoundary);
                $stamina->addFatigue($this->createFatigue(10), $fatigueBoundary);
        Severity: Minor
        Found in tests/Stamina/StaminaTest.php by phpmd

        CamelCaseMethodName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name methods.

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method I_can_rest is not named in camelCase.
        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 by phpmd

        CamelCaseMethodName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name methods.

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method I_can_be_exhausted_out_of_imagination is not named in camelCase.
        Open

            public function I_can_be_exhausted_out_of_imagination(): void
            {
                $fatigueBoundary = $this->createFatigueBoundary(5);
                $stamina = $this->createStaminaToTest($fatigueBoundary);
                $stamina->addFatigue($this->createFatigue(999), $fatigueBoundary);
        Severity: Minor
        Found in tests/Stamina/StaminaTest.php by phpmd

        CamelCaseMethodName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name methods.

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method I_can_not_rest_if_roll_on_malus_expected is not named in camelCase.
        Open

            public function I_can_not_rest_if_roll_on_malus_expected(): void
            {
                $fatigueBoundary = $this->createFatigueBoundary(10);
                $stamina = $this->createStaminaToTest($fatigueBoundary);
                $stamina->addFatigue($this->createFatigue(4), $fatigueBoundary);
        Severity: Minor
        Found in tests/Stamina/StaminaTest.php by phpmd

        CamelCaseMethodName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name methods.

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method I_should_roll_against_malus_from_fatigue_because_of_rest is not named in camelCase.
        Open

            public function I_should_roll_against_malus_from_fatigue_because_of_rest(int $willValue, int $rollValue, int $expectedMalus): void
            {
                $fatigueBoundary = $this->createFatigueBoundary(10);
                $stamina = $this->createStaminaToTest($fatigueBoundary);
                $stamina->addFatigue($this->createFatigue(4), $fatigueBoundary);
        Severity: Minor
        Found in tests/Stamina/StaminaTest.php by phpmd

        CamelCaseMethodName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name methods.

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method Malus_can_not_decrease_on_new_fatigue is not named in camelCase.
        Open

            public function Malus_can_not_decrease_on_new_fatigue(int $willValue, int $rollValue, int $expectedMalus): void
            {
                $fatigueBoundary = $this->createFatigueBoundary(5);
                $stamina = $this->createStaminaToTest($fatigueBoundary);
        
        
        Severity: Minor
        Found in tests/Stamina/StaminaTest.php by phpmd

        CamelCaseMethodName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name methods.

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method I_can_easily_find_out_if_creature_is_conscious_and_alive is not named in camelCase.
        Open

            public function I_can_easily_find_out_if_creature_is_conscious_and_alive(int $fatigueBoundaryValue, int $fatigueValue, bool $isConscious, bool $isAlive): void
            {
                $fatigueBoundary = $this->createFatigueBoundary($fatigueBoundaryValue);
                $stamina = $this->createStaminaToTest($fatigueBoundary);
                $stamina->addFatigue($this->createFatigue($fatigueValue), $fatigueBoundary);
        Severity: Minor
        Found in tests/Stamina/StaminaTest.php by phpmd

        CamelCaseMethodName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name methods.

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method I_can_use_it is not named in camelCase.
        Open

            public function I_can_use_it(): void
            {
                $fatigueBoundary = $this->createFatigueBoundary(123);
                $stamina = $this->createStaminaToTest($fatigueBoundary);
        
        
        Severity: Minor
        Found in tests/Stamina/StaminaTest.php by phpmd

        CamelCaseMethodName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name methods.

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method I_can_not_roll_on_malus_from_fatigue_if_not_needed is not named in camelCase.
        Open

            public function I_can_not_roll_on_malus_from_fatigue_if_not_needed(): void
            {
                $fatigueBoundary = $this->createFatigueBoundary(10);
                $stamina = $this->createStaminaToTest($fatigueBoundary);
                $this->expectException(\DrdPlus\Stamina\Exceptions\UselessRollAgainstMalus::class);
        Severity: Minor
        Found in tests/Stamina/StaminaTest.php by phpmd

        CamelCaseMethodName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name methods.

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method I_can_not_get_malus_from_fatigue_if_roll_on_it_expected is not named in camelCase.
        Open

            public function I_can_not_get_malus_from_fatigue_if_roll_on_it_expected(): void
            {
                $fatigueBoundary = $this->createFatigueBoundary(10);
                $stamina = $this->createStaminaToTest($fatigueBoundary);
                $stamina->addFatigue($this->createFatigue(14), $fatigueBoundary);
        Severity: Minor
        Found in tests/Stamina/StaminaTest.php by phpmd

        CamelCaseMethodName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name methods.

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method I_can_ask_it_if_I_am_suffering_from_fatigue is not named in camelCase.
        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: Minor
        Found in tests/Stamina/StaminaTest.php by phpmd

        CamelCaseMethodName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name methods.

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method Malus_can_increase_on_new_fatigue is not named in camelCase.
        Open

            public function Malus_can_increase_on_new_fatigue(int $willValue, int $rollValue, int $expectedMalus): void
            {
                $fatigueBoundary = $this->createFatigueBoundary(5);
                $stamina = $this->createStaminaToTest($fatigueBoundary);
        
        
        Severity: Minor
        Found in tests/Stamina/StaminaTest.php by phpmd

        CamelCaseMethodName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name methods.

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method Malus_is_not_increased_on_new_rest_by_worse_roll is not named in camelCase.
        Open

            public function Malus_is_not_increased_on_new_rest_by_worse_roll(): void
            {
                $fatigueBoundary = $this->createFatigueBoundary(5);
                $stamina = $this->createStaminaToTest($fatigueBoundary);
                self::assertSame(0, $stamina->getMalusFromFatigue($fatigueBoundary)->getValue());
        Severity: Minor
        Found in tests/Stamina/StaminaTest.php by phpmd

        CamelCaseMethodName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name methods.

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method I_can_ask_it_if_may_suffer_from_fatigue is not named in camelCase.
        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: Minor
        Found in tests/Stamina/StaminaTest.php by phpmd

        CamelCaseMethodName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name methods.

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method I_can_not_add_new_fatigue_if_roll_on_malus_expected is not named in camelCase.
        Open

            public function I_can_not_add_new_fatigue_if_roll_on_malus_expected(): void
            {
                $fatigueBoundary = $this->createFatigueBoundary(10);
                $stamina = $this->createStaminaToTest($fatigueBoundary);
                $stamina->addFatigue($this->createFatigue(10), $fatigueBoundary);
        Severity: Minor
        Found in tests/Stamina/StaminaTest.php by phpmd

        CamelCaseMethodName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name methods.

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method I_can_be_fatigued is not named in camelCase.
        Open

            public function I_can_be_fatigued(): void
            {
                $fatigueBoundary = $this->createFatigueBoundary(5);
                $stamina = $this->createStaminaToTest($fatigueBoundary);
        
        
        Severity: Minor
        Found in tests/Stamina/StaminaTest.php by phpmd

        CamelCaseMethodName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name methods.

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method I_can_rest_so_little_so_nothing_changes is not named in camelCase.
        Open

            public function I_can_rest_so_little_so_nothing_changes(): void
            {
                $fatigueBoundary = $this->createFatigueBoundary(4);
                $stamina = $this->createStaminaToTest($fatigueBoundary);
        
        
        Severity: Minor
        Found in tests/Stamina/StaminaTest.php by phpmd

        CamelCaseMethodName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name methods.

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        There are no issues that match your filters.

        Category
        Status