topfreegames/khan

View on GitHub

Showing 425 of 425 total issues

Function GetTestClanWithStaleData has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
Open

func GetTestClanWithStaleData(db models.DB, staleApplications, staleInvites, staleDenies, staleDeletes int) (string, error) {
    gameID := uuid.NewV4().String()
    game := GameFactory.MustCreateWithOption(map[string]interface{}{
        "PublicID": gameID,
        "Metadata": map[string]interface{}{
Severity: Minor
Found in models/fixtures/fixtures.go - About 45 mins 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

Function GetClanReachedMaxMemberships has 7 return statements (exceeds 4 allowed).
Open

func GetClanReachedMaxMemberships(db models.DB) (*models.Game, *models.Clan, *models.Player, []*models.Player, []*models.Membership, error) {
    gameID := uuid.NewV4().String()
    clanPublicID := uuid.NewV4().String()

    game := GameFactory.MustCreateWithOption(map[string]interface{}{
Severity: Major
Found in models/fixtures/fixtures.go - About 45 mins to fix

    Function validateMembership has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    func validateMembership(db DB, encryptionKey []byte, game *Game, membership *Membership, clan *Clan, playerPublicID, requestorPublicID string) (int64, bool, error) {
    Severity: Minor
    Found in models/membership.go - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                  if timeToBeReady > 0 {
                      return -1, false, &MustWaitMembershipCooldownError{timeToBeReady, playerPublicID, clan.PublicID}
                  }
      Severity: Major
      Found in models/membership.go - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                    if previousInvite && requestorPublicID != playerPublicID {
                        cd = game.CooldownBeforeInvite
                    }
        Severity: Major
        Found in models/membership.go - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              if m, ok := v4.(easyjson.Unmarshaler); ok {
                                  m.UnmarshalEasyJSON(in)
                              } else if m, ok := v4.(json.Unmarshaler); ok {
                                  _ = m.UnmarshalJSON(in.Raw())
                              } else {
          Severity: Major
          Found in api/payload_easyjson.go - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                if m, ok := v11.(easyjson.Unmarshaler); ok {
                                    m.UnmarshalEasyJSON(in)
                                } else if m, ok := v11.(json.Unmarshaler); ok {
                                    _ = m.UnmarshalJSON(in.Raw())
                                } else {
            Severity: Major
            Found in api/payload_easyjson.go - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                  if m, ok := v1.(easyjson.Unmarshaler); ok {
                                      m.UnmarshalEasyJSON(in)
                                  } else if m, ok := v1.(json.Unmarshaler); ok {
                                      _ = m.UnmarshalJSON(in.Raw())
                                  } else {
              Severity: Major
              Found in models/clan_easyjson.go - About 45 mins to fix

                Function InitDb has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                func InitDb(host string, user string, port int, sslmode string, dbName string, password string) (interfaces.Database, error) {
                Severity: Minor
                Found in models/helpers.go - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                              if !previousInvite && requestorPublicID == playerPublicID && !memberLeft {
                                  cd = game.CooldownBeforeApply
                              }
                  Severity: Major
                  Found in models/membership.go - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                        if m, ok := v9.(easyjson.Unmarshaler); ok {
                                            m.UnmarshalEasyJSON(in)
                                        } else if m, ok := v9.(json.Unmarshaler); ok {
                                            _ = m.UnmarshalJSON(in.Raw())
                                        } else {
                    Severity: Major
                    Found in api/payload_easyjson.go - About 45 mins to fix

                      Function CreateTestClans has 6 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                          db models.DB, mongoDB interfaces.MongoDB, gameID string, publicIDTemplate string, numberOfClans int, afterCreationHook AfterClanCreationHook,
                      Severity: Minor
                      Found in models/fixtures/fixtures.go - About 45 mins to fix

                        Function ApproveOrDenyMembershipInvitationHandler has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
                        Open

                        func ApproveOrDenyMembershipInvitationHandler(app *App) func(c echo.Context) error {
                            return func(c echo.Context) error {
                                var membership *models.Membership
                                var err error
                                var tx interfaces.Transaction
                        Severity: Minor
                        Found in api/membership.go - About 45 mins 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

                        Function createClanPlayers has 6 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                        func createClanPlayers(db models.DB, games []string, clans map[string][]clanData, playersPerClan int, approved, denied, banned bool, progress func() bool) {
                        Severity: Minor
                        Found in perf/main.go - About 45 mins to fix

                          Identical blocks of code found in 4 locations. Consider refactoring.
                          Open

                              for i := 0; i < b.N; i++ {
                                  player := fixtures.PlayerFactory.MustCreateWithOption(map[string]interface{}{
                                      "GameID": game.PublicID,
                                  }).(*models.Player)
                                  err = db.Insert(player)
                          Severity: Major
                          Found in bench/player_test.go and 3 other locations - About 45 mins to fix
                          bench/clan_test.go on lines 41..50
                          bench/membership_test.go on lines 44..53
                          bench/membership_test.go on lines 88..97

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

                          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

                          Identical blocks of code found in 4 locations. Consider refactoring.
                          Open

                              for i := 0; i < b.N; i++ {
                                  player := fixtures.PlayerFactory.MustCreateWithOption(map[string]interface{}{
                                      "GameID": game.PublicID,
                                  }).(*models.Player)
                                  err = db.Insert(player)
                          Severity: Major
                          Found in bench/clan_test.go and 3 other locations - About 45 mins to fix
                          bench/membership_test.go on lines 44..53
                          bench/membership_test.go on lines 88..97
                          bench/player_test.go on lines 68..77

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

                          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

                          Method Khan.sendTo has 7 return statements (exceeds 4 allowed).
                          Open

                          func (k *Khan) sendTo(ctx context.Context, method, url string, payload interface{}) ([]byte, error) {
                              payloadJSON, err := json.Marshal(payload)
                              if err != nil {
                                  return nil, err
                              }
                          Severity: Major
                          Found in lib/lib.go - About 45 mins to fix

                            Identical blocks of code found in 4 locations. Consider refactoring.
                            Open

                                for i := 0; i < b.N; i++ {
                                    player := fixtures.PlayerFactory.MustCreateWithOption(map[string]interface{}{
                                        "GameID": game.PublicID,
                                    }).(*models.Player)
                                    err = db.Insert(player)
                            Severity: Major
                            Found in bench/membership_test.go and 3 other locations - About 45 mins to fix
                            bench/clan_test.go on lines 41..50
                            bench/membership_test.go on lines 88..97
                            bench/player_test.go on lines 68..77

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

                            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

                            Identical blocks of code found in 4 locations. Consider refactoring.
                            Open

                                for i := 0; i < b.N; i++ {
                                    player := fixtures.PlayerFactory.MustCreateWithOption(map[string]interface{}{
                                        "GameID": game.PublicID,
                                    }).(*models.Player)
                                    err = db.Insert(player)
                            Severity: Major
                            Found in bench/membership_test.go and 3 other locations - About 45 mins to fix
                            bench/clan_test.go on lines 41..50
                            bench/membership_test.go on lines 44..53
                            bench/player_test.go on lines 68..77

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

                            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 14 locations. Consider refactoring.
                            Open

                            func (mr *MockKhanInterfaceMockRecorder) ApplyForMembership(arg0, arg1 interface{}) *gomock.Call {
                                mr.mock.ctrl.T.Helper()
                                return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ApplyForMembership", reflect.TypeOf((*MockKhanInterface)(nil).ApplyForMembership), arg0, arg1)
                            }
                            Severity: Major
                            Found in lib/mocks/khan.go and 13 other locations - About 45 mins to fix
                            lib/mocks/khan.go on lines 62..65
                            lib/mocks/khan.go on lines 77..80
                            lib/mocks/khan.go on lines 92..95
                            lib/mocks/khan.go on lines 122..125
                            lib/mocks/khan.go on lines 137..140
                            lib/mocks/khan.go on lines 152..155
                            lib/mocks/khan.go on lines 167..170
                            lib/mocks/khan.go on lines 182..185
                            lib/mocks/khan.go on lines 197..200
                            lib/mocks/khan.go on lines 212..215
                            lib/mocks/khan.go on lines 227..230
                            lib/mocks/khan.go on lines 242..245
                            lib/mocks/khan.go on lines 272..275

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

                            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

                            Severity
                            Category
                            Status
                            Source
                            Language