valasek/timesheet

View on GitHub

Showing 59 of 66 total issues

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

        switch baseFileName {
        case "projects":
            n, err = api.projects.ProjectBackup(filePath)
        case "rates":
            n, err = api.rates.RateBackup(filePath)
Severity: Minor
Found in server/api/api.go and 1 other location - About 45 mins to fix
server/api/api.go on lines 355..366

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

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

        switch baseFileName {
        case "projects":
            n, err = api.projects.ProjectGenerate(filePath)
        case "rates":
            n, err = api.rates.RateGenerate(filePath)
Severity: Minor
Found in server/api/api.go and 1 other location - About 45 mins to fix
server/api/api.go on lines 490..501

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

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 SeedTable has 6 return statements (exceeds 4 allowed).
Open

func SeedTable(api *API, table, file string) (count int) {
    switch table {
    case "rates":
        if api.rates.RateCount() > 0 {
            logger.Log.Warn(fmt.Sprintf("- rates, file %s skipped, table contains %d records", file, api.rates.RateCount()))
Severity: Major
Found in server/api/api.go - About 40 mins to fix

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

    func (db *ReportedRecordManager) ReportedRecordCount() int {
        reportedRecords := []ReportedRecord{}
        var count int
        if err := db.db.Find(&reportedRecords).Count(&count); err != nil {
            return count
    Severity: Major
    Found in server/models/reportedRecords.go and 4 other locations - About 40 mins to fix
    server/models/consultants.go on lines 165..173
    server/models/holidays.go on lines 84..92
    server/models/projects.go on lines 156..164
    server/models/rates.go on lines 77..85

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

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

    func (db *ProjectManager) ProjectCount() int {
        projects := []Project{}
        var count int
        if err := db.db.Find(&projects).Count(&count); err != nil {
            return count
    Severity: Major
    Found in server/models/projects.go and 4 other locations - About 40 mins to fix
    server/models/consultants.go on lines 165..173
    server/models/holidays.go on lines 84..92
    server/models/rates.go on lines 77..85
    server/models/reportedRecords.go on lines 266..274

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

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

    func (db *RateManager) RateCount() int {
        rates := []Rate{}
        var count int
        if err := db.db.Find(&rates).Count(&count); err != nil {
            return count
    Severity: Major
    Found in server/models/rates.go and 4 other locations - About 40 mins to fix
    server/models/consultants.go on lines 165..173
    server/models/holidays.go on lines 84..92
    server/models/projects.go on lines 156..164
    server/models/reportedRecords.go on lines 266..274

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

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

    func (db *ConsultantManager) ConsultantCount() int {
        consultants := []Consultant{}
        var count int
        if err := db.db.Find(&consultants).Count(&count); err != nil {
            return count
    Severity: Major
    Found in server/models/consultants.go and 4 other locations - About 40 mins to fix
    server/models/holidays.go on lines 84..92
    server/models/projects.go on lines 156..164
    server/models/rates.go on lines 77..85
    server/models/reportedRecords.go on lines 266..274

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

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

    func (db *HolidayManager) HolidayCount() int {
        holidays := []Holiday{}
        var count int
        if err := db.db.Find(&holidays).Count(&count); err != nil {
            return count
    Severity: Major
    Found in server/models/holidays.go and 4 other locations - About 40 mins to fix
    server/models/consultants.go on lines 165..173
    server/models/projects.go on lines 156..164
    server/models/rates.go on lines 77..85
    server/models/reportedRecords.go on lines 266..274

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

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

      SET_CONSULTANTS (state, consultants) {
        state.all = consultants.sort(function (a, b) {
          var nameA = a.name.toUpperCase()
          var nameB = b.name.toUpperCase()
          if (nameA < nameB) {
    Severity: Minor
    Found in client/src/store/modules/consultants.js - 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

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

    func getborderDays(year, month string) (days []string, err error) {
        layout := "2006-1-02"
        monthStart, err := time.Parse(layout, year+"-"+month+"-01")
        if err != nil {
            return nil, err
    Severity: Major
    Found in server/models/reportedRecords.go - About 35 mins to fix

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

      func uploadedFileList() (list map[string]string, err error) {
          list = make(map[string]string)
          files, err := ioutil.ReadDir(filepath.Clean(viper.GetString("uploadFolderTemp")))
          if err != nil {
              return nil, err
      Severity: Major
      Found in server/api/apiFunctions.go - About 35 mins to fix

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

        func restoreDB(f *os.File) error {
            // delete if target folder exists
            err := os.RemoveAll(viper.GetString("uploadFolderTemp"))
            if err != nil {
                return err
        Severity: Major
        Found in server/api/apiFunctions.go - About 35 mins to fix

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

          func export() (fileName string, err error) {
              fileName = "timesheet-backup.zip"
              db := ConnectDB()
              defer db.Close()
              exportFolder := viper.GetString("export.location")
          Severity: Major
          Found in server/api/apiFunctions.go - About 35 mins to fix

            Method ReportedRecordManager.ReportedRecordUpdate has 5 return statements (exceeds 4 allowed).
            Open

            func (db *ReportedRecordManager) ReportedRecordUpdate(r UpdatedValue) ReportedRecord {
                updateValue := UpdatedValue{
                    ID:    r.ID,
                    Type:  r.Type,
                    Value: r.Value,
            Severity: Major
            Found in server/models/reportedRecords.go - About 35 mins to fix

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

                  case "projects":
                      if api.projects.ProjectCount() > 0 {
                          logger.Log.Warn(fmt.Sprintf("- projects, file %s skipped, table contains %d records", file, api.projects.ProjectCount()))
                          return 0
                      }
              Severity: Major
              Found in server/api/api.go and 4 other locations - About 35 mins to fix
              server/api/api.go on lines 399..405
              server/api/api.go on lines 406..412
              server/api/api.go on lines 420..426
              server/api/api.go on lines 427..433

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

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

                  case "holidays":
                      if api.holidays.HolidayCount() > 0 {
                          logger.Log.Warn(fmt.Sprintf("- holidays, file %s skipped, table contains %d records", file, api.holidays.HolidayCount()))
                          return 0
                      }
              Severity: Major
              Found in server/api/api.go and 4 other locations - About 35 mins to fix
              server/api/api.go on lines 399..405
              server/api/api.go on lines 406..412
              server/api/api.go on lines 413..419
              server/api/api.go on lines 420..426

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

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

                  case "reported_records":
                      if api.reportedRecords.ReportedRecordCount() > 0 {
                          logger.Log.Warn(fmt.Sprintf("- reported_records, file %s skipped, table contains %d records", file, api.reportedRecords.ReportedRecordCount()))
                          return 0
                      }
              Severity: Major
              Found in server/api/api.go and 4 other locations - About 35 mins to fix
              server/api/api.go on lines 399..405
              server/api/api.go on lines 406..412
              server/api/api.go on lines 413..419
              server/api/api.go on lines 427..433

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

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

                  case "consultants":
                      if api.consultants.ConsultantCount() > 0 {
                          logger.Log.Warn(fmt.Sprintf("- consultants, file %s skipped, table contains %d records", file, api.consultants.ConsultantCount()))
                          return 0
                      }
              Severity: Major
              Found in server/api/api.go and 4 other locations - About 35 mins to fix
              server/api/api.go on lines 399..405
              server/api/api.go on lines 413..419
              server/api/api.go on lines 420..426
              server/api/api.go on lines 427..433

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

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

                  case "rates":
                      if api.rates.RateCount() > 0 {
                          logger.Log.Warn(fmt.Sprintf("- rates, file %s skipped, table contains %d records", file, api.rates.RateCount()))
                          return 0
                      }
              Severity: Major
              Found in server/api/api.go and 4 other locations - About 35 mins to fix
              server/api/api.go on lines 406..412
              server/api/api.go on lines 413..419
              server/api/api.go on lines 420..426
              server/api/api.go on lines 427..433

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

              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