From 0e7f6e2f4ac08d29e58a6a9249d29176274b0b45 Mon Sep 17 00:00:00 2001 From: "matheo.thierry" Date: Wed, 24 May 2023 22:07:43 +0200 Subject: [PATCH] fix by sonar code smell --- notus/Biblioteque_de_Class/Exception.cs | 11 +++++++++++ notus/Biblioteque_de_Class/Note.cs | 8 ++++---- notus/Biblioteque_de_Class/PersistenceManager.cs | 2 +- notus/Biblioteque_de_Class/Theme.cs | 2 +- notus/Notus_Persistence/ToJSON.cs | 11 +++++------ 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/notus/Biblioteque_de_Class/Exception.cs b/notus/Biblioteque_de_Class/Exception.cs index b37c3e4..a074c57 100644 --- a/notus/Biblioteque_de_Class/Exception.cs +++ b/notus/Biblioteque_de_Class/Exception.cs @@ -30,4 +30,15 @@ namespace Biblioteque_de_Class { } } + + + + + + public class FileException : Exception + { + public FileException(string message) : base(message) + { + } + } } diff --git a/notus/Biblioteque_de_Class/Note.cs b/notus/Biblioteque_de_Class/Note.cs index 2d072e1..6f00e18 100644 --- a/notus/Biblioteque_de_Class/Note.cs +++ b/notus/Biblioteque_de_Class/Note.cs @@ -25,11 +25,11 @@ namespace Biblioteque_de_Class private DateOnly CreationDate { get; } private DateOnly ModificationDate { get; set; } - private List ImageList; + private readonly List ImageList; private string TextLine; - private List Collaborators; - private List Editors; - private User Owner; + private readonly List Collaborators; + private readonly List Editors; + private readonly User Owner; public Note(string name, string logoPath, User owner) { diff --git a/notus/Biblioteque_de_Class/PersistenceManager.cs b/notus/Biblioteque_de_Class/PersistenceManager.cs index 9e943ae..dbe388f 100644 --- a/notus/Biblioteque_de_Class/PersistenceManager.cs +++ b/notus/Biblioteque_de_Class/PersistenceManager.cs @@ -4,7 +4,7 @@ namespace Biblioteque_de_Class { public class PersistenceManager { - private IManager persistence; + private readonly IManager persistence; public PersistenceManager(IManager pers) { diff --git a/notus/Biblioteque_de_Class/Theme.cs b/notus/Biblioteque_de_Class/Theme.cs index c4d2340..6a6f54a 100644 --- a/notus/Biblioteque_de_Class/Theme.cs +++ b/notus/Biblioteque_de_Class/Theme.cs @@ -9,7 +9,7 @@ namespace Biblioteque_de_Class public class Theme { private string Name { get; set; } - private List ColorList; + private readonly List ColorList; public Theme(string name, List colorList) { diff --git a/notus/Notus_Persistence/ToJSON.cs b/notus/Notus_Persistence/ToJSON.cs index 9ff522a..23987ef 100644 --- a/notus/Notus_Persistence/ToJSON.cs +++ b/notus/Notus_Persistence/ToJSON.cs @@ -37,23 +37,22 @@ namespace Notus_Persistance { if (File.Exists(DatabaseDataFilePath)) { - Database database1; using (FileStream fileStream = File.OpenRead(DatabaseDataFilePath)) { Database? database = (Database?)DatabasejsonSerializer.ReadObject(fileStream); if (database == null) { - throw new Exception("Failed to load database. The loaded object is null."); + throw new FileException("Failed to load database. The loaded object is null."); } else { - return database1 = database; + return database; } } } else { - throw new Exception("No data file found."); + throw new FileException("No data file found."); } } @@ -82,7 +81,7 @@ namespace Notus_Persistance User? user = (User?)UserjsonSerializer.ReadObject(fileStream); if (user == null) { - throw new Exception("Failed to load database. The loaded object is null."); + throw new FileException("Failed to load database. The loaded object is null."); } else { @@ -92,7 +91,7 @@ namespace Notus_Persistance } else { - throw new Exception("No userfile find"); + throw new FileException("No userfile find"); } } }