mirror of
https://github.com/php/frankenphp.git
synced 2026-03-24 00:52:11 +01:00
chore: modernize Go code
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user