< Summary

Class:NotificationFactory
Assembly:NotificationHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NotificationHUD/NotificationFactory.cs
Covered lines:11
Uncovered lines:4
Coverable lines:15
Total lines:56
Line coverage:73.3% (11 of 15)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
EnsueFactoryDictionary()0%440100%
CreateNotificationFromType(...)0%64050%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NotificationHUD/NotificationFactory.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using UnityEngine;
 3using Type = DCL.NotificationModel.Type;
 4
 5public class NotificationFactory : ScriptableObject
 6{
 7    [System.Serializable]
 8    public class Item
 9    {
 10        public Type type;
 11        public Notification prefab;
 12    }
 13
 14    public Item[] factoryList;
 15
 16    private Dictionary<Type, Item> factoryDict;
 17
 18    public void EnsueFactoryDictionary()
 19    {
 420        if (factoryDict == null)
 21        {
 122            factoryDict = new Dictionary<Type, Item>();
 23
 1824            for (int i = 0; i < factoryList.Length; i++)
 25            {
 826                Item item = factoryList[i];
 27
 828                if (!factoryDict.ContainsKey(item.type))
 29                {
 830                    factoryDict.Add(item.type, item);
 31                }
 32            }
 33        }
 434    }
 35
 36    public Notification CreateNotificationFromType(Type type, Transform parent = null)
 37    {
 438        EnsueFactoryDictionary();
 39
 440        if (!factoryDict.ContainsKey(type))
 41        {
 42#if UNITY_EDITOR
 043            Debug.LogError("Notification of type " + type + " can't be instantiated because it does not exist in the fac
 44#endif
 045            return null;
 46        }
 47
 448        if (factoryDict[type].prefab == null)
 49        {
 050            Debug.LogError("Prefab for type " + type + " is null!");
 051            return null;
 52        }
 53
 454        return parent == null ? Instantiate(factoryDict[type].prefab) : Instantiate(factoryDict[type].prefab, parent);
 55    }
 56}