Showing 526 of 526 total issues
Function CmdConnect
has 14 return statements (exceeds 4 allowed). Open
func CmdConnect(f cmdutil.Factory) *cobra.Command {
var connect = &handler.ConnectOptions{}
var extraRoute = &handler.ExtraRouteInfo{}
var sshConf = &pkgssh.SshConfig{}
var transferImage, foreground, lite bool
Function recursiveTar
has 14 return statements (exceeds 4 allowed). Open
func recursiveTar(srcDir, srcFile localPath, destDir, destFile remotePath, tw *tar.Writer) error {
matchedPaths, err := srcDir.Join(srcFile).Glob()
if err != nil {
return err
}
Function createTun
has 14 return statements (exceeds 4 allowed). Open
func createTun(cfg Config) (conn net.Conn, itf *net.Interface, err error) {
if cfg.Addr == "" && cfg.Addr6 == "" {
err = fmt.Errorf("IPv4 address and IPv6 address can not be empty at same time")
return
}
Similar blocks of code found in 2 locations. Consider refactoring. Open
if lite {
resp, err := cli.ConnectFork(cmd.Context(), req)
if err != nil {
return err
}
- 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 150.
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
} else {
resp, err := cli.Connect(cmd.Context(), req)
if err != nil {
return err
}
- 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 150.
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 createTun
has 58 lines of code (exceeds 50 allowed). Consider refactoring. Open
func createTun(cfg Config) (conn net.Conn, itf *net.Interface, err error) {
if cfg.Addr == "" && cfg.Addr6 == "" {
err = fmt.Errorf("IPv4 address and IPv6 address can not be empty at same time")
return
}
Method Route.GenerateServers
has 58 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (r *Route) GenerateServers() ([]Server, error) {
chain, err := r.parseChain()
if err != nil && !errors.Is(err, ErrorInvalidNode) {
log.Errorf("Failed to parse chain: %v", err)
return nil, err
Function createContainer
has 57 lines of code (exceeds 50 allowed). Consider refactoring. Open
func createContainer(ctx context.Context, dockerCli command.Cli, runConfig *RunConfig) (string, error) {
config := runConfig.config
hostConfig := runConfig.hostConfig
networkingConfig := runConfig.networkingConfig
var (
Method server.ServeDNS
has 57 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (s *server) ServeDNS(w miekgdns.ResponseWriter, m *miekgdns.Msg) {
defer w.Close()
if len(m.Question) == 0 {
m.Response = true
_ = w.WriteMsg(m)
Method Connects.Less
has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring. Open
func (s Connects) Less(i, j int) bool {
a := s[i]
b := s[j]
if a == nil {
- 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 ConnectOptions.DoConnect
has 13 return statements (exceeds 4 allowed). Open
func (c *ConnectOptions) DoConnect(ctx context.Context, isLite bool) (err error) {
c.ctx, c.cancel = context.WithCancel(ctx)
log.Info("Starting connect")
m := dhcp.NewDHCPManager(c.clientset.CoreV1().ConfigMaps(c.Namespace), c.Namespace)
Method ConnectOptions.upgradeDeploy
has 13 return statements (exceeds 4 allowed). Open
func (c *ConnectOptions) upgradeDeploy(ctx context.Context) error {
deploy, err := c.clientset.AppsV1().Deployments(c.Namespace).Get(ctx, config.ConfigMapPodTrafficManager, metav1.GetOptions{})
if err != nil {
return err
}
Function downloadAndInstall
has 13 return statements (exceeds 4 allowed). Open
func downloadAndInstall(client *http.Client, url string) error {
temp, err := os.CreateTemp("", "*.zip")
if err != nil {
return err
}
Function CmdProxy
has 13 return statements (exceeds 4 allowed). Open
func CmdProxy(f cmdutil.Factory) *cobra.Command {
var connect = handler.ConnectOptions{}
var extraRoute = &handler.ExtraRouteInfo{}
var sshConf = &pkgssh.SshConfig{}
var transferImage, foreground bool
Method Server.redirectConnectForkToSudoDaemon
has 13 return statements (exceeds 4 allowed). Open
func (svr *Server) redirectConnectForkToSudoDaemon(req *rpc.ConnectRequest, resp rpc.Daemon_ConnectServer) (err error) {
cli := svr.GetClient(true)
if cli == nil {
return fmt.Errorf("sudo daemon not start")
}
Method Server.redirectToSudoDaemon
has 13 return statements (exceeds 4 allowed). Open
func (svr *Server) redirectToSudoDaemon(req *rpc.ConnectRequest, resp rpc.Daemon_ConnectServer) (e error) {
cli := svr.GetClient(true)
if cli == nil {
return fmt.Errorf("sudo daemon not start")
}
Method Server.Proxy
has 13 return statements (exceeds 4 allowed). Open
func (svr *Server) Proxy(req *rpc.ConnectRequest, resp rpc.Daemon_ProxyServer) (e error) {
defer func() {
util.InitLoggerForServer(true)
log.SetOutput(svr.LogFile)
config.Debug = false
Function handle
has 13 return statements (exceeds 4 allowed). Open
func handle(ctx context.Context, tcpConn net.Conn, udpConn *net.UDPConn) {
defer udpConn.Close()
log.Debugf("[TUN-UDP] %s <-> %s", tcpConn.RemoteAddr(), udpConn.LocalAddr())
errChan := make(chan error, 2)
go func() {
Function networkCancel
has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring. Open
func networkCancel() {
b, err := exec.Command("networksetup", "-listallnetworkservices").CombinedOutput()
if err != nil {
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 downloadAndInstall
has 56 lines of code (exceeds 50 allowed). Consider refactoring. Open
func downloadAndInstall(client *http.Client, url string) error {
temp, err := os.CreateTemp("", "*.zip")
if err != nil {
return err
}