Skip to content

Commit 0206465

Browse files
authored
Merge pull request #23 from fabceolin/main
Add php support
2 parents aaac815 + 9c7237e commit 0206465

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
@@ -297,16 +297,17 @@ def _filter_supported_languages(self, code_files: List[Dict]) -> List[Dict]:
297297
"""
298298
Filter code files to only include supported languages.
299299
300-
Supports Python, JavaScript, TypeScript, C, C++, Go, and Rust.
300+
Supports Python, JavaScript, TypeScript, Java, C#, C, C++, PHP, Go, and Rust.
301301
"""
302302
supported_languages = {
303303
"python",
304-
"javascript",
304+
"javascript",
305305
"typescript",
306306
"java",
307307
"csharp",
308308
"c",
309309
"cpp",
310+
"php",
310311
"go",
311312
"rust",
312313
}
@@ -319,7 +320,7 @@ def _filter_supported_languages(self, code_files: List[Dict]) -> List[Dict]:
319320

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

324325
def _cleanup_repository(self, temp_dir: str):
325326
"""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
@@ -132,6 +132,8 @@ def _analyze_code_file(self, repo_dir: str, file_info: Dict):
132132
self._analyze_c_file(file_path, content, repo_dir)
133133
elif language == "cpp":
134134
self._analyze_cpp_file(file_path, content, repo_dir)
135+
elif language == "php":
136+
self._analyze_php_file(file_path, content, repo_dir)
135137
# else:
136138
# logger.warning(
137139
# f"Unsupported language for call graph analysis: {language} for file {file_path}"
@@ -300,6 +302,28 @@ def _analyze_csharp_file(self, file_path: str, content: str, repo_dir: str):
300302
except Exception as e:
301303
logger.error(f"Failed to analyze C# file {file_path}: {e}", exc_info=True)
302304

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

388414
cytoscape_elements.append(
389415
{

0 commit comments

Comments
 (0)