|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +JBZoo/Utils is a PHP utility library providing a collection of functions, mini classes, and snippets for everyday PHP development. It contains 24 utility classes covering array manipulation, string operations, file system operations, date handling, email validation, image processing, and more. |
| 8 | + |
| 9 | +### Key Architecture |
| 10 | + |
| 11 | +- **Namespace**: All classes are under `JBZoo\Utils` namespace |
| 12 | +- **PSR-4 Autoloading**: Source code in `src/` directory follows PSR-4 standard |
| 13 | +- **Static Method Classes**: Each utility class (Arr, Str, FS, etc.) provides static methods for specific functionality |
| 14 | +- **Function Aliases**: The `src/aliases.php` file provides convenient function aliases for common operations |
| 15 | +- **Constants**: Global constants defined in `src/defines.php` |
| 16 | + |
| 17 | +### Core Utility Classes |
| 18 | + |
| 19 | +The library includes 24 main utility classes: |
| 20 | +- **Arr**: Array manipulation and operations |
| 21 | +- **Str**: String processing and manipulation |
| 22 | +- **FS**: File system operations |
| 23 | +- **Filter**: Data filtering and sanitization |
| 24 | +- **Dates**: Date/time operations |
| 25 | +- **Email**: Email validation and processing |
| 26 | +- **Env**: Environment variable handling |
| 27 | +- **Http**: HTTP header operations |
| 28 | +- **Image**: Image processing utilities |
| 29 | +- **Url**: URL manipulation |
| 30 | +- **Xml**: XML processing |
| 31 | +- **Cli**: Command-line interface utilities |
| 32 | +- Plus 12 additional specialized classes (Csv, IP, Ser, Slug, Stats, Sys, Timer, Vars, PhpDocs, etc.) |
| 33 | + |
| 34 | +## Development Commands |
| 35 | + |
| 36 | +### Core Development Tasks |
| 37 | +```bash |
| 38 | +# Install/update dependencies |
| 39 | +make update |
| 40 | + |
| 41 | +# Run all tests |
| 42 | +make test |
| 43 | + |
| 44 | +# Run code style checks |
| 45 | +make codestyle |
| 46 | + |
| 47 | +# Run all project tests and quality checks |
| 48 | +make test-all |
| 49 | +``` |
| 50 | + |
| 51 | +### Testing |
| 52 | +```bash |
| 53 | +# Run PHPUnit tests |
| 54 | +vendor/bin/phpunit |
| 55 | + |
| 56 | +# Run PHPUnit with specific configuration |
| 57 | +vendor/bin/phpunit --configuration phpunit.xml.dist |
| 58 | + |
| 59 | +# Run tests for specific file |
| 60 | +vendor/bin/phpunit tests/ArrayTest.php |
| 61 | +``` |
| 62 | + |
| 63 | +### Code Quality |
| 64 | +The project uses JBZoo Toolbox codestyle standards via Makefile targets: |
| 65 | +- `make codestyle` - runs all code quality checks |
| 66 | +- Code style configuration comes from `vendor/jbzoo/codestyle/src/init.Makefile` |
| 67 | + |
| 68 | +### Build System |
| 69 | +- **Makefile**: Main build configuration with standard targets |
| 70 | +- **Dependencies**: Uses `jbzoo/toolbox-dev` for development dependencies |
| 71 | +- **PHP Version**: Requires PHP 8.2+ (as of current version) |
| 72 | + |
| 73 | +## Testing Architecture |
| 74 | + |
| 75 | +### Test Structure |
| 76 | +- **Location**: All tests in `tests/` directory |
| 77 | +- **Naming**: Test files follow `*Test.php` pattern |
| 78 | +- **Bootstrap**: Tests use `tests/autoload.php` for initialization |
| 79 | +- **Coverage**: Configured for full source code coverage analysis |
| 80 | + |
| 81 | +### Test Organization |
| 82 | +- Each utility class has a corresponding test file (e.g., `Arr.php` → `ArrayTest.php`) |
| 83 | +- Tests use PHPUnit framework with comprehensive coverage reporting |
| 84 | +- Test isolation and cleanup handled via `revertServerVar()` function |
| 85 | + |
| 86 | +### CI/CD Pipeline |
| 87 | +- **GitHub Actions**: `.github/workflows/main.yml` |
| 88 | +- **PHP Versions**: Tests run on PHP 8.2, 8.3, 8.4 |
| 89 | +- **Matrix Testing**: Tests with different composer flags (`--prefer-lowest`) |
| 90 | +- **Coverage**: Uses Xdebug for coverage reporting |
| 91 | +- **Quality Gates**: Separate jobs for PHPUnit tests, linters, and reports |
| 92 | + |
| 93 | +## File Structure Patterns |
| 94 | + |
| 95 | +### Source Code Organization |
| 96 | +``` |
| 97 | +src/ |
| 98 | +├── aliases.php # Function aliases for common operations |
| 99 | +├── defines.php # Global constants |
| 100 | +├── Exception.php # Base exception class |
| 101 | +└── [UtilityClass].php # Individual utility classes (Arr, Str, FS, etc.) |
| 102 | +``` |
| 103 | + |
| 104 | +### Development Standards |
| 105 | +- **PHP 8.2+**: Uses modern PHP features including typed properties and strict types |
| 106 | +- **PSR Standards**: Follows PSR-4 autoloading and coding standards |
| 107 | +- **Static Methods**: All utility functions implemented as static class methods |
| 108 | +- **Immutable Operations**: Most operations return new values rather than modifying input |
| 109 | + |
| 110 | +### Key Dependencies |
| 111 | +- **Production**: Minimal dependencies (only PHP 8.2+) |
| 112 | +- **Development**: `jbzoo/toolbox-dev` for testing and code quality tools |
| 113 | +- **Optional**: `symfony/process` for CLI operations, `jbzoo/data` for data handling |
| 114 | + |
| 115 | +## Working with the Codebase |
| 116 | + |
| 117 | +### Adding New Utilities |
| 118 | +1. Create new class in `src/` following existing patterns |
| 119 | +2. Add corresponding test file in `tests/` |
| 120 | +3. Update documentation if adding major functionality |
| 121 | +4. Follow existing code style and static method patterns |
| 122 | + |
| 123 | +### Common Development Patterns |
| 124 | +- All utility classes follow similar structure with static methods |
| 125 | +- Input validation and type checking handled consistently |
| 126 | +- Error handling uses custom Exception class when needed |
| 127 | +- Comprehensive test coverage expected for all new functionality |
0 commit comments