< Summary

Information
Class: Spdx3.Utility.Naming
Assembly: Spdx3
File(s): /home/runner/work/Spdx3/Spdx3/Spdx3/Utility/Naming.cs
Line coverage
97%
Covered lines: 33
Uncovered lines: 1
Coverable lines: 34
Total lines: 66
Line coverage: 97%
Branch coverage
96%
Covered branches: 27
Total branches: 28
Branch coverage: 96.4%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
ClassNameForSpdxType(...)95%202091.66%
SpdxTypeForClass(...)100%88100%

File(s)

/home/runner/work/Spdx3/Spdx3/Spdx3/Utility/Naming.cs

#LineLine coverage
 1using Spdx3.Exceptions;
 2
 3namespace Spdx3.Utility;
 4
 5public static class Naming
 6{
 17    private static readonly Dictionary<string, string> PrefixesForNamespaces = new()
 18    {
 19        { "Model.Core", "" },
 110        { "Model.Security", "security_" },
 111        { "Model.Software", "software_" },
 112        { "Model.Licensing", "licensing_" },
 113        { "Model.SimpleLicensing", "simplelicensing_" },
 114        { "Model.ExpandedLicensing", "expandedlicensing_" },
 115        { "Model.Dataset", "dataset_" },
 116        { "Model.AI", "ai_" },
 117        { "Model.Build", "build_" },
 118        { "Model.Lite", "lite_" },
 119        { "Model.Extension", "extension_" }
 120    };
 21
 22    public static string ClassNameForSpdxType(Dictionary<string, object> hashTable)
 23    {
 5924        var spdxType = (string)hashTable[hashTable.ContainsKey("type") ? "type" : "@type"];
 25
 5926        if (spdxType == "NoAssertionElement" || spdxType == "NoneElement" || spdxType == "SpdxOrganization")
 27        {
 328            return $"Spdx3.Model.Core.Individuals.{spdxType}";
 29        }
 30
 5631        if (spdxType == "NoneLicense" || spdxType == "NoAssertionLicense")
 32        {
 233            return $"Spdx3.Model.ExpandedLicensing.Individuals.{spdxType}";
 34        }
 35
 5436        if (!spdxType.Contains('_'))
 37        {
 3938            return $"Spdx3.Model.Core.Classes.{spdxType}";
 39        }
 40
 4541        foreach (var prefix in PrefixesForNamespaces.Where(prefix =>
 9342                     !string.IsNullOrWhiteSpace(prefix.Value) && spdxType.StartsWith(prefix.Value)))
 43        {
 1544            return $"Spdx3.{prefix.Key}.Classes.{spdxType[prefix.Value.Length..]}";
 45        }
 46
 047        throw new Spdx3SerializationException($"Unable to determine class type for node of Type={spdxType}");
 1548    }
 49
 50    public static string SpdxTypeForClass(Type classType)
 51    {
 113852        if (classType.Namespace == null)
 53        {
 154            throw new Spdx3Exception($"Unable to determine SPDX3 node type value for {classType.FullName}");
 55        }
 56
 341057        foreach (var prefix in PrefixesForNamespaces.Keys.Where(prefix =>
 338358                     classType.Namespace.StartsWith($"Spdx3.{prefix}") ||
 338359                     classType.Namespace.StartsWith($"Spdx3.Tests.{prefix}")))
 60        {
 113661            return $"{PrefixesForNamespaces[prefix]}{classType.Name}";
 62        }
 63
 164        throw new Spdx3Exception($"Unable to determine SPDX3 node type value for {classType.FullName}");
 113665    }
 66}