SonarQube has detected duplicate functions in specific lines:
- beneficiaires.forEach(beneficiaire => {
- () => {
Below are the identified functions:
affectPercentageToBeneficiares(beneficiaires: BeneficiaryData[], sum: number) {
let numberOfBeneficiaresWithEmptyPrecentage = this.getBeneficiaresWithEmptyPercentageNumber(beneficiaires);
let valueToAffecte = (100.02 - sum) / numberOfBeneficiaresWithEmptyPrecentage;
beneficiaires.forEach(beneficiaire => {
if (beneficiaire.percentage == "") {
valueToAffecte = Math.round(valueToAffecte * 100) / 100;
beneficiaire.percentage = "" + valueToAffecte;
}
})
}
affectPercentageToBeneficiaresInZeroCase(beneficiaires: BeneficiaryData[]) {
let numberOfBeneficiaresWithEmptyPrecentage = this.getBeneficiaresWithEmptyPercentageNumber(beneficiaires);
let valueToAffecte = (100) / numberOfBeneficiaresWithEmptyPrecentage;
beneficiaires.forEach(beneficiaire => {
if (beneficiaire.percentage == "") {
valueToAffecte = Math.round(valueToAffecte * 100) / 100;
beneficiaire.percentage = "" + valueToAffecte;
}
});
}
this.userProfilService.updateUser(this.UpdatedUser)
.subscribe(
() => {
this.toastr.success('User has been updated successfully', null, {
enableHtml: true,
});
},
(err) => {
this.toastr.error('erreur dans la modification utilisateur', null, {
enableHtml: true,
});
}
);
this.userProfilService.addUser(this.User)
.subscribe(
() => {
this.toastr.success('User has been created', null, {
enableHtml: true,
});
},
(err) => {
throw err;
}
);
Is there a way to resolve the issue with the duplicate functions without merging them?
Thank you