Skip to content

Commit dcd4090

Browse files
committed
feat(se): remove unnecessary checks
1 parent 764d13f commit dcd4090

File tree

3 files changed

+10
-23
lines changed

3 files changed

+10
-23
lines changed

regimes/se/invoices.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,8 @@ func validateOrgParty(value any) error {
7171
party.TaxID != nil && party.TaxID.Country == l10n.TaxCountryCode(l10n.SE),
7272
validation.Each(
7373
validation.By(func(value any) error {
74-
id, ok := value.(*org.Identity)
75-
if !ok || id == nil {
76-
return nil
77-
}
74+
// Casting to org.Identity is safe, as the identity type is validated before this function is called
75+
id, _ := value.(*org.Identity)
7876
if !id.Type.In(IdentityTypeOrgNr, IdentityTypePersonNr, IdentityTypeCoordinationNr) {
7977
return validation.NewError("type", "must be one of: SE-ON, SE-PN, SE-CN")
8078
}
@@ -90,10 +88,8 @@ func validateOrgParty(value any) error {
9088
// validateSupplier checks the supplier's tax ID requirements.
9189
// The supplier's VAT number is always required.
9290
func validateSupplier(value any) error {
93-
party, ok := value.(*org.Party)
94-
if !ok || party == nil {
95-
return nil
96-
}
91+
// Casting to org.Party is safe, as the party is validated before this function is called
92+
party, _ := value.(*org.Party)
9793

9894
return validation.ValidateStruct(party,
9995
// Swedish Tax ID (VAT ID) is always required for the supplier,
@@ -114,10 +110,8 @@ func validateSupplier(value any) error {
114110
}
115111

116112
func validateSupplierSimplifiedInvoice(value any) error {
117-
party, ok := value.(*org.Party)
118-
if !ok || party == nil {
119-
return nil
120-
}
113+
// Casting to org.Party is safe, as the party is validated before this function is called
114+
party, _ := value.(*org.Party)
121115

122116
return validation.ValidateStruct(party,
123117
validation.Field(&party.Name,

regimes/se/org_identities.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ var identityTypeDefinitions = []*cbc.Definition{
7272
//
7373
// If too many or too few numbers are present, it does nothing.
7474
func normalizeOrgIdentity(id *org.Identity) {
75-
if id == nil {
76-
return
77-
}
78-
75+
// No need for nil check, as the identity type is validated before this function is called
7976
switch id.Type {
8077
case IdentityTypeOrgNr:
8178
// Organization numbers should be numeric only, with no separators
@@ -143,9 +140,7 @@ func normalizeOrgIdentity(id *org.Identity) {
143140
//
144141
// If the organization type is not valid, it returns nil.
145142
func validateOrgIdentity(id *org.Identity) error {
146-
if id == nil {
147-
return nil
148-
}
143+
// No need for nil check, as the identity type is validated before this function is called
149144

150145
return validation.ValidateStruct(id,
151146
validation.Field(&id.Code,

regimes/se/tax_identities.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ func validateTaxIdentity(tID *tax.Identity) error {
3232
// Assumes the code has already been normalized, is made of 12 numeric characters,
3333
// retaining the checksum at the end, plus 2 control digits "01".
3434
func validateTaxCode(value any) error {
35-
code, ok := value.(cbc.Code)
36-
if !ok {
37-
return nil
38-
}
35+
// No need for nil check, as the identity type is validated before this function is called
36+
code, _ := value.(cbc.Code)
3937
if code == "" {
4038
return nil
4139
}

0 commit comments

Comments
 (0)