From f742ff44945748dcfc170c86cf335949d279c91c Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE Date: Mon, 12 Jun 2023 21:37:52 +0200 Subject: [PATCH] Fix code smells --- Sources/Model/Manager.cs | 7 +- Sources/Model/Playlist.cs | 4 +- .../Serialization/LINQ_XML_Serialization.cs | 109 +++++------------- 3 files changed, 36 insertions(+), 84 deletions(-) diff --git a/Sources/Model/Manager.cs b/Sources/Model/Manager.cs index 7b89662..2099804 100644 --- a/Sources/Model/Manager.cs +++ b/Sources/Model/Manager.cs @@ -428,12 +428,9 @@ namespace Model.Stub foreach(Playlist p in DataManager.GetPlaylists()) { List ToDelete = new(); - foreach (CustomTitle ct in p.Titles) + foreach (CustomTitle ct in p.Titles.Where(ct => ct.Equals(title))) { - if (ct.Equals(title)) - { - ToDelete.Add(ct); - } + ToDelete.Add(ct); } foreach(CustomTitle ct in ToDelete) { diff --git a/Sources/Model/Playlist.cs b/Sources/Model/Playlist.cs index 4fbd0c0..206ad55 100644 --- a/Sources/Model/Playlist.cs +++ b/Sources/Model/Playlist.cs @@ -314,9 +314,9 @@ namespace Model /// Booléen True si le CustomTitle est contenu dans la Playlist, False sinon public bool HasCustomTitle(CustomTitle customTitle) { - foreach (CustomTitle custom in Titles) + foreach (CustomTitle custom in Titles.Where(ct => ct.Equals(customTitle))) { - if (custom.Equals(customTitle)) return true; + return true; } return false; } diff --git a/Sources/Model/Serialization/LINQ_XML_Serialization.cs b/Sources/Model/Serialization/LINQ_XML_Serialization.cs index 126d692..c6b1570 100644 --- a/Sources/Model/Serialization/LINQ_XML_Serialization.cs +++ b/Sources/Model/Serialization/LINQ_XML_Serialization.cs @@ -479,12 +479,9 @@ namespace Model.Serialization /// Retourne l'objet InfoTitle avec un nom équivalent à celui donné en paramètre public InfoTitle GetInfoTitleByName(string name) { - foreach (InfoTitle it in infoTitles) + foreach (InfoTitle it in infoTitles.Where(it => it.Name.Equals(name))) { - if (it.Name.Equals(name)) - { - return it; - } + return it; } return null; } @@ -496,12 +493,9 @@ namespace Model.Serialization /// Retourne l'objet Artist avec un nom équivalent à celui donné en paramètre public Artist GetArtistByName(string name) { - foreach (Artist a in artists) + foreach (Artist a in artists.Where(artist => artist.Name.Equals(name))) { - if (a.Name.Equals(name)) - { - return a; - } + return a; } return null; } @@ -513,12 +507,9 @@ namespace Model.Serialization /// Retourne l'objet Album avec un nom équivalent à celui donné en paramètre public Album GetAlbumByName(string name) { - foreach (Album a in albums) + foreach (Album a in albums.Where(a => a.Name.Equals(name))) { - if (a.Name.Equals(name)) - { - return a; - } + return a; } return null; } @@ -530,9 +521,9 @@ namespace Model.Serialization /// Retourne l'objet Album avec un ID équivalent à celui donné en paramètre public Album GetAlbumById(long id) { - foreach (Album a in albums) + foreach (Album a in albums.Where(a => a.ID == id)) { - if (a.ID == id) return a; + return a; } return null; } @@ -544,12 +535,9 @@ namespace Model.Serialization /// Retourne l'objet CustomTitle avec un chemin d'accès équivalent à celui donné en paramètre public CustomTitle GetCustomTitleByPath(string custom) { - foreach (CustomTitle customTitle in customTitles) + foreach (CustomTitle customTitle in customTitles.Where(customTitle => customTitle.Path.Equals(custom))) { - if (customTitle.Path.Equals(custom)) - { - return customTitle; - } + return customTitle; } return null; } @@ -621,12 +609,9 @@ namespace Model.Serialization /// Retourne l'objet Playlist avec un nom équivalent à celui donné en paramètre public Playlist GetPlaylistByName(string name) { - foreach (Playlist p in playlists) + foreach (Playlist p in playlists.Where(p => p.Name.Equals(name))) { - if (p.Name.Equals(name)) - { - return p; - } + return p; } return null; } @@ -916,12 +901,9 @@ namespace Model.Serialization /// Booléen True s'il est contenu dans l'application, False sinon public bool ExistsPlaylist(Playlist playlist) { - foreach (Playlist p in playlists) + foreach (Playlist p in playlists.Where(p => p.Equals(playlist))) { - if (p.Equals(playlist)) - { - return true; - } + return true; } return false; } @@ -933,12 +915,9 @@ namespace Model.Serialization /// Booléen True s'il est contenu dans l'application, False sinon public bool ExistsPlaylistByName(string name) { - foreach (Playlist p in playlists) + foreach (Playlist p in playlists.Where(p => p.Name.Equals(name))) { - if (p.Name.Equals(name)) - { - return true; - } + return true; } return false; } @@ -950,12 +929,9 @@ namespace Model.Serialization /// Booléen True s'il est contenu dans l'application, False sinon public bool ExistsAlbum(Album album) { - foreach (Album a in albums) + foreach (Album a in albums.Where(a => a.Equals(album))) { - if (a.Equals(album)) - { - return true; - } + return true; } return false; } @@ -967,12 +943,9 @@ namespace Model.Serialization /// Booléen True s'il est contenu dans l'application, False sinon public bool ExistsAlbumByName(string name) { - foreach (Album a in albums) + foreach (Album a in albums.Where(a => a.Name.Equals(name))) { - if (a.Name.Equals(name)) - { - return true; - } + return true; } return false; } @@ -984,12 +957,9 @@ namespace Model.Serialization /// Booléen True s'il est contenu dans l'application, False sinon public bool ExistsArtist(Artist artist) { - foreach (Artist a in artists) + foreach (Artist a in artists.Where(a => a.Equals(artist))) { - if (a.Equals(artist)) - { - return true; - } + return true; } return false; } @@ -1001,12 +971,9 @@ namespace Model.Serialization /// Booléen True s'il est contenu dans l'application, False sinon public bool ExistsArtistByName(string name) { - foreach (Artist a in artists) + foreach (Artist a in artists.Where(a => a.Name.Equals(name))) { - if (a.Name.Equals(name)) - { - return true; - } + return true; } return false; } @@ -1018,12 +985,9 @@ namespace Model.Serialization /// Booléen True s'il est contenu dans l'application, False sinon public bool ExistsCustomTitle(CustomTitle title) { - foreach (CustomTitle ct in customTitles) + foreach (CustomTitle ct in customTitles.Where(ct => title.Equals(ct))) { - if (title.Equals(ct)) - { - return true; - } + return true; } return false; } @@ -1035,12 +999,9 @@ namespace Model.Serialization /// Booléen True s'il est contenu dans l'application, False sinon public bool ExistsCustomTitleByName(string name) { - foreach (CustomTitle ct in customTitles) + foreach (CustomTitle ct in customTitles.Where(ct => ct.Name.Equals(name))) { - if (ct.Name.Equals(name)) - { - return true; - } + return true; } return false; } @@ -1052,12 +1013,9 @@ namespace Model.Serialization /// Booléen True s'il est contenu dans l'application, False sinon public bool ExistsInfoTitle(InfoTitle title) { - foreach (InfoTitle it in infoTitles) + foreach (InfoTitle it in infoTitles.Where(it => it.Equals(title))) { - if (it.Equals(title)) - { - return true; - } + return true; } return false; } @@ -1069,12 +1027,9 @@ namespace Model.Serialization /// Booléen True s'il est contenu dans l'application, False sinon public bool ExistsInfoTitleByName(string name) { - foreach (InfoTitle it in infoTitles) + foreach (InfoTitle it in infoTitles.Where(it => it.Name.Equals(name))) { - if (it.Name.Equals(name)) - { - return true; - } + return true; } return false; }