Lichess4545/Chesster

View on GitHub
src/league.ts

Summary

Maintainability
F
4 days
Test Coverage
F
20%

File league.ts has 572 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// -----------------------------------------------------------------------------
// Defines a league object which can be used to interact with the website
// for the given league
// -----------------------------------------------------------------------------
import _ from 'lodash'
Severity: Major
Found in src/league.ts - About 1 day to fix

    League has 33 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export class League {
        private log: LogWithPrefix
    
        constructor(
            public bot: SlackBot,
    Severity: Minor
    Found in src/league.ts - About 4 hrs to fix

      Function refreshRosters has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          async refreshRosters() {
              const newPlayers: Player[] = []
              const newPlayerLookup: Record<string, Player> = {}
              const newTeams: Team[] = []
              const newTeamLookup: Record<string, Team> = {}
      Severity: Minor
      Found in src/league.ts - About 1 hr to fix

        Function refresh has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            refresh() {
                return Promise.all([
                    this.refreshRosters()
                        .then(() => {
                            this._lastUpdated = moment.utc()
        Severity: Minor
        Found in src/league.ts - About 1 hr to fix

          Function getTeamByPlayerName has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              getTeamByPlayerName(playerName: string): Team | undefined {
                  playerName = playerName.toLowerCase()
                  const directTeamMapping =
                      this._playerLookup[playerName] &&
                      this._playerLookup[playerName].team
          Severity: Minor
          Found in src/league.ts - 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 getPairingDetails has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              async getPairingDetails(
                  lichessUsername: string
              ): Promise<PairingDetails | undefined> {
                  return new Promise(async (resolve) => {
                      const pairings = this.findPairing(lichessUsername)
          Severity: Minor
          Found in src/league.ts - About 1 hr to fix

            Function resultFromString has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

            function resultFromString(result: string | undefined): ResultsEnum {
                if (result === undefined) return ResultsEnum.UNKNOWN
                result = result.toLowerCase()
                if (result === '1-0') {
                    return ResultsEnum.WHITE_WIN
            Severity: Minor
            Found in src/league.ts - 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 formatPairingResponse has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                formatPairingResponse(
                    requestingPlayer: LeagueMember,
                    details: PairingDetails
                ) {
                    let time
            Severity: Minor
            Found in src/league.ts - About 35 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

            Avoid too many return statements within this function.
            Open

                        return team.name + ' has not chosen a team captain. '
            Severity: Major
            Found in src/league.ts - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return ResultsEnum.BLACK_FORFEIT_WIN
              Severity: Major
              Found in src/league.ts - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                        return ResultsEnum.WHITE_FORFEIT_WIN
                Severity: Major
                Found in src/league.ts - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          return ResultsEnum.UNKNOWN
                  Severity: Major
                  Found in src/league.ts - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                            return ResultsEnum.SCHEDULING_DRAW
                    Severity: Major
                    Found in src/league.ts - About 30 mins to fix

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

                          formatRulesLinkResponse() {
                              if (this.config.links.rules) {
                                  return `Here are the rules and regulations:\n${this.config.links.rules}`
                              } else {
                                  return `The ${this.name} league does not have a rules link.`
                      Severity: Major
                      Found in src/league.ts and 2 other locations - About 2 hrs to fix
                      src/league.ts on lines 478..484
                      src/league.ts on lines 489..495

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

                      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

                          formatStarterGuideResponse() {
                              if (this.config.links.guide) {
                                  return `Here is everything you need to know:\n${this.config.links.guide}`
                              } else {
                                  return `The ${this.name} league does not have a starter guide.`
                      Severity: Major
                      Found in src/league.ts and 2 other locations - About 2 hrs to fix
                      src/league.ts on lines 467..473
                      src/league.ts on lines 489..495

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

                      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

                          formatRegistrationResponse() {
                              if (this.config.links.registration) {
                                  return `You can sign up here:\n${this.config.links.registration}`
                              } else {
                                  return `The ${this.name} league does not have an active signup form at the moment.`
                      Severity: Major
                      Found in src/league.ts and 2 other locations - About 2 hrs to fix
                      src/league.ts on lines 467..473
                      src/league.ts on lines 478..484

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

                      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

                                  this.refreshRosters()
                                      .then(() => {
                                          this._lastUpdated = moment.utc()
                                          this.emitter.emit('refreshRosters', this)
                                      })
                      Severity: Major
                      Found in src/league.ts and 1 other location - About 1 hr to fix
                      src/league.ts on lines 185..197

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

                      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

                                  this.refreshCurrentRoundSchedules()
                                      .then(() => {
                                          this._lastUpdated = moment.utc()
                                          this.emitter.emit('refreshPairings', this)
                                      })
                      Severity: Major
                      Found in src/league.ts and 1 other location - About 1 hr to fix
                      src/league.ts on lines 174..184

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

                      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

                      There are no issues that match your filters.

                      Category
                      Status