|  | 
|  | 1 | +# WARP.md | 
|  | 2 | + | 
|  | 3 | +This file provides guidance to WARP (warp.dev) when working with code in this repository. | 
|  | 4 | + | 
|  | 5 | +## Project Overview | 
|  | 6 | + | 
|  | 7 | +PHP AbraFlexi is a PHP 8.1+ library for easy interaction with the Czech economic system AbraFlexi. It provides a complete REST API client with object-oriented interface for all AbraFlexi evidences (entities). | 
|  | 8 | + | 
|  | 9 | +## Development Commands | 
|  | 10 | + | 
|  | 11 | +### Package Management | 
|  | 12 | +```bash | 
|  | 13 | +composer install          # Install dependencies | 
|  | 14 | +composer update           # Update dependencies | 
|  | 15 | +composer require <package> # Add new dependency | 
|  | 16 | +``` | 
|  | 17 | + | 
|  | 18 | +### Testing | 
|  | 19 | +```bash | 
|  | 20 | +phpunit                   # Run all tests | 
|  | 21 | +phpunit --testsuite=all   # Run full test suite | 
|  | 22 | +phpunit tests/src/AbraFlexi/ActionsTest.php  # Run specific test | 
|  | 23 | +``` | 
|  | 24 | + | 
|  | 25 | +### Code Quality | 
|  | 26 | +```bash | 
|  | 27 | +vendor/bin/php-cs-fixer fix                    # Fix code style issues | 
|  | 28 | +vendor/bin/php-cs-fixer fix --dry-run         # Check code style without fixing | 
|  | 29 | +vendor/bin/phpstan analyze                     # Run static analysis | 
|  | 30 | +``` | 
|  | 31 | + | 
|  | 32 | +### Evidence Classes Generation | 
|  | 33 | +```bash | 
|  | 34 | +cd tools/ | 
|  | 35 | +./update_all.sh           # Update evidence classes from AbraFlexi API | 
|  | 36 | +./force_update_all.sh     # Force update all classes regardless of version | 
|  | 37 | +``` | 
|  | 38 | + | 
|  | 39 | +## Core Architecture | 
|  | 40 | + | 
|  | 41 | +### Class Hierarchy | 
|  | 42 | + | 
|  | 43 | +The library follows a layered architecture with these core base classes: | 
|  | 44 | + | 
|  | 45 | +- **`RO` (Read Only)**: Base class for reading data from AbraFlexi | 
|  | 46 | +  - Located: `src/AbraFlexi/RO.php` | 
|  | 47 | +  - Handles HTTP communication, authentication, and data parsing | 
|  | 48 | +  - Contains curl operations, URL building, and response processing | 
|  | 49 | + | 
|  | 50 | +- **`RW` (Read Write)**: Extends RO for write operations | 
|  | 51 | +  - Located: `src/AbraFlexi/RW.php` | 
|  | 52 | +  - Adds insert, update, delete functionality | 
|  | 53 | +  - Supports transactions (`atomic` mode) and dry-run testing | 
|  | 54 | + | 
|  | 55 | +### Evidence System | 
|  | 56 | + | 
|  | 57 | +AbraFlexi uses "evidences" (entities/records). Each evidence has: | 
|  | 58 | +- Auto-generated class derived from RO or RW | 
|  | 59 | +- Class naming: evidence name converted to PascalCase (e.g., `faktura-vydana` → `FakturaVydana`) | 
|  | 60 | +- Each class defines `$evidence` property with the API endpoint name | 
|  | 61 | + | 
|  | 62 | +### Evidence Class Generation | 
|  | 63 | + | 
|  | 64 | +Classes are auto-generated from AbraFlexi API using tools in `tools/` directory: | 
|  | 65 | +- `update_evidencelist_class.php` - Updates available evidences | 
|  | 66 | +- `update_properties_class.php` - Updates field definitions | 
|  | 67 | +- `update_actions_class.php` - Updates available actions | 
|  | 68 | +- `generate_evidence_classes.php` - Generates individual evidence classes | 
|  | 69 | + | 
|  | 70 | +### Configuration | 
|  | 71 | + | 
|  | 72 | +Connection can be configured via: | 
|  | 73 | +1. Constants: `ABRAFLEXI_URL`, `ABRAFLEXI_LOGIN`, `ABRAFLEXI_PASSWORD`, `ABRAFLEXI_COMPANY` | 
|  | 74 | +2. Environment variables with same names | 
|  | 75 | +3. Constructor parameters (highest priority) | 
|  | 76 | + | 
|  | 77 | +### Data Types | 
|  | 78 | + | 
|  | 79 | +The library automatically converts AbraFlexi data types to PHP equivalents: | 
|  | 80 | +- `date` → `\DateTime` | 
|  | 81 | +- `datetime` → `\DateTime`  | 
|  | 82 | +- `integer` → `int` | 
|  | 83 | +- `numeric` → `float` | 
|  | 84 | +- `logic` → `bool` | 
|  | 85 | +- `relation` → `\AbraFlexi\Relation` | 
|  | 86 | + | 
|  | 87 | +## Testing Infrastructure | 
|  | 88 | + | 
|  | 89 | +### Test Configuration | 
|  | 90 | +- Bootstrap: `tests/bootstrap.php` | 
|  | 91 | +- Configuration: `phpunit.xml` | 
|  | 92 | +- Test server: Uses demo.flexibee.eu by default, configurable via `.env` | 
|  | 93 | + | 
|  | 94 | +### Test Structure | 
|  | 95 | +- Unit tests in `tests/src/AbraFlexi/` | 
|  | 96 | +- Each main class should have corresponding test | 
|  | 97 | +- Tests extend base test classes for consistency | 
|  | 98 | + | 
|  | 99 | +## Code Standards | 
|  | 100 | + | 
|  | 101 | +### From GitHub Copilot Instructions: | 
|  | 102 | +- **PHP Version**: PHP 8.4 or later | 
|  | 103 | +- **Code Style**: PSR-12 coding standard | 
|  | 104 | +- **Documentation**: Include docblocks for all functions and classes with parameters and return types | 
|  | 105 | +- **Type Hints**: Always include type hints for parameters and return types | 
|  | 106 | +- **Internationalization**: Use `_()` functions for translatable strings | 
|  | 107 | +- **Security**: Never expose sensitive information | 
|  | 108 | +- **Testing**: Create/update PHPUnit tests for new/modified classes | 
|  | 109 | +- **Comments**: Write in English using complete sentences | 
|  | 110 | +- **Variables**: Use meaningful, descriptive names | 
|  | 111 | +- **Constants**: Define constants instead of magic numbers/strings | 
|  | 112 | +- **Error Handling**: Handle exceptions properly with meaningful messages | 
|  | 113 | + | 
|  | 114 | +### Code Formatting | 
|  | 115 | +The project uses `friendsofphp/php-cs-fixer` with custom configuration in `.php-cs-fixer.dist.php`. | 
|  | 116 | + | 
|  | 117 | +## Project Structure | 
|  | 118 | + | 
|  | 119 | +``` | 
|  | 120 | +src/AbraFlexi/           # Main library classes | 
|  | 121 | +├── RO.php               # Base read-only class | 
|  | 122 | +├── RW.php               # Base read-write class | 
|  | 123 | +├── Actions.php          # Available actions (auto-generated) | 
|  | 124 | +├── EvidenceList.php     # Evidence list (auto-generated) | 
|  | 125 | +├── Relations.php        # Relations between evidences (auto-generated) | 
|  | 126 | +├── Formats.php          # Supported formats (auto-generated) | 
|  | 127 | +├── Structure.php        # Evidence structure definitions | 
|  | 128 | +└── [Evidence classes]   # Individual evidence classes | 
|  | 129 | +
 | 
|  | 130 | +Examples/                # Usage examples for different operations | 
|  | 131 | +tests/                   # PHPUnit tests | 
|  | 132 | +tools/                   # Code generation and update scripts | 
|  | 133 | +static/                  # Generated JSON metadata files | 
|  | 134 | +``` | 
|  | 135 | + | 
|  | 136 | +## Important Implementation Notes | 
|  | 137 | + | 
|  | 138 | +### Evidence Class Creation Pattern | 
|  | 139 | +```php | 
|  | 140 | +class NewEvidence extends \AbraFlexi\RW { | 
|  | 141 | +    public $evidence = 'evidence-name'; | 
|  | 142 | +} | 
|  | 143 | +``` | 
|  | 144 | + | 
|  | 145 | +### Object Instantiation with Options | 
|  | 146 | +```php | 
|  | 147 | +$invoice = new \AbraFlexi\FakturaVydana('code:VF2-12345', [ | 
|  | 148 | +    'company' => 'demo', | 
|  | 149 | +    'url' => 'https://demo.flexibee.eu', | 
|  | 150 | +    'debug' => true, | 
|  | 151 | +    'nativeTypes' => false,  // Disable automatic type conversion | 
|  | 152 | +    'ignore404' => true      // Don't throw exception for missing records | 
|  | 153 | +]); | 
|  | 154 | +``` | 
|  | 155 | + | 
|  | 156 | +### Authentication Methods | 
|  | 157 | +1. Username/password | 
|  | 158 | +2. AuthSessionId for web application integration | 
|  | 159 | +3. Environment variables or constants | 
|  | 160 | + | 
|  | 161 | +### Debug Mode Features | 
|  | 162 | +- Validates field existence and permissions | 
|  | 163 | +- Logs all requests/responses to `/tmp/` | 
|  | 164 | +- Automatic error reporting with detailed information | 
|  | 165 | +- Enhanced error messages for development | 
|  | 166 | + | 
|  | 167 | +## Dependencies | 
|  | 168 | + | 
|  | 169 | +- **Runtime**: PHP 8.1+, ext-json, ext-curl, ext-gettext, vitexsoftware/ease-core | 
|  | 170 | +- **Development**: PHPUnit, PHP-CS-Fixer, PHPStan, Phing | 
|  | 171 | + | 
|  | 172 | +## License | 
|  | 173 | + | 
|  | 174 | +MIT License - allows commercial use and modification. | 
0 commit comments