Cloning and Duplication

Concept

Cloning and Duplication KPI intends to focus on the code that should be reworked. It basically addresses architecture design and implementation. The KPI is computed thanks to Squore Analyzer metrics. These metrics highlight duplicated block and similar algorithms.

Algorithmic Cloning Vs Duplication

Duplication is directly computed from the source code textual analysis. Cloning on the other hand is related to the source code algorithm analysis.

The analyzer can generate both metrics and findings related to cloning and duplication. The quality model embeds 2 indicators: Inner Cloning and Outer Cloning.

  • Inner (or Internal) Cloning is related to cloning within the artefact ⇒ is the artefact well-designed?

  • Outer (or External) Cloning is related to cloning outside the artefact ⇒ is the artefact cloned with another artefact?

SWAN cloning concept
Figure 1. Cloning - Overview

Metrics

The analyzer produces the following metrics:

  • ICC = Inner Cloned Code = Number of duplicated line of code within the artefact

  • CC = Cloned Code = Number of duplicated line of code outside the artefact

From these information the Inner and Outer cloning ratio can be computed

  • ICCR = 100 * (ICC/LC)

  • CCR = 100 * (CC/LC)

Findings

In order to help find cloning and or duplication instances, Squore generates findings that are reachable from the findings tab.

  • R_NOCFTC - No Algorithmic Cloning

  • R_NOCC - No Code Cloning

  • R_NORS - No Repeated Substrings (Block duplication)

  • R_NOCAC - Consider re-factorization (Artifacts contains too many clones)

Example:

SWAN cloning findings
Figure 2. Cloning - Findings