Showing 1,904 of 1,904 total issues
Method Cluster.GetServices
has 6 return statements (exceeds 4 allowed). Open
func (c *Cluster) GetServices(options types.ServiceListOptions) ([]swarm.Service, error) {
c.mu.RLock()
defer c.mu.RUnlock()
state := c.currentNodeState()
Method sharedTempFileConverter.convert
has 6 return statements (exceeds 4 allowed). Open
func (c *sharedTempFileConverter) convert(f *os.File) (converted *os.File, size int64, err error) {
dst, err := os.CreateTemp(c.TempDir, "dockerdtemp.*")
if err != nil {
return nil, 0, err
}
Method reader.readJournal
has 6 return statements (exceeds 4 allowed). Open
func (r *reader) readJournal(ctx context.Context) error {
caughtUp := r.s.ordinal.Load()
if more, err := r.drainJournal(ctx); err != nil || !more {
return err
}
Method Daemon.getExecConfig
has 6 return statements (exceeds 4 allowed). Open
func (daemon *Daemon) getExecConfig(name string) (*container.ExecConfig, error) {
ec := daemon.execCommands.Get(name)
if ec == nil {
return nil, errExecNotFound(name)
}
Method Daemon.ContainerExport
has 6 return statements (exceeds 4 allowed). Open
func (daemon *Daemon) ContainerExport(ctx context.Context, name string, out io.Writer) error {
ctr, err := daemon.GetContainer(name)
if err != nil {
return err
}
Function newAWSLogsClient
has 6 return statements (exceeds 4 allowed). Open
func newAWSLogsClient(info logger.Info, configOpts ...func(*config.LoadOptions) error) (*cloudwatchlogs.Client, error) {
ctx := context.TODO()
var region, endpoint *string
if os.Getenv(regionEnvKey) != "" {
region = aws.String(os.Getenv(regionEnvKey))
Method Daemon.GetContainer
has 6 return statements (exceeds 4 allowed). Open
func (daemon *Daemon) GetContainer(prefixOrName string) (*container.Container, error) {
if len(prefixOrName) == 0 {
return nil, errors.WithStack(invalidIdentifier(prefixOrName))
}
Method Daemon.getInspectData
has 6 return statements (exceeds 4 allowed). Open
func (daemon *Daemon) getInspectData(daemonCfg *config.Config, container *container.Container) (*containertypes.ContainerJSONBase, error) {
// make a copy to play with
hostConfig := *container.HostConfig
children := daemon.children(container)
Function FilterNetworks
has 6 return statements (exceeds 4 allowed). Open
func FilterNetworks(nws []network.Inspect, filter filters.Args) ([]network.Inspect, error) {
// if filter is empty, return original network list
if filter.Len() == 0 {
return nws, nil
}
Function getEndpointPortMapInfo
has 6 return statements (exceeds 4 allowed). Open
func getEndpointPortMapInfo(ep *libnetwork.Endpoint) (nat.PortMap, error) {
pm := nat.PortMap{}
driverInfo, err := ep.DriverInfo()
if err != nil {
return pm, err
Function buildCreateEndpointOptions
has 6 return statements (exceeds 4 allowed). Open
func buildCreateEndpointOptions(c *container.Container, n *libnetwork.Network, epConfig *network.EndpointSettings, sb *libnetwork.Sandbox, daemonDNS []string) ([]libnetwork.EndpointOption, error) {
var createOptions []libnetwork.EndpointOption
genericOptions := make(options.Generic)
nwName := n.Name()
Method Daemon.ContainersPrune
has 6 return statements (exceeds 4 allowed). Open
func (daemon *Daemon) ContainersPrune(ctx context.Context, pruneFilters filters.Args) (*container.PruneReport, error) {
if !daemon.pruneRunning.CompareAndSwap(false, true) {
return nil, errPruneRunning
}
defer daemon.pruneRunning.Store(false)
Method ImageService.imageDeleteHelper
has 6 return statements (exceeds 4 allowed). Open
func (i *ImageService) imageDeleteHelper(imgID image.ID, records *[]imagetypes.DeleteResponse, force, prune, quiet bool) error {
// First, determine if this image has any conflicts. Ignore soft conflicts
// if force is true.
c := conflictHard
if !force {
Method ImageService.ImagesPrune
has 6 return statements (exceeds 4 allowed). Open
func (i *ImageService) ImagesPrune(ctx context.Context, pruneFilters filters.Args) (*imagetypes.PruneReport, error) {
if !i.pruneRunning.CompareAndSwap(false, true) {
return nil, errPruneRunning
}
defer i.pruneRunning.Store(false)
Method Daemon.Containers
has 6 return statements (exceeds 4 allowed). Open
func (daemon *Daemon) Containers(ctx context.Context, config *containertypes.ListOptions) ([]*containertypes.Summary, error) {
if err := config.Filters.Validate(acceptedPsFilterTags); err != nil {
return nil, err
}
Method Daemon.ContainerAttach
has 6 return statements (exceeds 4 allowed). Open
func (daemon *Daemon) ContainerAttach(prefixOrName string, req *backend.ContainerAttachConfig) error {
keys := []byte{}
var err error
if req.DetachKeys != "" {
keys, err = term.ToBytes(req.DetachKeys)
Method Daemon.initializeNetworking
has 6 return statements (exceeds 4 allowed). Open
func (daemon *Daemon) initializeNetworking(ctx context.Context, cfg *config.Config, ctr *container.Container) error {
if ctr.HostConfig.NetworkMode.IsContainer() {
// we need to get the hosts files from the container to join
nc, err := daemon.getNetworkedContainer(ctr.ID, ctr.HostConfig.NetworkMode.ConnectedContainer())
if err != nil {
Function doUnpackLayer
has 6 return statements (exceeds 4 allowed). Open
func doUnpackLayer(root string, layer io.Reader, options *archive.TarOptions) (int64, error) {
var result int64
optionsR, optionsW, err := os.Pipe()
if err != nil {
return 0, err
Function FrozenImagesLinux
has 6 return statements (exceeds 4 allowed). Open
func FrozenImagesLinux(ctx context.Context, client client.APIClient, images ...string) error {
ctx, span := otel.Tracer("").Start(ctx, "LoadFrozenImages")
defer span.End()
var loadImages []struct{ srcName, destName string }
Identical blocks of code found in 4 locations. Consider refactoring. Open
func (e ExperimentalMiddleware) WrapHandler(handler func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error) func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
w.Header().Set("Docker-Experimental", e.experimental)
return handler(ctx, w, r, vars)
}
- 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 110.
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