From 4d98ec337e5d27b30078ebbe733f2f8033198431 Mon Sep 17 00:00:00 2001 From: Jade_VAN_BRABANDT Date: Tue, 6 Jun 2023 17:56:20 +0200 Subject: [PATCH] Fix : Code smells --- Sources/Stim.Model/Game.cs | 12 ++++++------ Sources/Stim.Model/Manager.cs | 4 ++-- Sources/Stim.Model/User.cs | 34 +++++++++++++++++----------------- Sources/Stim/Create.xaml.cs | 10 +++++----- Sources/Stub/Stub.cs | 9 ++------- 5 files changed, 32 insertions(+), 37 deletions(-) diff --git a/Sources/Stim.Model/Game.cs b/Sources/Stim.Model/Game.cs index 3dcd37c..9cde10f 100644 --- a/Sources/Stim.Model/Game.cs +++ b/Sources/Stim.Model/Game.cs @@ -23,7 +23,7 @@ namespace Model } } } - private string name; + private string name = default!; [DataMember] public string Description @@ -39,7 +39,7 @@ namespace Model } } } - private string description; + private string description = default!; [DataMember] public int Year @@ -55,7 +55,7 @@ namespace Model } } } - private int year; + private int year = default!; [DataMember] public string Cover @@ -71,7 +71,7 @@ namespace Model } } } - private string cover; + private string cover = default!; [DataMember] public ObservableCollection Tags @@ -87,7 +87,7 @@ namespace Model } } } - private ObservableCollection tags; + private ObservableCollection tags = default!; [DataMember] public List Reviews { get; private init; } @@ -112,7 +112,7 @@ namespace Model } } } - private string lien; + private string lien = default!; public Game(string name, string description, int year, List c_tags, string cover, string c_lien) { diff --git a/Sources/Stim.Model/Manager.cs b/Sources/Stim.Model/Manager.cs index 61e2ad3..99c8552 100644 --- a/Sources/Stim.Model/Manager.cs +++ b/Sources/Stim.Model/Manager.cs @@ -27,10 +27,10 @@ namespace Model .Where(game => game.Name.IndexOf(filterName, StringComparison.OrdinalIgnoreCase) >= 0 ); if (filterTag1 != null) retList = retList - .Where(game => game.Tags != null && game.Tags.Any(tag => tag != null && tag.IndexOf(filterTag1, StringComparison.OrdinalIgnoreCase) >= 0) + .Where(game => game.Tags != null && game.Tags.Any(tag => tag != null && tag.Contains(filterTag1, StringComparison.OrdinalIgnoreCase)) ); if (filterTag2 != null) retList = retList - .Where(game => game.Tags != null && game.Tags.Any(tag => tag != null && tag.IndexOf(filterTag2, StringComparison.OrdinalIgnoreCase) >= 0) + .Where(game => game.Tags != null && game.Tags.Any(tag => tag != null && tag.Contains(filterTag2, StringComparison.OrdinalIgnoreCase)) ); return retList; } diff --git a/Sources/Stim.Model/User.cs b/Sources/Stim.Model/User.cs index 10b5a63..d26d83c 100644 --- a/Sources/Stim.Model/User.cs +++ b/Sources/Stim.Model/User.cs @@ -10,6 +10,17 @@ namespace Model [DataContract] public sealed class User : INotifyPropertyChanged , IEquatable { + [DataMember] + public string UserImage + { + get => userImage; + private set + { + if (!string.IsNullOrWhiteSpace(value)) userImage = value; + else userImage = "no_cover.png"; + } + } + private string userImage = default!; [DataMember] public string? Username { @@ -24,11 +35,11 @@ namespace Model } } } - private string username; + private string username=default!; [DataMember] public string Biographie { - get => biographie ?? "Pas de biographie"; + get => biographie; private set { if (string.IsNullOrWhiteSpace(value)) biographie = "Pas de biographie"; @@ -39,7 +50,7 @@ namespace Model } } } - private string biographie; + private string biographie = default!; [DataMember] public string Email { @@ -55,7 +66,7 @@ namespace Model else email = "Default"; } } - private string email; + private string email = default!; [DataMember] public string Password { @@ -71,7 +82,7 @@ namespace Model } } } - private string password; + private string password = default!; public event PropertyChangedEventHandler? PropertyChanged; @@ -89,17 +100,6 @@ namespace Model get; private init; } - [DataMember] - public string? UserImage - { - get => userImage; - private set - { - if (!string.IsNullOrWhiteSpace(value)) userImage = value; - else userImage = "no_cover.png"; - } - } - private string? userImage; public User(string userImage,string username, string biographie, string email, string password) { @@ -111,7 +111,7 @@ namespace Model else Biographie = biographie; if (email == null) Email = "Default"; else Email = email; - if (password == null) throw new ArgumentNullException("password"); + if (password == null) throw new ArgumentNullException(nameof(password)); else Password = password; Followed_Games = new ObservableCollection(); } diff --git a/Sources/Stim/Create.xaml.cs b/Sources/Stim/Create.xaml.cs index b317763..ebda9ff 100644 --- a/Sources/Stim/Create.xaml.cs +++ b/Sources/Stim/Create.xaml.cs @@ -12,15 +12,15 @@ public partial class Create : ContentPage private async void Creer_un_compte(object sender, EventArgs e) { Error.Clear(); - if (!string.IsNullOrWhiteSpace(Username.Text) || !string.IsNullOrWhiteSpace(Pswd.Text) || !string.IsNullOrWhiteSpace(Email.Text)) + if (!(string.IsNullOrWhiteSpace(Username.Text) || string.IsNullOrWhiteSpace(Pswd.Text) || string.IsNullOrWhiteSpace(Email.Text))) { if (((App)App.Current).Manager.SearchUser(Username.Text) == null) { - Regex rg = new Regex("^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$"); - if (rg.IsMatch(Email.Text)) + GeneratedRegexAttribute rg = new GeneratedRegexAttribute("^([a-zA-Z0-9_.])+@([a-zA-Z0-9_]+[.])+[a-zA-Z0-9_]{2,}$"); + if (rg.Match(Email.Text)) { - rg = new Regex("^(?=.*[A-Za-z])(?=.*[0-9@$!%*#?&])[A-Za-z-0-9@$!%*#?&]{8,}$"); - if (rg.IsMatch(Pswd.Text)) + rg = new GeneratedRegexAttribute("^(?=.*[A-Za-z])(?=.*[0-9@$!%*#?&])[A-Za-z-0-9@$!%*#?&]{8,}$"); + if (rg.Match(Pswd.Text)) { ((App)App.Current).Manager.AddUsertoUserList(new("", Username.Text, "", Email.Text, Pswd.Text)); ((App)App.Current).Manager.CurrentUser = ((App)App.Current).Manager.SearchUser(Username.Text); diff --git a/Sources/Stub/Stub.cs b/Sources/Stub/Stub.cs index 8f7db88..46a5260 100644 --- a/Sources/Stub/Stub.cs +++ b/Sources/Stub/Stub.cs @@ -7,16 +7,11 @@ namespace StimStub [ExcludeFromCodeCoverage] public class Stub : IPersistance { - public List Games - { - get { return games; } - set { games = value; } - } - private List games; + public List Games { get; set; } public Stub() { - Games = LoadGame(); + Games = LoadGame() ?? new(); } public void SaveGame(List games)