# πŸ” PHP Code Analyzer - Professional Edition [![PHP Version](https://img.shields.io/badge/PHP-8.0+-blue.svg)](https://php.net) [![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE) [![Version](https://img.shields.io/badge/Version-2.0.0-orange.svg)](CHANGELOG.md) **Advanced PHP Code Analyzer** - A professional tool that detects unused code (dead code) in your PHP projects, analyzes code quality, and provides detailed reports. ## ✨ Features ### 🎯 Core Features - **Dead Code Detection** - Identifies unused functions, classes, and methods - **Cross-Reference Analysis** - Cross-analyzes code references - **Multi-Directory Support** - Supports multiple directories like includes/, lib/, helpers/, src/ - **Enterprise Reporting** - Detailed reports in HTML, JSON, Console formats - **Performance Optimized** - Optimized for large projects - **Web Interface** - Modern and user-friendly web interface - **REST API** - JSON API for integration - **CLI Support** - Command-line interface ### πŸš€ Advanced Features - **AST-based Parsing** - Complete analysis using PHP's own tokenizer - **Fuzzy Matching** - Finds namespace, class, and method variants - **Dynamic Call Detection** - Detects variable function calls and call_user_func - **Smart Filtering** - Automatically excludes vendor/, cache/, tests/ directories - **Memory Management** - Memory optimization for large projects - **Caching System** - File cache for fast analysis - **Error Resilience** - Skips corrupted files and continues analysis ## πŸ“¦ Installation ### System Requirements - **PHP:** 8.0 or higher - **Memory:** Minimum 256MB, Recommended 512MB+ - **Extensions:** tokenizer, mbstring, json - **Web Server:** Apache, Nginx, LiteSpeed ### 1. Download Files ```bash # Clone from GitHub git clone https://github.com/gneral/php-code-analyzer.git # Or download files manually ``` ### 2. Upload to Web Server ```bash # Copy project files to your web directory cp -r php-code-analyzer/* /var/www/html/analyzer/ ``` ### 3. Installation Check Open `setup.php` file in your browser: ``` http://yourdomain.com/analyzer/setup.php ``` ### 4. Set Permissions ```bash # Write permission for cache directory chmod 755 /tmp/php_analyzer_cache # Write permission for report files chmod 755 /var/www/html/analyzer/ ``` ## 🎯 Usage ### Web Interface 1. **Open in browser:** `http://yourdomain.com/analyzer/analyzer-web.php` 2. **Project settings:** - Project Root: Main directory of your project - Target Directories: Directories to analyze (e.g., includes,lib,helpers) - Output Format: Select report format 3. **Click "Start Analysis"** button 4. **View results:** In web interface or downloaded reports ### Command Line (CLI) ```bash # Basic usage php AdvancedPHPCodeAnalyzer.php --project=/path/to/project # With custom directories php AdvancedPHPCodeAnalyzer.php --project=/var/www/myproject --target=includes,lib,helpers # Generate HTML report php AdvancedPHPCodeAnalyzer.php --project=/path/to/project --format=html # Help php AdvancedPHPCodeAnalyzer.php --help ``` ### REST API ```bash # Start analysis with POST request curl -X POST http://yourdomain.com/analyzer/analyzer.php \ -H "Content-Type: application/json" \ -d '{ "project_root": "/var/www/myproject", "target_dirs": ["includes", "lib", "helpers"], "output_format": "json" }' ``` ## πŸ“Š Report Examples ### Console Output ``` πŸ“Š PHP CODE ANALYSIS REPORT =============================================== πŸ“ˆ SUMMARY STATISTICS: β”œβ”€ Total Definitions: 156 β”œβ”€ Total References: 423 β”œβ”€ Dead Code Items: 12 β”œβ”€ Dead Code Ratio: 7.69% β”œβ”€ Analysis Time: 2.3s └─ Memory Peak: 45.2 MB πŸ’€ DEAD CODE DETECTED: β”œβ”€ [function] unused_helper_function β”‚ └─ helpers.php:45 β”œβ”€ [class] OldUtilityClass β”‚ └─ legacy.php:12 ``` ### JSON Response ```json { "metadata": { "analyzer_version": "2.0.0", "generated_at": "2025-07-29 10:30:45", "project_root": "/var/www/myproject" }, "statistics": { "target_files_count": 25, "scanned_files_count": 156, "dead_code_count": 12, "analysis_time": 2.34, "memory_peak_mb": 45.2 }, "summary": { "total_definitions": 156, "total_references": 423, "dead_code_percentage": 7.69, "top_used_items": [...] }, "dead_code": [ { "type": "function", "name": "unused_helper_function", "file": "/includes/helpers.php", "line": 45 } ] } ``` ## βš™οΈ Configuration ### Basic Settings ```php $config = [ 'project_root' => '/var/www/myproject', 'target_dirs' => ['includes', 'lib', 'helpers', 'src'], 'scan_dirs' => [''], // Empty = entire project 'extensions' => ['php', 'phtml', 'inc'], 'output_format' => 'json' // json, html, console ]; ``` ### Advanced Settings ```php $config = [ // ... basic settings ... 'exclude_patterns' => [ '/vendor/', '/node_modules/', '/cache/', '/tmp/', '/.git/', '/tests/', '*.min.php' ], 'enable_cache' => true, 'max_file_size' => 10 * 1024 * 1024, // 10MB 'memory_limit' => '512M', 'timeout' => 300 // 5 minutes ]; ``` ## πŸ”§ Project Examples ### WordPress Theme Analysis ```bash php AdvancedPHPCodeAnalyzer.php \ --project=/var/www/wp-content/themes/mytheme \ --target=includes,lib,functions \ --format=html ``` ### Laravel Project Analysis ```bash php AdvancedPHPCodeAnalyzer.php \ --project=/var/www/laravel-project \ --target=app/Helpers,app/Services,app/Utilities \ --format=json ``` ### Custom PHP Framework ```bash php AdvancedPHPCodeAnalyzer.php \ --project=/var/www/myframework \ --target=core,libs,helpers,includes \ --format=console ``` ## 🎨 Web Interface Features ### πŸ“± Responsive Design - **Mobile Compatible** - Works on all devices - **Modern UI** - Dark/light theme support - **Interactive** - Real-time progress indicator - **Professional** - Enterprise-level design ### πŸ“Š Visual Reports - **Statistics Cards** - Visual presentation of key metrics - **Dead Code List** - List of unused code - **Top Used Items** - Most frequently used items - **Recommendations** - Code quality suggestions ### πŸ”„ Dynamic Features - **Tab Navigation** - Easy report browsing - **Download Options** - JSON/HTML download - **Progress Tracking** - Analysis progress monitoring - **Error Handling** - User-friendly error messages ## 🀝 Contributing ### Bug Reports - Use **GitHub Issues** - Write **detailed descriptions** - Include **system information** - Share **sample code** ### Development 1. **Fork** the project 2. Create a **feature branch** 3. **Commit** your changes 4. Send a **Pull Request** ### Coding Standards - **PSR-12** PHP coding standard - **Comprehensive documentation** - Write **unit tests** - Maintain **backward compatibility** ## πŸ“ License This project is licensed under **MIT License**. See [LICENSE](LICENSE) file for details. ## πŸ‘¨β€πŸ’» Developer **Muhsin İŞSEVER** - **Email:** muhsin.issever@gmail.com - **Website:** https://ai.zefre.net/ - **GitHub:** [@gneral](https://github.com/gneral) - **R10 Profile:** https://www.r10.net/profil/193-gneral.html **Zefre.NET AI Internet Technologies** - **Website:** https://zefre.net/ - **Powered by:** [Zefre.net AI Technologies](https://zefre.net/) ## πŸ™ Acknowledgments Thanks to everyone who uses and contributes to this project! ### Special Thanks - **PHP Community** - For token analysis insights - **Open Source Contributors** - For inspiring projects - **Beta Testers** - For early feedback ## πŸ“ž Contact and Support ### πŸ†˜ Support - **Email:** muhsin.issever@gmail.com - **GitHub Issues:** For technical problems - **Website:** https://ai.zefre.net/php-code-analyzer/ ### πŸ’¬ Community - **GitHub Discussions** - For general discussions - **Stack Overflow** - Use `php-code-analyzer` tag ### πŸ“§ Business Inquiries Contact for enterprise solutions and custom development. --- ## 🌍 Language Versions - **English:** [README.md](README_EN.md) (This file) - **TΓΌrkΓ§e:** [README.md](README.md) (Turkish version) --- ## πŸ“š Documentation ### Quick Start Guide 1. **Download** and extract files 2. **Upload** to your web server 3. **Run** setup.php for installation check 4. **Access** analyzer-web.php for web interface 5. **Configure** your project settings 6. **Start** analysis and view results ### API Documentation #### POST /analyzer.php **Request:** ```json { "project_root": "/path/to/project", "target_dirs": ["includes", "lib"], "scan_dirs": [""], "extensions": ["php", "phtml"], "output_format": "json", "exclude_patterns": ["/vendor/", "/cache/"] } ``` **Response:** ```json { "success": true, "data": { "metadata": {...}, "statistics": {...}, "summary": {...}, "dead_code": [...], "recommendations": [...] } } ``` ### CLI Documentation #### Basic Commands ```bash # Analyze current directory php AdvancedPHPCodeAnalyzer.php --project=. # Analyze specific directories php AdvancedPHPCodeAnalyzer.php --project=/path/to/project --target=includes,lib # Generate HTML report php AdvancedPHPCodeAnalyzer.php --project=/path/to/project --format=html # Generate JSON report php AdvancedPHPCodeAnalyzer.php --project=/path/to/project --format=json ``` #### Advanced Usage ```bash # WordPress plugin analysis php AdvancedPHPCodeAnalyzer.php \ --project=/wp-content/plugins/myplugin \ --target=includes,admin,public \ --format=html # Laravel application analysis php AdvancedPHPCodeAnalyzer.php \ --project=/var/www/laravel-app \ --target=app/Services,app/Helpers,app/Repositories \ --format=json # Custom framework analysis php AdvancedPHPCodeAnalyzer.php \ --project=/var/www/framework \ --target=core,system,libraries,helpers \ --format=console ``` ### Troubleshooting #### Common Issues **1. Memory limit exceeded** ```php // Increase memory limit in config 'memory_limit' => '1024M' ``` **2. Execution timeout** ```php // Increase timeout in config 'timeout' => 600 // 10 minutes ``` **3. Permission denied** ```bash # Fix file permissions chmod 755 /path/to/analyzer/ chmod 755 /tmp/php_analyzer_cache/ ``` **4. Extension not loaded** ```bash # Install required extensions apt-get install php-tokenizer php-mbstring php-json ``` #### Performance Tips 1. **Use caching** for repeated analyses 2. **Exclude unnecessary directories** (vendor/, node_modules/) 3. **Set appropriate memory limits** for large projects 4. **Use CLI** for better performance on large codebases 5. **Run on servers** with sufficient resources --- **Copyright Β© 2025 Zefre.NET AI Internet Technologies** **Licensed under MIT License** [![Powered by Zefre.net](https://zefre.net/images/zefreNetLogo587-230.png)](https://zefre.net)