topfreegames/khan

View on GitHub
models/clan.go

Summary

Maintainability
F
3 days
Test Coverage

File clan.go has 854 lines of code (exceeds 500 allowed). Consider refactoring.
Open

// khan
// https://github.com/topfreegames/khan
//
// Licensed under the MIT license:
// http://www.opensource.org/licenses/mit-license
Severity: Major
Found in models/clan.go - About 1 day to fix

    Function GetClanDetails has 119 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func GetClanDetails(db DB, encryptionKey []byte, gameID string, clan *Clan, maxClansPerPlayer int, options *GetClanDetailsOptions) (map[string]interface{}, error) {
        query := fmt.Sprintf(`
        WITH memberships_pending AS (
            SELECT *
            FROM memberships im
    Severity: Major
    Found in models/clan.go - About 3 hrs to fix

      Function TransferClanOwnership has 73 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func TransferClanOwnership(db DB, encryptionKey []byte, gameID, clanPublicID, playerPublicID string, levels map[string]interface{}, maxLevel int) (*Clan, *Player, *Player, error) {
          clan, err := GetClanByPublicID(db, gameID, clanPublicID)
          if err != nil {
              return nil, nil, nil, err
          }
      Severity: Minor
      Found in models/clan.go - About 1 hr to fix

        Function LeaveClan has 13 return statements (exceeds 4 allowed).
        Open

        func LeaveClan(db DB, encryptionKey []byte, gameID, publicID string) (*Clan, *Player, *Player, error) {
            clan, err := GetClanByPublicID(db, gameID, publicID)
            if err != nil {
                return nil, nil, nil, err
            }
        Severity: Major
        Found in models/clan.go - About 1 hr to fix

          Function TransferClanOwnership has 13 return statements (exceeds 4 allowed).
          Open

          func TransferClanOwnership(db DB, encryptionKey []byte, gameID, clanPublicID, playerPublicID string, levels map[string]interface{}, maxLevel int) (*Clan, *Player, *Player, error) {
              clan, err := GetClanByPublicID(db, gameID, clanPublicID)
              if err != nil {
                  return nil, nil, nil, err
              }
          Severity: Major
          Found in models/clan.go - About 1 hr to fix

            Function LeaveClan has 54 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func LeaveClan(db DB, encryptionKey []byte, gameID, publicID string) (*Clan, *Player, *Player, error) {
                clan, err := GetClanByPublicID(db, gameID, publicID)
                if err != nil {
                    return nil, nil, nil, err
                }
            Severity: Minor
            Found in models/clan.go - About 1 hr to fix

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

              func GetClanDetails(db DB, encryptionKey []byte, gameID string, clan *Clan, maxClansPerPlayer int, options *GetClanDetailsOptions) (map[string]interface{}, error) {
              Severity: Minor
              Found in models/clan.go - About 45 mins to fix

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

                func CreateClan(db DB, encryptionKey []byte, gameID, publicID, name, ownerPublicID string, metadata map[string]interface{}, allowApplication, autoJoin bool, maxClansPerPlayer int) (*Clan, error) {
                Severity: Minor
                Found in models/clan.go - About 45 mins to fix

                  Function UpdateClan has 6 return statements (exceeds 4 allowed).
                  Open

                  func UpdateClan(db DB, gameID, publicID, name, ownerPublicID string, metadata map[string]interface{}, allowApplication, autoJoin bool) (*Clan, error) {
                      clan, err := GetClanByPublicIDAndOwnerPublicID(db, gameID, publicID, ownerPublicID)
                      if err != nil {
                          return nil, err
                      }
                  Severity: Major
                  Found in models/clan.go - About 40 mins to fix

                    Function UpdateClanMembershipCount has 6 return statements (exceeds 4 allowed).
                    Open

                    func UpdateClanMembershipCount(db DB, id int64) error {
                        query := `
                        UPDATE clans SET membership_count=membership.count+1
                        FROM (
                            SELECT COUNT(*) as count
                    Severity: Major
                    Found in models/clan.go - About 40 mins to fix

                      Function GetClanByPublicIDAndOwnerPublicID has 6 return statements (exceeds 4 allowed).
                      Open

                      func GetClanByPublicIDAndOwnerPublicID(db DB, gameID, publicID, ownerPublicID string) (*Clan, error) {
                          var clans []*Clan
                          var players []*Player
                          _, err := db.Select(&clans, "SELECT * FROM clans WHERE game_id=$1 AND public_id=$2", gameID, publicID)
                          if err != nil {
                      Severity: Major
                      Found in models/clan.go - About 40 mins to fix

                        Function TransferClanOwnership has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                        func TransferClanOwnership(db DB, encryptionKey []byte, gameID, clanPublicID, playerPublicID string, levels map[string]interface{}, maxLevel int) (*Clan, *Player, *Player, error) {
                        Severity: Minor
                        Found in models/clan.go - About 35 mins to fix

                          Function SearchClan has 5 return statements (exceeds 4 allowed).
                          Open

                          func SearchClan(
                              db DB, mongo interfaces.MongoDB, gameID, term string, pageSize int64,
                          ) ([]Clan, error) {
                              if term == "" {
                                  return nil, &EmptySearchTermError{}
                          Severity: Major
                          Found in models/clan.go - About 35 mins to fix

                            Function CreateClan has 5 return statements (exceeds 4 allowed).
                            Open

                            func CreateClan(db DB, encryptionKey []byte, gameID, publicID, name, ownerPublicID string, metadata map[string]interface{}, allowApplication, autoJoin bool, maxClansPerPlayer int) (*Clan, error) {
                                player, err := GetPlayerByPublicID(db, encryptionKey, gameID, ownerPublicID)
                                if err != nil {
                                    return nil, err
                                }
                            Severity: Major
                            Found in models/clan.go - About 35 mins to fix

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

                              func (c *Clan) IndexClanIntoElasticSearch() error {
                                  es := es.GetConfiguredClient()
                                  // TODO: fix it, boomforce is hardcoded for now
                                  if es != nil && c.GameID == "boomforce" {
                                      workers.Enqueue(queues.KhanESQueue, "Add", map[string]interface{}{
                              Severity: Major
                              Found in models/clan.go and 2 other locations - About 1 hr to fix
                              models/clan.go on lines 256..268
                              models/clan.go on lines 271..283

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

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

                              func (c *Clan) DeleteClanFromElasticSearch() error {
                                  es := es.GetConfiguredClient()
                                  // TODO: fix it, boomforce is hardcoded for now
                                  if es != nil && c.GameID == "boomforce" {
                                      workers.Enqueue(queues.KhanESQueue, "Add", map[string]interface{}{
                              Severity: Major
                              Found in models/clan.go and 2 other locations - About 1 hr to fix
                              models/clan.go on lines 185..197
                              models/clan.go on lines 256..268

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

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

                              func (c *Clan) UpdateClanIntoElasticSearch() error {
                                  es := es.GetConfiguredClient()
                                  // TODO: fix it, boomforce is hardcoded for now
                                  if es != nil && c.GameID == "boomforce" {
                                      workers.Enqueue(queues.KhanESQueue, "Add", map[string]interface{}{
                              Severity: Major
                              Found in models/clan.go and 2 other locations - About 1 hr to fix
                              models/clan.go on lines 185..197
                              models/clan.go on lines 271..283

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

                              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

                              func getClanLevelByLevelInt(levelInt int, levels map[string]interface{}) string {
                                  for k, v := range levels {
                                      switch v.(type) {
                                      case float64:
                                          if int(v.(float64)) == levelInt {
                              Severity: Minor
                              Found in models/clan.go and 1 other location - About 30 mins to fix
                              models/membership.go on lines 680..694

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

                              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

                              Your code does not pass gofmt in 11 places. Go fmt your code!
                              Open

                              // khan
                              Severity: Minor
                              Found in models/clan.go by gofmt

                              There are no issues that match your filters.

                              Category
                              Status