Showing 1,904 of 1,904 total issues
Similar blocks of code found in 2 locations. Consider refactoring. Open
NetworkSettingsBase: containertypes.NetworkSettingsBase{
Bridge: ctr.NetworkSettings.Bridge,
SandboxID: ctr.NetworkSettings.SandboxID,
SandboxKey: ctr.NetworkSettings.SandboxKey,
HairpinMode: ctr.NetworkSettings.HairpinMode,
- 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 112.
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 Push
has 6 return statements (exceeds 4 allowed). Open
func Push(ctx context.Context, ref reference.Named, config *ImagePushConfig) error {
// FIXME: Allow to interrupt current push when new push of same image is done.
// Resolve the Repository name from fqn to RepositoryInfo
repoInfo, err := config.RegistryService.ResolveRepository(ref)
Consider simplifying this complex logical expression. Open
if p.OS == "" && p.Architecture == "" && p.Variant == "" && p.OSVersion == "" && p.OSFeatures == nil && p.Features == nil {
Function checkValidParent
has 6 return statements (exceeds 4 allowed). Open
func checkValidParent(img, parent *image.Image) bool {
if len(img.History) == 0 && len(parent.History) == 0 {
return true // having history is not mandatory
}
if len(img.History)-len(parent.History) != 1 {
Function fixManifestLayers
has 6 return statements (exceeds 4 allowed). Open
func fixManifestLayers(m *schema1.Manifest) error {
imgs := make([]*image.V1Image, len(m.FSLayers))
for i := range m.FSLayers {
img := &image.V1Image{}
Method pushDescriptor.uploadUsingSession
has 6 return statements (exceeds 4 allowed). Open
func (pd *pushDescriptor) uploadUsingSession(
ctx context.Context,
progressOutput progress.Output,
diffID layer.DiffID,
layerUpload distribution.BlobWriter,
Method Manager.Remove
has 6 return statements (exceeds 4 allowed). Open
func (pm *Manager) Remove(name string, config *backend.PluginRmConfig) error {
p, err := pm.config.Store.GetV2Plugin(name)
pm.mu.RLock()
c := pm.cMap[p]
pm.mu.RUnlock()
Function verifySchema1Manifest
has 6 return statements (exceeds 4 allowed). Open
func verifySchema1Manifest(signedManifest *schema1.SignedManifest, ref reference.Reference) (m *schema1.Manifest, err error) {
// If pull by digest, then verify the manifest digest. NOTE: It is
// important to do this first, before any other content validation. If the
// digest cannot be verified, don't even bother with those other things.
if digested, isCanonical := ref.(reference.Canonical); isCanonical {
Function pullEndpoints
has 6 return statements (exceeds 4 allowed). Open
func pullEndpoints(ctx context.Context, registryService RegistryResolver, ref reference.Named,
f func(context.Context, registry.RepositoryInfo, registry.APIEndpoint) error,
) (*registry.RepositoryInfo, error) {
// Resolve the Repository name from fqn to RepositoryInfo
repoInfo, err := registryService.ResolveRepository(ref)
Method puller.pullRepository
has 6 return statements (exceeds 4 allowed). Open
func (p *puller) pullRepository(ctx context.Context, ref reference.Named) (err error) {
var layersDownloaded bool
if !reference.IsNameOnly(ref) {
layersDownloaded, err = p.pullTag(ctx, ref, p.config.Platform)
if err != nil {
Function parseTCPAddr
has 6 return statements (exceeds 4 allowed). Open
func parseTCPAddr(address string, strict bool) (*url.URL, error) {
if !strict && !strings.Contains(address, "://") {
address = "tcp://" + address
}
parsedURL, err := url.Parse(address)
Method pusher.pushRepository
has 6 return statements (exceeds 4 allowed). Open
func (p *pusher) pushRepository(ctx context.Context) (err error) {
if namedTagged, isNamedTagged := p.ref.(reference.NamedTagged); isNamedTagged {
imageID, err := p.config.ReferenceStore.Get(p.ref)
if err != nil {
return fmt.Errorf("tag does not exist: %s", reference.FamiliarString(p.ref))
Method Sandbox.SetKey
has 6 return statements (exceeds 4 allowed). Open
func (sb *Sandbox) SetKey(ctx context.Context, basePath string) error {
start := time.Now()
defer func() {
log.G(ctx).Debugf("sandbox set key processing took %s for container %s", time.Since(start), sb.ContainerID())
}()
Method EndpointInterface.UnmarshalJSON
has 6 return statements (exceeds 4 allowed). Open
func (epi *EndpointInterface) UnmarshalJSON(b []byte) error {
var (
err error
epMap map[string]interface{}
)
Method Controller.handleKeyChange
has 6 return statements (exceeds 4 allowed). Open
func (c *Controller) handleKeyChange(keys []*types.EncryptionKey) error {
drvEnc := discoverapi.DriverEncryptionUpdate{}
agent := c.getAgent()
if agent == nil {
Method Sandbox.clearNetworkResources
has 6 return statements (exceeds 4 allowed). Open
func (sb *Sandbox) clearNetworkResources(origEp *Endpoint) error {
ep := sb.GetEndpoint(origEp.id)
if ep == nil {
return fmt.Errorf("could not find the sandbox endpoint data for endpoint %s",
origEp.id)
Method Endpoint.Delete
has 6 return statements (exceeds 4 allowed). Open
func (ep *Endpoint) Delete(ctx context.Context, force bool) error {
var err error
n, err := ep.getNetworkFromStore()
if err != nil {
return fmt.Errorf("failed to get network during Delete: %v", err)
Method IPAMData.UnmarshalJSON
has 6 return statements (exceeds 4 allowed). Open
func (i *IPAMData) UnmarshalJSON(data []byte) error {
var (
m map[string]interface{}
err error
)
Method Endpoint.deleteServiceInfoFromCluster
has 6 return statements (exceeds 4 allowed). Open
func (ep *Endpoint) deleteServiceInfoFromCluster(sb *Sandbox, fullRemove bool, method string) error {
if len(ep.dnsNames) == 0 {
return nil
}
Method Namespace.AddNeighbor
has 6 return statements (exceeds 4 allowed). Open
func (n *Namespace) AddNeighbor(dstIP net.IP, dstMac net.HardwareAddr, force bool, options ...NeighOption) error {
var (
iface netlink.Link
err error
neighborAlreadyPresent bool