< Summary

Class:DCLServices.WearablesCatalogService.ExtendedUrnParser
Assembly:WearablesCatalogService
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/WearablesCatalogService/ExtendedUrnParser.cs
Covered lines:8
Uncovered lines:9
Coverable lines:17
Total lines:55
Line coverage:47% (8 of 17)
Covered branches:0
Total branches:0
Covered methods:2
Total methods:3
Method coverage:66.6% (2 of 3)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GetShortenedUrn(...)0%39.048021.43%
CountParts(...)0%220100%
IsThirdPartyCollection(...)0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/WearablesCatalogService/ExtendedUrnParser.cs

#LineLine coverage
 1namespace DCLServices.WearablesCatalogService
 2{
 3    public static class ExtendedUrnParser
 4    {
 5        private const int REGULAR_NFTS_SHORT_PARTS = 6;
 6        private const int THIRD_PARTY_V2_SHORTEN_URN_PARTS = 7;
 7        private const string COLLECTIONS_THIRD_PARTY = "collections-thirdparty";
 8
 9        public static string GetShortenedUrn(string urnReceived)
 10        {
 11411            if (string.IsNullOrEmpty(urnReceived)) return urnReceived;
 22812            if (CountParts(urnReceived) <= REGULAR_NFTS_SHORT_PARTS) return urnReceived;
 13
 14            int index;
 15
 016            if (IsThirdPartyCollection(urnReceived))
 17            {
 018                index = -1;
 19
 20                // Third party v2 contains 10 parts, on which 3 are reserved for the tokenId
 21                // "id": urn:decentraland:amoy:collections-thirdparty:back-to-the-future:amoy-eb54:tuxedo-6751:amoy:0x1d
 22                // "tokenId": amoy:0x1d9fb685c257e74f869ba302e260c0b68f5ebb37:12
 023                for (var i = 0; i < THIRD_PARTY_V2_SHORTEN_URN_PARTS; i++)
 24                {
 025                    index = urnReceived.IndexOf(':', index + 1);
 026                    if (index == -1) break;
 27                }
 28
 029                return index != -1 ? urnReceived[..index] : urnReceived;
 30            }
 31
 32            // TokenId is always placed in the last part for regular nfts
 033            index = urnReceived.LastIndexOf(':');
 34
 035            return index != -1 ? urnReceived[..index] : urnReceived;
 36        }
 37
 38        private static int CountParts(string urn)
 39        {
 11440            int count = 1;
 11441            int index = urn.IndexOf(':');
 42
 34243            while (index != -1)
 44            {
 22845                count++;
 22846                index = urn.IndexOf(':', index + 1);
 47            }
 48
 11449            return count;
 50        }
 51
 52        private static bool IsThirdPartyCollection(string urn) =>
 053            !string.IsNullOrEmpty(urn) && urn.Contains(COLLECTIONS_THIRD_PARTY);
 54    }
 55}