Skip to content

Commit 9c7237e

Browse files
committed
feat(php): add PHP language support with tree-sitter analyzer [codewiki/src/be/dependency_analyzer/analyzers/php.py, codewiki/src/be/dependency_analyzer/analysis/analysis_service.py, codewiki/src/be/dependency_analyzer/analysis/call_graph_analyzer.py, codewiki/cli/utils/repo_validator.py, codewiki/cli/utils/validation.py, codewiki/src/be/dependency_analyzer/utils/patterns.py, codewiki/src/be/prompt_template.py, pyproject.toml]
1 parent 07bb410 commit 9c7237e

8 files changed

Lines changed: 654 additions & 5 deletions

File tree

codewiki/cli/utils/repo_validator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
'.cxx', # C++
2828
'.hxx', # C++ headers
2929
'.cs', # C#
30+
'.php', # PHP
31+
'.phtml', # PHP templates
32+
'.inc', # PHP includes
3033
}
3134

3235

@@ -57,7 +60,7 @@ def validate_repository(repo_path: Path) -> Tuple[Path, List[Tuple[str, int]]]:
5760
if not languages:
5861
raise RepositoryError(
5962
f"No supported code files found in {repo_path}\n\n"
60-
"CodeWiki supports: Python, Java, JavaScript, TypeScript, C, C++, C#\n\n"
63+
"CodeWiki supports: Python, Java, JavaScript, TypeScript, C, C++, C#, PHP\n\n"
6164
"Please navigate to a code repository or specify a custom directory:\n"
6265
" cd /path/to/your/project\n"
6366
" codewiki generate"

codewiki/cli/utils/validation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ def detect_supported_languages(directory: Path) -> List[Tuple[str, int]]:
171171
'C': ['.c', '.h'],
172172
'C++': ['.cpp', '.hpp', '.cc', '.hh', '.cxx', '.hxx'],
173173
'C#': ['.cs'],
174+
'PHP': ['.php', '.phtml', '.inc'],
174175
}
175176

176177
# Directories to exclude from counting

codewiki/src/be/dependency_analyzer/analysis/analysis_service.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,16 +295,17 @@ def _filter_supported_languages(self, code_files: List[Dict]) -> List[Dict]:
295295
"""
296296
Filter code files to only include supported languages.
297297
298-
Supports Python, JavaScript, TypeScript, C, C++, Go, and Rust.
298+
Supports Python, JavaScript, TypeScript, Java, C#, C, C++, PHP, Go, and Rust.
299299
"""
300300
supported_languages = {
301301
"python",
302-
"javascript",
302+
"javascript",
303303
"typescript",
304304
"java",
305305
"csharp",
306306
"c",
307307
"cpp",
308+
"php",
308309
"go",
309310
"rust",
310311
}
@@ -317,7 +318,7 @@ def _filter_supported_languages(self, code_files: List[Dict]) -> List[Dict]:
317318

318319
def _get_supported_languages(self) -> List[str]:
319320
"""Get list of currently supported languages for analysis."""
320-
return ["python", "javascript", "typescript", "java", "csharp", "c", "cpp"]
321+
return ["python", "javascript", "typescript", "java", "csharp", "c", "cpp", "php"]
321322

322323
def _cleanup_repository(self, temp_dir: str):
323324
"""Clean up cloned repository."""

codewiki/src/be/dependency_analyzer/analysis/call_graph_analyzer.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ def _analyze_code_file(self, repo_dir: str, file_info: Dict):
131131
self._analyze_c_file(file_path, content, repo_dir)
132132
elif language == "cpp":
133133
self._analyze_cpp_file(file_path, content, repo_dir)
134+
elif language == "php":
135+
self._analyze_php_file(file_path, content, repo_dir)
134136
# else:
135137
# logger.warning(
136138
# f"Unsupported language for call graph analysis: {language} for file {file_path}"
@@ -298,6 +300,28 @@ def _analyze_csharp_file(self, file_path: str, content: str, repo_dir: str):
298300
except Exception as e:
299301
logger.error(f"Failed to analyze C# file {file_path}: {e}", exc_info=True)
300302

303+
def _analyze_php_file(self, file_path: str, content: str, repo_dir: str):
304+
"""
305+
Analyze PHP file using tree-sitter based analyzer.
306+
307+
Args:
308+
file_path: Relative path to the PHP file
309+
content: File content string
310+
repo_dir: Repository base directory
311+
"""
312+
from codewiki.src.be.dependency_analyzer.analyzers.php import analyze_php_file
313+
314+
try:
315+
functions, relationships = analyze_php_file(file_path, content, repo_path=repo_dir)
316+
317+
for func in functions:
318+
func_id = func.id if func.id else f"{file_path}:{func.name}"
319+
self.functions[func_id] = func
320+
321+
self.call_relationships.extend(relationships)
322+
except Exception as e:
323+
logger.error(f"Failed to analyze PHP file {file_path}: {e}", exc_info=True)
324+
301325
def _resolve_call_relationships(self):
302326
"""
303327
Resolve function call relationships across all languages.
@@ -382,6 +406,8 @@ def _generate_visualization_data(self) -> Dict:
382406
node_classes.append("lang-c")
383407
elif file_ext in [".cpp", ".cc", ".cxx", ".hpp", ".hxx"]:
384408
node_classes.append("lang-cpp")
409+
elif file_ext in [".php", ".phtml", ".inc"]:
410+
node_classes.append("lang-php")
385411

386412
cytoscape_elements.append(
387413
{

0 commit comments

Comments
 (0)