Showing 69 of 79 total issues
Similar blocks of code found in 5 locations. Consider refactoring. Open
package open
import (
"github.com/spf13/cobra"
"github.com/zephinzer/dev/cmd/dev/open/merge_request"
- Read upRead up
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 151.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Function run
has 57 lines of code (exceeds 50 allowed). Consider refactoring. Open
func run(command *cobra.Command, args []string) {
targetWorkspaceName := strings.Join(args, ".")
if len(targetWorkspaceName) == 0 {
command.Help()
workspaces := c.Global.Repositories.GetWorkspaces()
Function GetCommand
has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring. Open
func GetCommand() *cobra.Command {
cmd := cobra.Command{
Use: constants.AccountCanonicalNoun,
Aliases: constants.AccountAliases,
Short: "Retrieves account information from Trello",
- Read upRead up
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
Method TodoSerializer.GetMessage
has 55 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (ts TodoSerializer) GetMessage() string {
targetType := ts.getTargetType()
createdAt := humanize.Time(ts.CreatedAt)
switch ts.ActionName {
case "assigned":
Function WatchNotifications
has 55 lines of code (exceeds 50 allowed). Consider refactoring. Open
func WatchNotifications(
accessToken string,
fromProjects Projects,
databaseConnection *sql.DB,
updateInterval time.Duration,
Function run
has 54 lines of code (exceeds 50 allowed). Consider refactoring. Open
func run(cmd *cobra.Command, args []string) {
pathToInitialiseAt := path.Join(args...)
log.Debug("resolving provided path %s...", pathToInitialiseAt)
pathToInitialiseAt, resolvePathError := utils.ResolvePath(pathToInitialiseAt)
if resolvePathError != nil {
Function Download
has 11 return statements (exceeds 4 allowed). Open
func Download(options DownloadOptions) error {
downloadStatus := DownloadStatus{}
tmpFilePath := options.FilePath + ".download_" + time.Now().Format("20060102150405")
if options.Events == nil {
options.Events = make(chan DownloadEvent, 16)
Function GetCommand
has 52 lines of code (exceeds 50 allowed). Consider refactoring. Open
func GetCommand() *cobra.Command {
cmd := cobra.Command{
Use: constants.NotificationsCanonicalNoun,
Aliases: constants.NotificationsAliases,
Short: "Initialises telegram notifications",
Function Init
has 10 return statements (exceeds 4 allowed). Open
func Init(atPath string) error {
directory := filepath.Dir(atPath)
filename := filepath.Base(atPath)
fullPath := path.Join(directory, filename)
fullPathInfo, checkFileError := os.Lstat(fullPath)
Function Unzip
has 10 return statements (exceeds 4 allowed). Open
func Unzip(options UnzipOptions) []error {
var err error
status := UnzipStatus{}
if options.Events == nil {
Function run
has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring. Open
func run(command *cobra.Command, args []string) {
if config.Global.Repositories == nil {
log.Error("no repositories have been defined")
os.Exit(1)
return
- Read upRead up
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 run
has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring. Open
func run(command *cobra.Command, args []string) {
if len(args) == 0 {
command.Help()
log.Errorf("no repository url(s) specified, see usage above for how to use this command")
os.Exit(1)
- Read upRead up
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 GetSSH
has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring. Open
func GetSSH(keysDirectory string) ([]Key, error) {
directoryList, readDirError := ioutil.ReadDir(keysDirectory)
if readDirError != nil {
return nil, fmt.Errorf("failed to list directory at '%s': %s", keysDirectory, readDirError)
}
- Read upRead up
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 Untar
has 9 return statements (exceeds 4 allowed). Open
func Untar(options UntarOptions) []error {
var err error
status := UntarStatus{}
if options.Events == nil {
Function run
has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring. Open
func run(command *cobra.Command, args []string) {
targetWorkspaceName := strings.Join(args, ".")
if len(targetWorkspaceName) == 0 {
command.Help()
workspaces := c.Global.Repositories.GetWorkspaces()
- Read upRead up
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 getOAuthCallbackHandler
has 8 return statements (exceeds 4 allowed). Open
func getOAuthCallbackHandler(res http.ResponseWriter, req *http.Request) {
requestID := uuid.New().String()
params := mux.Vars(req)
Function WatchNotifications
has 7 return statements (exceeds 4 allowed). Open
func WatchNotifications(
accounts []AccountConfig,
databaseConnection *sql.DB,
updateInterval time.Duration,
stop chan struct{},
Method Repository.GetPath
has 7 return statements (exceeds 4 allowed). Open
func (r Repository) GetPath(rootPath ...string) (string, error) {
// if :rootPath is defined, use that as the root instead of the current directory
storagePath := "."
if len(rootPath) > 0 {
storagePath = rootPath[0]
Method VSCode.WriteTo
has 7 return statements (exceeds 4 allowed). Open
func (vsc VSCode) WriteTo(workspacePath string, overwrite ...bool) error {
isOverwritable := false
if len(overwrite) > 0 {
isOverwritable = overwrite[0]
}
Function Check
has 7 return statements (exceeds 4 allowed). Open
func Check(atPath string) error {
absolutePath, resolvePathError := utils.ResolvePath(atPath)
if resolvePathError != nil {
return fmt.Errorf("failed to resolve path '%s': %s", atPath, resolvePathError)
}