Skip to content

Commit 2b48804

Browse files
authored
docs: Add Claude AI guidance and improve project docs (#16)
- Introduce CLAUDE.md to provide specific instructions and context for Claude Code. - Significantly enhance README.md with a detailed project overview, features, quick start, and expanded explanations for usage patterns and architecture. - Update .gitignore to exclude the .claude directory.
1 parent 854aa0a commit 2b48804

File tree

3 files changed

+287
-131
lines changed

3 files changed

+287
-131
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ build
1515
vendor
1616
composer.lock
1717
*.cache
18+
.claude

CLAUDE.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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 SimpleTypes is a universal PHP library for converting and manipulating values with units of measurement including money, weight, length, temperature, volume, area, and more. It provides smart parsing, arithmetic operations, formatting, and conversion between different units.
8+
9+
## Core Architecture
10+
11+
### Type System Structure
12+
The library follows a consistent pattern with paired Config and Type classes:
13+
14+
**Core Classes:**
15+
- `src/Type/AbstractType.php` - Base class for all measurement types
16+
- `src/Config/AbstractConfig.php` - Base configuration class
17+
- `src/Parser.php` - Smart input value parser
18+
- `src/Formatter.php` - Output formatting and rendering
19+
20+
**Built-in Types:**
21+
- `Money` - Currency conversion and arithmetic
22+
- `Weight` - Mass measurements (kg, lb, g, etc.)
23+
- `Length` - Distance measurements (km, mile, m, etc.)
24+
- `Temperature` - Temp conversions (Celsius, Fahrenheit, Kelvin)
25+
- `Volume` - Volume measurements (liter, gallon, etc.)
26+
- `Area` - Area measurements (m², ft², etc.)
27+
- `Time` - Time duration measurements
28+
- `Info` - Digital storage (bytes, KB, MB, GB)
29+
- `Degree` - Angular measurements
30+
31+
### Configuration System
32+
Each type has a corresponding config class that defines:
33+
- Default unit for parsing
34+
- Conversion rates between units
35+
- Formatting rules (symbols, decimal places, separators)
36+
- Rounding behavior
37+
38+
### Smart Parser
39+
The `Parser` class handles flexible input parsing:
40+
- Extracts numbers from mixed strings
41+
- Recognizes various decimal formats (comma/dot)
42+
- Handles scientific notation
43+
- Identifies unit symbols and names
44+
- Supports negative values and percentages
45+
46+
## Common Commands
47+
48+
### Development
49+
```bash
50+
make update # Install/update all dependencies
51+
make autoload # Dump optimized autoloader
52+
```
53+
54+
### Testing
55+
```bash
56+
make test-all # Run PHPUnit tests and all code style checks
57+
make test # Run PHPUnit tests only (alias for test-phpunit)
58+
make codestyle # Run all linting tools at once
59+
```
60+
61+
### Individual Quality Assurance
62+
```bash
63+
make test-phpstan # PHPStan static analysis
64+
make test-psalm # Psalm static analysis
65+
make test-phpcs # PHP Code Sniffer (PSR-12)
66+
make test-phpcsfixer # PHP-CS-Fixer style check
67+
make test-phpcsfixer-fix # Auto-fix code style issues
68+
make test-phpmd # PHP Mess Detector
69+
make test-phan # Phan static analyzer
70+
```
71+
72+
### Reports
73+
```bash
74+
make report-all # Generate all reports
75+
make report-phpmetrics # PHP Metrics report
76+
make report-pdepend # PHP Depend analysis
77+
```
78+
79+
## Usage Patterns
80+
81+
### Creating Type Objects
82+
```php
83+
// Various construction methods
84+
$money = new Money('10 eur');
85+
$weight = new Weight('1000'); // Uses default unit from config
86+
$length = new Length('500 km');
87+
$money = new Money('100500 usd', new ConfigMoney()); // Custom config
88+
```
89+
90+
### Global Configuration
91+
```php
92+
// Set default configs for all objects of a type
93+
Config::registerDefault('money', new ConfigMoney());
94+
```
95+
96+
### Arithmetic Operations
97+
All types support: `add()`, `subtract()`, `multiply()`, `division()`, `negative()`, `abs()`, `percent()`
98+
99+
### Method Chaining
100+
Operations return the same object for chaining:
101+
```php
102+
$result = (new Money('10 usd'))
103+
->add('5 eur')
104+
->multiply(2)
105+
->convert('rub');
106+
```
107+
108+
### Output Formats
109+
- `text()` - Formatted string with symbol
110+
- `noStyle()` - Number only without symbol
111+
- `html()` - HTML with data attributes for JavaScript
112+
- `htmlInput()` - HTML input element
113+
- `dump()` - Debug output with object ID
114+
115+
## Key Design Principles
116+
117+
### Immutable Operations
118+
Most operations create new objects rather than modifying existing ones. Use `getClone()` when you need a copy.
119+
120+
### Flexible Input Parsing
121+
The parser is very permissive and handles various input formats automatically.
122+
123+
### Type Safety
124+
All arithmetic operations check type compatibility and handle unit conversions automatically.
125+
126+
### Debugging Support
127+
Built-in logging system tracks all operations when debug mode is enabled in configs.
128+
129+
## File Structure
130+
131+
### Configuration Files
132+
Configuration arrays are also available as separate files in `src/config/` for direct access to conversion rules.
133+
134+
### Test Structure
135+
- `tests/` - PHPUnit tests following JBZoo test patterns
136+
- Tests extend base classes from jbzoo/toolbox-dev
137+
- Comprehensive coverage of parsing, arithmetic, and formatting
138+
139+
## Integration Notes
140+
141+
This library integrates with the JBZoo ecosystem:
142+
- Uses `jbzoo/utils` for utility functions
143+
- Follows JBZoo coding standards via `jbzoo/codestyle`
144+
- Compatible with JBZoo's Makefile-based development workflow

0 commit comments

Comments
 (0)