Missing class import via use statement (line '18', column '32'). Open
$reflectionClass = new \ReflectionClass(Difficulty::class);
- Read upRead up
- Exclude checks
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
protected function I_can_create_it_with_zero()
{
$difficulty = new Difficulty(['0', '1', '78=321']);
self::assertSame(0, $difficulty->getValue());
self::assertEquals(new DifficultyAddition('78=321', 0), $difficulty->getDifficultyAddition());
- 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 96.
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
protected function I_can_create_it_positive()
{
$difficulty = new Difficulty(['35689', '356891', '332211']);
self::assertSame(35689, $difficulty->getValue());
self::assertEquals(new DifficultyAddition('332211', 0), $difficulty->getDifficultyAddition());
- 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 96.
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 $withoutAdditionByRealms. Keep variable name length under 20. Open
$withoutAdditionByRealms = new Difficulty(['123', '456', '0']);
- 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
Avoid excessively long variable names like $zeroMinimalDifficulty. Keep variable name length under 20. Open
$zeroMinimalDifficulty = new Difficulty(['0', '65', '12=13']);
- 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
Avoid excessively long variable names like $higherThanMaximalDifficulty. Keep variable name length under 20. Open
$higherThanMaximalDifficulty = $formulaDifficulty->getWithDifficultyChange(5);
- 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_can_not_create_it_with_invalid_points_to_annotation is not named in camelCase. Open
public function I_can_not_create_it_with_invalid_points_to_annotation()
{
$this->expectException(\DrdPlus\Tables\Theurgist\Spells\SpellParameters\Partials\Exceptions\MissingValueForFormulaDifficultyAddition::class);
$this->expectExceptionMessageMatches('~123~');
new Difficulty([123, 456]);
- 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()
{
$zeroMinimalDifficulty = new Difficulty(['0', '65', '12=13']);
self::assertSame(0, $zeroMinimalDifficulty->getMinimal());
self::assertSame(65, $zeroMinimalDifficulty->getMaximal());
- 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_get_current_realms_increment is not named in camelCase. Open
public function I_can_get_current_realms_increment()
{
$formulaDifficulty = new Difficulty([1, 5, '2=3']);
self::assertSame($formulaDifficulty->getValue(), $formulaDifficulty->getMinimal());
self::assertSame(0, $formulaDifficulty->getCurrentRealmsIncrement());
- 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_create_it_with_negative_minimum is not named in camelCase. Open
public function I_can_not_create_it_with_negative_minimum()
{
$this->expectException(\DrdPlus\Tables\Theurgist\Spells\SpellParameters\Exceptions\InvalidValueForMinimalDifficulty::class);
$this->expectExceptionMessageMatches('~-1~');
new Difficulty(['-1', '65', '12=13']);
- 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_create_it_with_negative_maximum is not named in camelCase. Open
public function I_can_not_create_it_with_negative_maximum()
{
$this->expectException(\DrdPlus\Tables\Theurgist\Spells\SpellParameters\Exceptions\InvalidValueForMaximalDifficulty::class);
$this->expectExceptionMessageMatches('~-15~');
new Difficulty(['6', '-15', '12=13']);
- 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_get_its_clone_changed_by_difficulty_change is not named in camelCase. Open
public function I_can_get_its_clone_changed_by_difficulty_change()
{
$original = new Difficulty(['123', '345', '456=789']);
self::assertSame(0, $original->getDifficultyAddition()->getCurrentAddition());
- 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_create_it is not named in camelCase. Open
public function I_can_create_it()
{
$this->I_can_create_it_with_zero();
$this->I_can_create_it_positive();
}
- 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_get_untouched_instance_as_with_zero_change is not named in camelCase. Open
public function I_get_untouched_instance_as_with_zero_change()
{
$formulaDifficulty = new Difficulty([1, 2, '3=4']);
$beforeChange = serialize($formulaDifficulty);
- 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_create_it_with_zero is not named in camelCase. Open
protected function I_can_create_it_with_zero()
{
$difficulty = new Difficulty(['0', '1', '78=321']);
self::assertSame(0, $difficulty->getValue());
self::assertEquals(new DifficultyAddition('78=321', 0), $difficulty->getDifficultyAddition());
- 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_create_it_with_lesser_maximum_than_minimum is not named in camelCase. Open
public function I_can_not_create_it_with_lesser_maximum_than_minimum()
{
$this->expectException(\DrdPlus\Tables\Theurgist\Spells\SpellParameters\Exceptions\MinimalDifficultyCanNotBeGreaterThanMaximal::class);
$this->expectExceptionMessageMatches('~12.+11~');
new Difficulty(['12', '11', '12=13']);
- 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_get_whispered_current_class_as_return_value_for_difficulty_change is not named in camelCase. Open
public function I_get_whispered_current_class_as_return_value_for_difficulty_change()
{
$reflectionClass = new \ReflectionClass(Difficulty::class);
$classBaseName = preg_replace('~^.*[\\\](\w+)$~', '$1', Difficulty::class);
$add = $reflectionClass->getMethod('getWithDifficultyChange');
- 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_create_it_positive is not named in camelCase. Open
protected function I_can_create_it_positive()
{
$difficulty = new Difficulty(['35689', '356891', '332211']);
self::assertSame(35689, $difficulty->getValue());
self::assertEquals(new DifficultyAddition('332211', 0), $difficulty->getDifficultyAddition());
- 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() {
}
}