topfreegames/khan

View on GitHub

Showing 425 of 425 total issues

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

                It("Membership is already denied", func() {
                    action := "approve"
                    game, clan, _, players, memberships, err := fixtures.GetClanWithMemberships(testDb, 0, 0, 0, 1, "", "")
                    Expect(err).NotTo(HaveOccurred())

Severity: Major
Found in models/membership_test.go and 1 other location - About 2 hrs to fix
models/membership_test.go on lines 1787..1808

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

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

                It("Membership is already approved", func() {
                    action := "approve"
                    game, clan, _, players, memberships, err := fixtures.GetClanWithMemberships(testDb, 0, 0, 0, 1, "", "")
                    Expect(err).NotTo(HaveOccurred())

Severity: Major
Found in models/membership_test.go and 1 other location - About 2 hrs to fix
models/membership_test.go on lines 1810..1831

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

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

Function CreateGameHandler has 79 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func CreateGameHandler(app *App) func(c echo.Context) error {
    return func(c echo.Context) error {
        c.Set("route", "CreateGame")
        start := time.Now()

Severity: Major
Found in api/game.go - About 2 hrs to fix

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

            if err != nil {
                log.E(logger, "Could not dispatch membership hook by public id", func(cm log.CM) {
                    cm.Write(zap.Error(err))
                })
    
    
    Severity: Major
    Found in api/membership.go and 1 other location - About 2 hrs to fix
    api/membership.go on lines 352..368

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

    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

            if err != nil {
                log.E(logger, "Could not dispatch approve deny membership by id", func(cm log.CM) {
                    cm.Write(zap.Error(err))
                })
    
    
    Severity: Major
    Found in api/membership.go and 1 other location - About 2 hrs to fix
    api/membership.go on lines 566..582

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

    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

    Function GetClanReachedMaxMemberships has 77 lines of code (exceeds 50 allowed). Consider refactoring.
    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 2 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

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

                It("Should return in error case encryptionKey length is less than 32 bytes", func() {
                    _, err := DecryptData(data, encryptionKey[:31])
                    Expect(err).To(HaveOccurred())
        
                    if _, ok := err.(*TokenSizeError); !ok {
        Severity: Major
        Found in util/secure_test.go and 1 other location - About 1 hr to fix
        util/secure_test.go on lines 34..52

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

        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

                It("Should return in error case encryptionKey length is different than 32 bytes", func() {
                    _, err := EncryptData(data, encryptionKey[:31])
                    Expect(err).To(HaveOccurred())
        
                    if _, ok := err.(*TokenSizeError); !ok {
        Severity: Major
        Found in util/secure_test.go and 1 other location - About 1 hr to fix
        util/secure_test.go on lines 75..93

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

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

        func getHTTPTransport(
            maxIdleConns, maxIdleConnsPerHost int,
        ) http.RoundTripper {
            if _, ok := http.DefaultTransport.(*http.Transport); !ok {
                return http.DefaultTransport // tests use a mock transport
        Severity: Major
        Found in api/dispatcher.go and 1 other location - About 1 hr to fix
        lib/lib.go on lines 59..83

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

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

        func getHTTPTransport(
            maxIdleConns, maxIdleConnsPerHost int,
        ) http.RoundTripper {
            if _, ok := http.DefaultTransport.(*http.Transport); !ok {
                return http.DefaultTransport // tests use a mock transport
        Severity: Major
        Found in lib/lib.go and 1 other location - About 1 hr to fix
        api/dispatcher.go on lines 56..80

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

        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

        Function easyjson91eb9988DecodeGithubComTopfreegamesKhanModels has 71 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func easyjson91eb9988DecodeGithubComTopfreegamesKhanModels(in *jlexer.Lexer, out *Clan) {
            isTopLevel := in.IsStart()
            if in.IsNull() {
                if isTopLevel {
                    in.Consumed()
        Severity: Minor
        Found in models/clan_easyjson.go - About 1 hr to fix

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

                  It("should get pending invites even if max amount is not set", func() {
                      _, clan, _, _, _, err := fixtures.GetClanWithMemberships(testDb, 10, 0, 0, 10, "", "", false, true, true)
                      Expect(err).NotTo(HaveOccurred())
          
                      status, body := Get(app, GetGameRoute(clan.GameID, fmt.Sprintf("/clans/%s", clan.PublicID)))
          Severity: Major
          Found in api/clan_test.go and 1 other location - About 1 hr to fix
          api/clan_test.go on lines 762..773

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

          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

                  It("should get pending applications even if max amount is not set", func() {
                      _, clan, _, _, _, err := fixtures.GetClanWithMemberships(testDb, 10, 0, 0, 10, "", "", false, false, true)
                      Expect(err).NotTo(HaveOccurred())
          
                      status, body := Get(app, GetGameRoute(clan.GameID, fmt.Sprintf("/clans/%s", clan.PublicID)))
          Severity: Major
          Found in api/clan_test.go and 1 other location - About 1 hr to fix
          api/clan_test.go on lines 775..786

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

          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 21 places. Go fmt your code!
          Open

          // khan
          Severity: Minor
          Found in api/payload.go by gofmt

          Method playerDetailsDAO.Serialize has 68 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (p *playerDetailsDAO) Serialize(encryptionKey []byte) map[string]interface{} {
              requestor := &Player{
                  PublicID: nullOrString(p.RequestorPublicID),
                  Name:     nullOrString(p.RequestorName),
              }
          Severity: Minor
          Found in models/DAO.go - About 1 hr to fix

            Function PromoteOrDemoteMembershipHandler has 68 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func PromoteOrDemoteMembershipHandler(app *App, action string) func(c echo.Context) error {
                return func(c echo.Context) error {
                    c.Set("route", "PromoteOrDemoteMember")
                    start := time.Now()
                    clanPublicID := c.Param("clanPublicID")
            Severity: Minor
            Found in api/membership.go - About 1 hr to fix

              Function CreatePlayerHandler has 65 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func CreatePlayerHandler(app *App) func(c echo.Context) error {
                  return func(c echo.Context) error {
                      c.Set("route", "CreatePlayer")
                      start := time.Now()
                      gameID := c.Param("gameID")
              Severity: Minor
              Found in api/player.go - About 1 hr to fix

                Function easyjsonA8a797f8EncodeGithubComTopfreegamesKhanApi2 has a Cognitive Complexity of 28 (exceeds 20 allowed). Consider refactoring.
                Open

                func easyjsonA8a797f8EncodeGithubComTopfreegamesKhanApi2(out *jwriter.Writer, in UpdateGamePayload) {
                    out.RawByte('{')
                    first := true
                    _ = first
                    {
                Severity: Minor
                Found in api/payload_easyjson.go - About 1 hr 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 easyjsonA8a797f8EncodeGithubComTopfreegamesKhanApi8 has a Cognitive Complexity of 28 (exceeds 20 allowed). Consider refactoring.
                Open

                func easyjsonA8a797f8EncodeGithubComTopfreegamesKhanApi8(out *jwriter.Writer, in CreateGamePayload) {
                    out.RawByte('{')
                    first := true
                    _ = first
                    {
                Severity: Minor
                Found in api/payload_easyjson.go - About 1 hr 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

                Severity
                Category
                Status
                Source
                Language