• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hyperwallet / hyperwallet-ios-sdk / 15826401626

21 May 2025 02:36PM UTC coverage: 96.705%. Remained the same
15826401626

push

github

web-flow
Initial commit for CodeQL (#152)

* Initial commit for CodeQL

* Updating language

1937 of 2003 relevant lines covered (96.7%)

18.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.04
/Sources/AnyCodable.swift
1
//
2
// Copyright 2018 - Present Hyperwallet
3
//
4
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software
5
// and associated documentation files (the "Software"), to deal in the Software without restriction,
6
// including without limitation the rights to use, copy, modify, merge, publish, distribute,
7
// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
8
// furnished to do so, subject to the following conditions:
9
//
10
// The above copyright notice and this permission notice shall be included in all copies or
11
// substantial portions of the Software.
12
//
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
14
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18

19
import Foundation
20

21
struct AnyCodable: Codable {
22
    var value: Any
23

24
    init(value: Any) {
249✔
25
        self.value = value
249✔
26
    }
249✔
27

28
    private struct CodingKeys: CodingKey {
29
        var stringValue: String
30
        var intValue: Int?
31
        init?(intValue: Int) {
×
32
            self.stringValue = "\(intValue)"
×
33
            self.intValue = intValue
×
34
        }
×
35
        init?(stringValue: String) { self.stringValue = stringValue }
129✔
36
    }
37

38
    func encode(to encoder: Encoder) throws {
248✔
39
        var container = encoder.singleValueContainer()
248✔
40
        if let intVal = value as? Int {
248✔
41
            try container.encode(intVal)
1✔
42
        } else if let doubleVal = value as? Double {
1✔
43
            try container.encode(doubleVal)
1✔
44
        } else if let boolVal = value as? Bool {
1✔
45
            try container.encode(boolVal)
1✔
46
        } else if let stringVal = value as? String {
244✔
47
            try container.encode(stringVal)
244✔
48
        } else {
244✔
49
            throw ErrorTypeHelper.parseError(fieldName: container.codingPath.first?.stringValue)
1✔
50
        }
247✔
51
    }
247✔
52

53
    init(from decoder: Decoder) throws {
1,044✔
54
        if let container = try? decoder.container(keyedBy: CodingKeys.self) {
1,044✔
55
            var result = [String: Any]()
86✔
56
            try container.allKeys.forEach { (key) throws in
129✔
57
                result[key.stringValue] = try container.decode(AnyCodable.self, forKey: key).value
129✔
58
            }
129✔
59
            value = result
86✔
60
        } else if var container = try? decoder.unkeyedContainer() {
86✔
61
            var result = [Any]()
43✔
62
            while !container.isAtEnd {
86✔
63
                result.append(try container.decode(AnyCodable.self).value)
43✔
64
            }
43✔
65
            value = result
43✔
66
        } else if let container = try? decoder.singleValueContainer() {
915✔
67
            if let intVal = try? container.decode(Int.self) {
915✔
68
                value = intVal
4✔
69
            } else if let doubleVal = try? container.decode(Double.self) {
4✔
70
                value = doubleVal
1✔
71
            } else if let boolVal = try? container.decode(Bool.self) {
1✔
72
                value = boolVal
1✔
73
            } else if let stringVal = try? container.decode(String.self) {
908✔
74
                value = stringVal
908✔
75
            } else if container.decodeNil() {
908✔
76
                value = ""
1✔
77
            } else {
1✔
78
                throw ErrorTypeHelper.parseError(message: "the container contains nothing serializable")
×
79
            }
915✔
80
        } else {
915✔
81
            throw ErrorTypeHelper.parseError(message: "Could not serialize",
×
82
                                             fieldName: decoder.codingPath.first?.stringValue)
×
83
        }
1,044✔
84
    }
1,044✔
85
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc