egordorichev/LastTry

View on GitHub
core/src/org/egordorichev/lasttry/entity/components/PhysicsComponent.java

Summary

Maintainability
F
3 days
Test Coverage

Method updateXVelocity has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
Open

    private void updateXVelocity() {
        // Non-solids skip adjustment and collision checks
        if (this.solid && this.velocity.x != 0) {
            // this.pushOutOfBlocks(Util.random(1, 5));
            Rectangle originalHitbox = this.hitbox.copy().offset(this.position);

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

    private void updateYVelocity() {
        if (this.solid) {
            // Apply gravity
            this.velocity.y -= 0.4f;
        }

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

PhysicsComponent has 34 methods (exceeds 20 allowed). Consider refactoring.
Open

public class PhysicsComponent<T extends Entity> extends EntityComponent<T> {
    public enum Direction {
        LEFT, RIGHT
    }

    File PhysicsComponent.java has 275 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    package org.egordorichev.lasttry.entity.components;
    
    import com.badlogic.gdx.math.Vector2;
    import org.egordorichev.lasttry.Globals;
    import org.egordorichev.lasttry.entity.Entity;

      Method pushOutOfBlocks has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          private boolean pushOutOfBlocks(int i) {
              Rectangle box = this.hitbox.copy().offset(this.position);
              float offsetSize = Block.SIZE;
              boolean pushed = false;
              if (collides(box)) {

      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 updateXVelocity has 53 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private void updateXVelocity() {
              // Non-solids skip adjustment and collision checks
              if (this.solid && this.velocity.x != 0) {
                  // this.pushOutOfBlocks(Util.random(1, 5));
                  Rectangle originalHitbox = this.hitbox.copy().offset(this.position);

        Method pushOutOfBlocks has 48 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private boolean pushOutOfBlocks(int i) {
                Rectangle box = this.hitbox.copy().offset(this.position);
                float offsetSize = Block.SIZE;
                boolean pushed = false;
                if (collides(box)) {

          Method updateYVelocity has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private void updateYVelocity() {
                  if (this.solid) {
                      // Apply gravity
                      this.velocity.y -= 0.4f;
                  }

            Avoid deeply nested control flow statements.
            Open

                                    if (this.velocity.y != -0.4f) {
                                        this.onGroundHit.call();
                                    }

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

                          } else {
                              // Prevent floor clipping with high speeds
                              float distToCollision = Globals.getWorld().distToVerticalCollision(boxO, this.velocity.y);
                              if (Math.abs(distToCollision) < Math.abs(this.velocity.y)) {
                                  this.velocity.y = distToCollision;
              core/src/org/egordorichev/lasttry/entity/components/PhysicsComponent.java on lines 188..194

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

              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

                          } else if (!this.isStepping) {
                              // Prevent wall clipping with high speeds
                              float distToCollision = Globals.getWorld().distToHorizontalCollision(originalHitbox, this.velocity.x);
                              if (Math.abs(distToCollision) < Math.abs(this.velocity.x)) {
                                  this.velocity.x = distToCollision;
              core/src/org/egordorichev/lasttry/entity/components/PhysicsComponent.java on lines 248..254

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

              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

              These nested if statements could be combined
              Open

                                      if (this.velocity.y != -0.4f) {
                                          this.onGroundHit.call();
                                      }

              CollapsibleIfStatements

              Since: PMD 3.1

              Priority: Medium

              Categories: Style

              Remediation Points: 50000

              Sometimes two consecutive 'if' statements can be consolidated by separating their conditions with a boolean short-circuit operator.

              Example:

              void bar() {
               if (x) { // original implementation
               if (y) {
               // do stuff
               }
               }
              }
              
              void bar() {
               if (x && y) { // optimized implementation
               // do stuff
               }
              }

              There are no issues that match your filters.

              Category
              Status