chore: modernize Go code

This commit is contained in:
Kévin Dunglas
2025-08-14 16:01:06 +02:00
parent 6ad34b1cb3
commit a1ae2692e1
17 changed files with 47 additions and 67 deletions

View File

@@ -306,8 +306,8 @@ func (cp *classParser) parseMethodSignature(className, signature string) (*phpCl
var params []phpParameter
if paramsStr != "" {
paramParts := strings.Split(paramsStr, ",")
for _, part := range paramParts {
paramParts := strings.SplitSeq(paramsStr, ",")
for part := range paramParts {
param, err := cp.parseMethodParameter(strings.TrimSpace(part))
if err != nil {
return nil, fmt.Errorf("parsing parameter '%s': %w", part, err)

View File

@@ -378,8 +378,7 @@ func BenchmarkDocumentationGenerator_GenerateMarkdown(b *testing.B) {
generator: generator,
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_, err := docGen.generateMarkdown()
assert.NoError(b, err)
}

View File

@@ -128,8 +128,8 @@ func (fp *FuncParser) parseSignature(signature string) (*phpFunction, error) {
var params []phpParameter
if paramsStr != "" {
paramParts := strings.Split(paramsStr, ",")
for _, part := range paramParts {
paramParts := strings.SplitSeq(paramsStr, ",")
for part := range paramParts {
param, err := fp.parseParameter(strings.TrimSpace(part))
if err != nil {
return nil, fmt.Errorf("parsing parameter '%s': %w", part, err)

View File

@@ -371,8 +371,7 @@ func internalTwo() {
analyzer := &SourceAnalyzer{}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_, _, err := analyzer.analyze(filename)
require.NoError(b, err)
}
@@ -391,8 +390,7 @@ func test3() {
analyzer := &SourceAnalyzer{}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
analyzer.extractInternalFunctions(content)
}
}

View File

@@ -234,7 +234,7 @@ func BenchmarkSanitizePackageName(b *testing.B) {
for _, tc := range testCases {
b.Run(tc, func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
SanitizePackageName(tc)
}
})

View File

@@ -6,6 +6,7 @@ import (
"go/parser"
"go/token"
"regexp"
"slices"
"strings"
)
@@ -115,12 +116,7 @@ func (v *Validator) validateClassProperty(prop phpClassProperty) error {
}
func (v *Validator) isValidPHPType(phpType phpType, validTypes []phpType) bool {
for _, valid := range validTypes {
if phpType == valid {
return true
}
}
return false
return slices.Contains(validTypes, phpType)
}
// validateScalarTypes checks if PHP signature contains only supported scalar types
@@ -141,12 +137,7 @@ func (v *Validator) validateScalarTypes(fn phpFunction) error {
}
func (v *Validator) isScalarPHPType(phpType phpType, supportedTypes []phpType) bool {
for _, supported := range supportedTypes {
if phpType == supported {
return true
}
}
return false
return slices.Contains(supportedTypes, phpType)
}
// validateGoFunctionSignatureWithOptions validates with option for method vs function

View File

@@ -150,7 +150,7 @@ func matchBracketPattern(pattern string, fileName string) bool {
// all bracket entries are checked individually, only one needs to match
// *.{php,twig,yaml} -> *.php, *.twig, *.yaml
for _, pattern := range strings.Split(betweenTheBrackets, ",") {
for pattern := range strings.SplitSeq(betweenTheBrackets, ",") {
if matchPattern(beforeTheBrackets+pattern+afterTheBrackets, fileName) {
return true
}