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;
StaminaTest
has 30 functions (exceeds 20 allowed). Consider refactoring. Open
class StaminaTest extends TestWithMockery
{
/**
* @test
*/
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
*/
- Read upRead up
- Exclude checks
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
*/
- Read upRead up
- Exclude checks
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));
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
*/
- Read upRead up
- Exclude checks
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());
- Read upRead up
- Exclude checks
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());
- Read upRead up
- Exclude checks
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));
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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));
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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));
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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));
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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());
- Read upRead up
- Exclude checks
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));
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}