Skip to content

Commit cea9f98

Browse files
author
razvan
committed
fix: address PR #46 review round 2 (5 fixes)
- Add NameFullyQualified support to woocommerce extractFuncName - Add action_check/filter_check cases to buildWCHookSignature - Use dynamic BaseClass for Oxygen element signatures - Increase bufio.Scanner buffer to 1MB for Blade templates - Update CI Go version from 1.22 to 1.24 to match go.mod Signed-off-by: doITmagic <razvan@doitmagic.com>
1 parent 9c34e57 commit cea9f98

5 files changed

Lines changed: 34 additions & 3 deletions

File tree

pkg/parser/php/laravel/blade.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func (ba *BladeAnalyzer) analyzeFile(filePath string) (BladeTemplate, error) {
6161
}
6262

6363
scanner := bufio.NewScanner(f)
64+
scanner.Buffer(make([]byte, 64*1024), 1024*1024) // Allow lines up to 1MB
6465
lineNum := 0
6566
for scanner.Scan() {
6667
lineNum++

pkg/parser/php/wordpress/analyzer.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,14 +389,18 @@ func (a *Analyzer) convertToChunks(info *WordPressInfo) []php.CodeChunk {
389389
if info.OxygenInfo != nil {
390390
if oxyInfo, ok := info.OxygenInfo.(*oxygen.OxygenInfo); ok {
391391
for _, elem := range oxyInfo.Elements {
392+
baseClass := elem.BaseClass
393+
if baseClass == "" {
394+
baseClass = "OxyEl"
395+
}
392396
chunks = append(chunks, php.CodeChunk{
393397
Name: elem.ClassName,
394398
Type: "oxy_element",
395399
Language: "php",
396400
FilePath: elem.FilePath,
397401
StartLine: elem.StartLine,
398402
EndLine: elem.EndLine,
399-
Signature: fmt.Sprintf("class %s extends OxyEl", elem.ClassName),
403+
Signature: fmt.Sprintf("class %s extends %s", elem.ClassName, baseClass),
400404
Docstring: fmt.Sprintf("Oxygen Builder Element: %s (methods: %s)", elem.ClassName, strings.Join(elem.Methods, ", ")),
401405
Metadata: map[string]any{
402406
"framework": "wordpress",
@@ -536,6 +540,10 @@ func buildWCHookSignature(wcHook woocommerce.WCHook) string {
536540
return fmt.Sprintf("remove_action('%s', '%s')", wcHook.HookName, wcHook.Callback)
537541
case "filter_removal":
538542
return fmt.Sprintf("remove_filter('%s', '%s')", wcHook.HookName, wcHook.Callback)
543+
case "action_check":
544+
return fmt.Sprintf("has_action('%s')", wcHook.HookName)
545+
case "filter_check":
546+
return fmt.Sprintf("has_filter('%s')", wcHook.HookName)
539547
default:
540548
return fmt.Sprintf("%s('%s', '%s')", wcHook.HookType, wcHook.HookName, wcHook.Callback)
541549
}

pkg/parser/php/wordpress/oxygen/analyzer.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func (a *Analyzer) extractOxygenElement(class php.ClassInfo) OxygenElement {
107107
ClassName: class.Name,
108108
Namespace: class.Namespace,
109109
FullName: class.FullName,
110+
BaseClass: extractBaseClassName(class.Extends),
110111
FilePath: class.FilePath,
111112
StartLine: class.StartLine,
112113
EndLine: class.EndLine,
@@ -177,6 +178,18 @@ func (a *Analyzer) walkForOxygenTemplates(node ast.Vertex, filePath string, info
177178
}
178179
}
179180

181+
// extractBaseClassName extracts the short base class name from a possibly namespaced extends value
182+
func extractBaseClassName(extends string) string {
183+
if extends == "" {
184+
return ""
185+
}
186+
// Get last segment after backslash (e.g., "Ns\OxyEl" → "OxyEl")
187+
if idx := strings.LastIndex(extends, "\\"); idx >= 0 {
188+
return extends[idx+1:]
189+
}
190+
return extends
191+
}
192+
180193
// extractFuncName extracts function name from AST node
181194
func extractFuncName(node ast.Vertex) string {
182195
if node == nil {

pkg/parser/php/wordpress/oxygen/types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ type OxygenElement struct {
1212
ClassName string `json:"class_name"`
1313
Namespace string `json:"namespace,omitempty"`
1414
FullName string `json:"full_name"`
15-
SlugMethod bool `json:"has_slug"` // Has slug() method
16-
Methods []string `json:"methods,omitempty"` // Detected methods (init, name, slug, icon, controls, render)
15+
BaseClass string `json:"base_class,omitempty"` // OxyEl, OxyElShadow, OxygenElement, etc.
16+
SlugMethod bool `json:"has_slug"` // Has slug() method
17+
Methods []string `json:"methods,omitempty"` // Detected methods (init, name, slug, icon, controls, render)
1718
FilePath string `json:"file_path"`
1819
StartLine int `json:"start_line"`
1920
EndLine int `json:"end_line"`

pkg/parser/php/wordpress/woocommerce/analyzer.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,14 @@ func extractFuncName(node ast.Vertex) string {
287287
}
288288
}
289289
return strings.Join(parts, "\\")
290+
case *ast.NameFullyQualified:
291+
var parts []string
292+
for _, part := range n.Parts {
293+
if namePart, ok := part.(*ast.NamePart); ok {
294+
parts = append(parts, string(namePart.Value))
295+
}
296+
}
297+
return strings.Join(parts, "\\")
290298
}
291299
return ""
292300
}

0 commit comments

Comments
 (0)