< Summary

Class:DCL.SettingsCommon.PlayerPrefsSettingsByKey
Assembly:Settings
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Settings/PlayerPrefsSettingsByKey.cs
Covered lines:18
Uncovered lines:3
Coverable lines:21
Total lines:73
Line coverage:85.7% (18 of 21)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PlayerPrefsSettingsByKey(...)0%2100%
GetEnum[T](...)0%220100%
GetBool(...)0%110100%
GetFloat(...)0%110100%
GetInt(...)0%110100%
GetString(...)0%110100%
SetBool(...)0%110100%
SetFloat(...)0%110100%
SetEnum[T](...)0%110100%
SetInt(...)0%110100%
SetString(...)0%110100%
GetFieldKey(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Settings/PlayerPrefsSettingsByKey.cs

#LineLine coverage
 1using System;
 2using DCL.Helpers;
 3using UnityEngine;
 4
 5namespace DCL.SettingsCommon
 6{
 7    public class PlayerPrefsSettingsByKey : IPlayerPrefsSettingsByKey
 8    {
 9        private readonly string prefixPrefsKey;
 10
 011        public PlayerPrefsSettingsByKey(string prefixPrefsKey)
 12        {
 013            this.prefixPrefsKey = prefixPrefsKey;
 014        }
 15
 16        public T GetEnum<T>(string fieldName, T defaultValue) where T : struct
 17        {
 384018            if (!Enum.TryParse<T>(PlayerPrefs.GetString(GetFieldKey(fieldName), ""), out var result))
 204619                return defaultValue;
 179420            return result;
 21        }
 22
 23        public bool GetBool(string fieldName, bool defaultValue)
 24        {
 576025            return PlayerPrefsUtils.GetBool(GetFieldKey(fieldName), defaultValue);
 26        }
 27
 28        public float GetFloat(string fieldName, float defaultValue)
 29        {
 1152030            return PlayerPrefs.GetFloat(GetFieldKey(fieldName), defaultValue);
 31        }
 32
 33        public int GetInt(string fieldName, int defaultValue)
 34        {
 64035            return PlayerPrefs.GetInt(GetFieldKey(fieldName), defaultValue);
 36        }
 37
 38        public string GetString(string fieldName, string defaultValue)
 39        {
 64040            return PlayerPrefs.GetString(GetFieldKey(fieldName), defaultValue);
 41        }
 42
 43        public void SetBool(string fieldName, bool value)
 44        {
 945            PlayerPrefsUtils.SetBool(GetFieldKey(fieldName), value);
 946        }
 47
 48        public void SetFloat(string fieldName, float value)
 49        {
 1850            PlayerPrefs.SetFloat(GetFieldKey(fieldName), value);
 1851        }
 52
 53        public void SetEnum<T>(string fieldName, T value) where T : struct
 54        {
 655            PlayerPrefs.SetString(GetFieldKey(fieldName), value.ToString());
 656        }
 57
 58        public void SetInt(string fieldName, int value)
 59        {
 160            PlayerPrefs.SetInt(GetFieldKey(fieldName), value);
 161        }
 62
 63        public void SetString(string fieldName, string value)
 64        {
 165            PlayerPrefs.SetString(GetFieldKey(fieldName), value);
 166        }
 67
 68        private string GetFieldKey(string fieldName)
 69        {
 2243570            return $"{prefixPrefsKey}.{fieldName}";
 71        }
 72    }
 73}