Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions internal/extgen/cfile_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ func (m *MySuperClass) Test() string {
tmpfile, err := os.CreateTemp("", "test_cfile_namespace_*.go")
require.NoError(t, err, "Failed to create temp file")
defer func() {
err := os.Remove(tmpfile.Name())
assert.NoError(t, err, "Failed to remove temp file: %v", err)
require.NoError(t, os.Remove(tmpfile.Name()), "Failed to remove temp file")
}()

_, err = tmpfile.Write([]byte(content))
Expand Down
6 changes: 2 additions & 4 deletions internal/extgen/classparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package extgen

import (
"bufio"
"errors"
"fmt"
"go/ast"
"go/parser"
Expand Down Expand Up @@ -211,10 +212,7 @@ func (cp *classParser) parseMethods(filename string) (methods []phpClassMethod,
}

defer func() {
e := file.Close()
if err != nil {
err = e
}
err = errors.Join(err, file.Close())
}()

scanner := bufio.NewScanner(file)
Expand Down
7 changes: 3 additions & 4 deletions internal/extgen/constparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package extgen

import (
"bufio"
"errors"
"fmt"
"os"
"regexp"
Expand All @@ -20,11 +21,9 @@ func (cp *ConstantParser) parse(filename string) (constants []phpConstant, err e
if err != nil {
return nil, err
}

defer func() {
e := file.Close()
if err == nil {
err = e
}
err = errors.Join(err, file.Close())
}()

scanner := bufio.NewScanner(file)
Expand Down
7 changes: 3 additions & 4 deletions internal/extgen/funcparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package extgen

import (
"bufio"
"errors"
"fmt"
"os"
"regexp"
Expand All @@ -19,11 +20,9 @@ func (fp *FuncParser) parse(filename string) (functions []phpFunction, err error
if err != nil {
return nil, err
}

defer func() {
e := file.Close()
if err == nil {
err = e
}
err = errors.Join(err, file.Close())
}()

scanner := bufio.NewScanner(file)
Expand Down
8 changes: 2 additions & 6 deletions internal/extgen/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -58,8 +57,7 @@ func main() {}`,
tmpfile, err := os.CreateTemp("", "test_namespace_*.go")
require.NoError(t, err, "Failed to create temp file")
defer func() {
err := os.Remove(tmpfile.Name())
assert.NoError(t, err, "Failed to remove temp file: %v", err)
require.NoError(t, os.Remove(tmpfile.Name()), "Failed to remove temp file")
}()

_, err = tmpfile.Write([]byte(tt.content))
Expand Down Expand Up @@ -98,9 +96,7 @@ const TEST_CONSTANT = "test_value"
tmpfile, err := os.CreateTemp("", "test_generator_namespace_*.go")
require.NoError(t, err, "Failed to create temp file")
defer func() {
if err := os.Remove(tmpfile.Name()); err != nil {
t.Logf("Failed to remove temp file: %v", err)
}
require.NoError(t, os.Remove(tmpfile.Name()), "Failed to remove temp file")
}()

_, err = tmpfile.Write([]byte(content))
Expand Down
6 changes: 3 additions & 3 deletions internal/extgen/nsparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package extgen

import (
"bufio"
"errors"
"fmt"
"os"
"regexp"
Expand All @@ -17,10 +18,9 @@ func (np *NamespaceParser) parse(filename string) (string, error) {
if err != nil {
return "", err
}

defer func() {
if err := file.Close(); err != nil {
fmt.Printf("Error closing file %s: %v\n", filename, err)
}
err = errors.Join(err, file.Close())
}()
Comment thread
dunglas marked this conversation as resolved.

var foundNamespace string
Expand Down
Loading