Skip to content

Commit e15acff

Browse files
committed
docs: complete documentation overhaul with type-aware transformations
- Add comprehensive type-aware transformation system documentation - Core Concepts guide: detailed transform() vs pipe() behavior and type context switching - Basic Usage guide: practical transformation examples and usage guidelines - API Reference: complete array method documentation with filterEmpty() examples - Document filterEmpty() method for ArrayValidator - Array Validation guide: comprehensive filtering section with real-world use cases - API Reference: type-specific methods section with complete array method docs - Practical examples: form data processing, CSV handling, tag validation - Fix API reference accuracy and remove unimplemented features - Remove unimplemented boolean parameter methods from documentation - Fix method signatures to match actual implementation - Update ROADMAP to focus on existing features only - Update project documentation files - CHANGELOG: add comprehensive documentation achievements to Unreleased - AGENTS.md: update validation capabilities and key metrics - IDEAS.md: reflect completed documentation work and API accuracy - Maintain comprehensive coverage across all guides - Zero dead links with seamless navigation - Complete API documentation with accurate method signatures - Enterprise-grade documentation matching actual implementation
1 parent 25b253b commit e15acff

15 files changed

Lines changed: 797 additions & 196 deletions

AGENTS.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ A comprehensive, fluent validation library for PHP inspired by Valibot and Zod.
2727
- **Form-Safe Coercion** - Empty strings convert to `null` (not dangerous `0`/`0.0`/`false`) for real-world form safety
2828
- **Array Filtering** - `filterEmpty()` method removes empty values while maintaining indexed array structure
2929
- **Type-Aware Transformations** - Revolutionary `transform()` and `pipe()` system with intelligent type context switching
30+
- **Custom Validation** - `satisfies()` method for business logic integration with optional error messages
3031
- **Context-Aware Validation** - Custom validators receive `(value, key, input)` parameters
3132
- **Comprehensive Error Collection** - All validation errors collected, not just the first failure
3233
- **Smart Type Coercion** - Configurable automatic type conversion with form-friendly defaults
3334
- **Fluent API** - Chainable method calls for readable validation code
3435

3536
### Developer Experience
3637
- **Dual Validation Methods** - `validate()` (exception-based) and `tryValidate()` (tuple-based)
37-
- **Custom Validation** - `satisfies()` method for business logic integration with optional error messages
3838
- **Schema Validation** - Nested structure validation with hierarchical error reporting
39+
- **Comprehensive Documentation** - Complete guides, API reference, and real-world examples
3940

4041
## 📚 Documentation Structure
4142

@@ -47,6 +48,8 @@ A comprehensive, fluent validation library for PHP inspired by Valibot and Zod.
4748
### Focused Guides
4849
- **String Validation** - Complete format validation suite with practical examples
4950
- **Numeric Validation** - Integer and float validation with shared constraints
51+
- **Array Validation** - Indexed array validation with filtering and item validation
52+
- **Object Validation** - Schema-based validation for complex structures
5053
- **Custom Validation** - Business logic integration and context-aware validation
5154
- **Error Handling** - Exception vs tuple patterns, structured error reporting
5255

@@ -89,22 +92,28 @@ tests/
8992

9093
## 🎯 Project Status
9194

92-
### Current Version: 0.4.0
93-
- ✅ Complete string validation suite
95+
### Current Version: 0.6.0
96+
- ✅ Complete string validation suite with form-safe handling
9497
- ✅ Dedicated float validator with numeric constraints
9598
- ✅ Static logical combinators for advanced validation logic
9699
- ✅ Instance logical combinators for chaining validation rules
97100
- ✅ Enhanced mixed-type validation support
101+
- ✅ Type-aware transformation system with `transform()` and `pipe()` methods
102+
- ✅ Form-safe coercion - empty strings convert to `null` (not dangerous `0`/`false`)
103+
- ✅ Intuitive custom validation with `satisfies()` method
98104
- ✅ Comprehensive error collection and context-aware validation
105+
- ✅ Complete documentation with `nullifyEmpty()` coverage across all guides
99106
- ✅ Organized test suite and enterprise documentation
100107
- ✅ 100% PHPStan compliance and PHP-CS-Fixer standards
101108

102109
### Key Metrics
103110
- **8 validator types** covering all PHP data types
104-
- **33+ built-in validation methods** including static logical combinators, array filtering, type-aware transformations, and custom validation
105-
- **4,000+ lines of documentation** with practical examples
111+
- **35+ built-in validation methods** including static logical combinators, array filtering, type-aware transformations, form-safe coercion, and intuitive custom validation
112+
- **5,000+ lines of documentation** with practical examples and comprehensive coverage
106113
- **114 unit tests** with comprehensive coverage (290 assertions)
107114
- **Zero technical debt** with modern PHP 8.1+ codebase
115+
- **Zero dead links** in documentation with seamless navigation
116+
- **Complete API documentation** with accurate method signatures and examples
108117

109118
## 🔮 Vision & Roadmap
110119

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Documentation
8+
- **Complete type-aware transformation system documentation** - Added comprehensive coverage for `transform()` and `pipe()` methods
9+
- Added "Data Transformations" section to Core Concepts guide with detailed type context switching explanation
10+
- Added transformation examples to Basic Usage guide with clear usage guidelines
11+
- Documented `filterEmpty()` method for ArrayValidator with practical examples and real-world use cases
12+
- Added "Type-Specific Methods" section to API Reference with complete array method documentation
13+
- Fixed API reference to match actual implementation (removed unimplemented boolean parameter methods)
14+
- Updated ROADMAP to remove unimplemented enhanced methods and focus on existing features
15+
- **Complete `nullifyEmpty()` documentation** - Added comprehensive coverage across all guides and API reference
16+
- Added "Universal Methods" section to API Reference with detailed `nullifyEmpty()` documentation
17+
- Added "Form-Safe String Handling" section to String Validation Guide with practical examples
18+
- Added "Explicit Empty String Nullification" section to Numeric Validation Guide
19+
- Added "Form-Safe Validation with nullifyEmpty()" section to Form Validation Examples
20+
- Added "Empty String Nullification" section to Basic Usage Guide with fundamental patterns
21+
- Updated README.md Quick Start example to showcase `nullifyEmpty()` usage
22+
- **Fixed all dead links in documentation** - Replaced 15 dead links with existing comprehensive guides
23+
- Fixed missing API reference links across all documentation files
24+
- Ensured all internal navigation works properly for seamless user experience
25+
- **Added development notice** - Clear indication that the library is in active development with potential API changes
26+
727
## [0.6.0] - 2025-10-09
828

929
### Fixed

IDEAS.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This document captures innovative ideas and suggestions for potential future enh
44

55
## ✅ Recently Implemented
66

7-
### Type-Aware Transformation System (v0.5.0-dev)
7+
### Type-Aware Transformation System (v0.5.0)
88
**Status**: ✅ **IMPLEMENTED**
99
**Concept**: Revolutionary transformation system with intelligent type context switching.
1010
```php
@@ -18,8 +18,7 @@ $tags = Validator::isArray()->filterEmpty()->validate(['php', '', 'javascript',
1818

1919
// Universal transformations - available on ALL validators
2020
$name = Validator::isString()
21-
->transform('trim')
22-
->transform('strtoupper')
21+
->pipe('trim', 'strtoupper') // Multiple string operations, maintains type
2322
->validate(' john '); // Returns: "JOHN"
2423

2524
// Multiple transformations with pipe
@@ -50,8 +49,13 @@ $formatted = Validator::isString()
5049
- ✅ Clean variadic syntax with `pipe(...$transformers)`
5150
- ✅ Perfect integration with external libraries (Laravel, Symfony)
5251
- ✅ Comprehensive test coverage (114 tests, 290 assertions)
52+
- ✅ Complete documentation overhaul with comprehensive coverage across all guides
53+
- ✅ Fixed all dead links in documentation for seamless navigation
54+
- ✅ Added type-aware transformation system documentation with detailed examples
55+
- ✅ Documented `filterEmpty()` method with practical use cases
56+
- ✅ Updated API reference to match actual implementation
5357

54-
### Intuitive Custom Validation (v0.6.0-dev)
58+
### Intuitive Custom Validation (v0.6.0)
5559
**Status**: ✅ **IMPLEMENTED**
5660
**Concept**: Natural language custom validation with optional error messages.
5761
```php
@@ -84,6 +88,8 @@ $workingAge = Validator::isInt()
8488
- ✅ Backward compatibility with deprecated `addValidation()`
8589
- ✅ Comprehensive documentation updates (65+ references)
8690
- ✅ Enhanced developer experience and API discoverability
91+
- ✅ Complete API documentation with accurate method signatures
92+
- ✅ Fixed documentation inconsistencies and removed unimplemented features
8793

8894
### Static Logical Combinators (v0.4.0)
8995
**Status**: ✅ **IMPLEMENTED**

README.md

Lines changed: 62 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -4,192 +4,101 @@
44
[![Latest Stable Version](https://img.shields.io/packagist/v/lemmon/validator.svg)](https://packagist.org/packages/lemmon/validator)
55
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
66

7-
A comprehensive, fluent validation library for PHP, inspired by Valibot and Zod. Build type-safe, readable validation schemas with chainable methods and intelligent error handling.
7+
> [!NOTE]
8+
> This library is in active development. The API may change in future versions as we refine and improve the developer experience based on real-world usage and feedback.
89
9-
## ✨ Features
10+
Lemmon Validator is a comprehensive, fluent validation and data processing library for PHP that prioritizes developer experience, type safety, and real-world practicality. Inspired by modern validation libraries like Valibot and Zod, it brings a chainable, readable API to PHP for validation, transformation, and sanitization with intelligent error handling and form-safe defaults.
1011

11-
- 🔒 **Type-safe validation** for strings, integers, floats, arrays, and objects
12-
- 🔗 **Fluent, chainable API** for readable and maintainable validation rules
13-
- 📋 **Comprehensive error collection** with detailed, structured feedback
14-
- ⚙️ **Intuitive custom validation** with `satisfies()` method and optional error messages
15-
- 🧩 **Logical combinators** (`Validator::allOf()`, `Validator::anyOf()`, `Validator::not()`) for complex validation logic
16-
- 🔄 **Form-safe coercion** - empty strings become `null` (not dangerous `0`/`false`) for real-world safety
17-
- 🎯 **Schema validation** for nested data structures
18-
-**Universal transformations** (`transform()`, `pipe()`) for post-validation data processing
12+
## Installation
1913

20-
## 🚀 Quick Start
14+
```bash
15+
composer require lemmon/validator
16+
```
17+
18+
**Requirements:** PHP 8.1 or higher
19+
20+
## About
21+
22+
**Philosophy: "Simple and Minimal with Extensibility Over Reinvention"**
23+
24+
Rather than reimplementing every possible transformation or validation rule, Lemmon Validator provides a solid foundation with generic `transform()` and `pipe()` methods that integrate seamlessly with PHP's ecosystem. Need complex string transformations? Plug in Laravel's `Str` class through our transformation system. Need advanced array operations? Connect Laravel Collections via our fluent API. The library focuses on what it does best: type-safe validation with excellent developer experience, while enabling you to leverage the entire PHP ecosystem.
25+
26+
**Key Design Principles:**
27+
28+
- **Form Safety First**: Empty strings coerce to `null` (not dangerous `0`/`false`) to prevent real-world issues like accidental zero bank balances
29+
- **Fluent API**: Validation rules read like natural language - `Validator::isString()->email()->required()`
30+
- **Comprehensive Error Collection**: All validation errors are collected, not just the first failure
31+
- **Type-Aware Transformations**: Intelligent transformation system that maintains type context and handles coercion automatically
32+
- **Extensible Architecture**: Generic transformation methods work with any PHP callable or external library
33+
34+
## Features
35+
36+
- **Type-safe validation** for strings, integers, floats, arrays, and objects
37+
- **Fluent, chainable API** for readable and maintainable validation rules
38+
- **Comprehensive error collection** with detailed, structured feedback
39+
- **Intuitive custom validation** with `satisfies()` method and optional error messages
40+
- **Logical combinators** (`Validator::allOf()`, `Validator::anyOf()`, `Validator::not()`) for complex validation logic
41+
- **Form-safe coercion** - empty strings become `null` (not dangerous `0`/`false`) for real-world safety
42+
- **Schema validation** for nested data structures
43+
- **Universal transformations** (`transform()`, `pipe()`) for post-validation data processing
44+
- **Null-safe operations** with `nullifyEmpty()` method for consistent empty value handling
45+
46+
## Quick Start
2147

2248
```php
2349
use Lemmon\Validator;
2450

25-
// Simple validation
51+
// Simple validation with form-safe coercion
2652
$email = Validator::isString()
2753
->email()
54+
->nullifyEmpty() // Empty strings become null (form-safe)
2855
->validate('user@example.com');
2956

30-
// Schema validation
57+
// Schema validation with custom logic
3158
$userSchema = Validator::isAssociative([
3259
'name' => Validator::isString()->required(),
33-
'age' => Validator::isInt()->min(18),
34-
'email' => Validator::isString()->email(),
35-
'preferences' => Validator::isObject([
36-
'theme' => Validator::isString()->oneOf(['light', 'dark'])->default('light'),
37-
'notifications' => Validator::isBool()->default(true)
38-
])
60+
'age' => Validator::isInt()->min(18)->coerce(),
61+
'email' => Validator::isString()->email()->nullifyEmpty(),
62+
'password' => Validator::isString()->satisfies(fn($v) => strlen($v) >= 8, 'Password too short')
3963
]);
4064

65+
// Tuple-based validation (no exceptions)
4166
[$valid, $user, $errors] = $userSchema->tryValidate($input);
67+
68+
// Exception-based validation
69+
$user = $userSchema->validate($input); // Throws ValidationException on failure
4270
```
4371

44-
## 📚 Documentation
72+
## Documentation
4573

4674
### Getting Started
47-
- 📖 [Installation & Setup](docs/getting-started/installation.md)
48-
- 🎯 [Basic Usage](docs/getting-started/basic-usage.md)
49-
- 💡 [Core Concepts](docs/getting-started/core-concepts.md)
75+
- [Installation & Setup](docs/getting-started/installation.md)
76+
- [Basic Usage](docs/getting-started/basic-usage.md)
77+
- [Core Concepts](docs/getting-started/core-concepts.md)
5078

5179
### Validation Guides
52-
- 🔤 [String Validation](docs/guides/string-validation.md) - Email, URL, patterns, length constraints
53-
- 🔢 [Numeric Validation](docs/guides/numeric-validation.md) - Integers, floats, ranges, constraints
54-
- 📋 [Array Validation](docs/guides/array-validation.md) - Indexed arrays and item validation
55-
- 🏗️ [Object & Schema Validation](docs/guides/object-validation.md) - Complex nested structures
56-
- ⚙️ [Custom Validation](docs/guides/custom-validation.md) - User-defined functions and business logic
57-
- [Error Handling](docs/guides/error-handling.md) - Working with validation errors
80+
- [String Validation](docs/guides/string-validation.md) - Email, URL, patterns, length constraints
81+
- [Numeric Validation](docs/guides/numeric-validation.md) - Integers, floats, ranges, constraints
82+
- [Array Validation](docs/guides/array-validation.md) - Indexed arrays and item validation
83+
- [Object & Schema Validation](docs/guides/object-validation.md) - Complex nested structures
84+
- [Custom Validation](docs/guides/custom-validation.md) - User-defined functions and business logic
85+
- [Error Handling](docs/guides/error-handling.md) - Working with validation errors
5886

5987
### API Reference
60-
- 🏭 [Validator Factory](docs/api-reference/validator-factory.md)
88+
- [Validator Factory](docs/api-reference/validator-factory.md)
6189

6290
### Examples
63-
- 📝 [Form Validation](docs/examples/form-validation.md)
64-
65-
## 📦 Installation
66-
67-
```bash
68-
composer require lemmon/validator
69-
```
70-
71-
**Requirements:** PHP 8.1 or higher
72-
73-
## 🏃‍♂️ Quick Examples
74-
75-
### String Validation with Formats
76-
```php
77-
// Email validation
78-
$email = Validator::isString()->email()->validate('user@example.com');
79-
80-
// URL with custom message
81-
$url = Validator::isString()
82-
->url('Please provide a valid URL')
83-
->validate('https://example.com');
84-
85-
// Pattern matching
86-
$code = Validator::isString()
87-
->pattern('/^[A-Z]{2}\d{4}$/', 'Code must be 2 letters + 4 digits')
88-
->validate('AB1234');
89-
```
90-
91-
### Numeric Validation
92-
```php
93-
// Integer with constraints
94-
$age = Validator::isInt()
95-
->min(18)
96-
->max(120)
97-
->validate(25);
98-
99-
// Form-safe coercion (BREAKING CHANGE in latest version)
100-
$quantity = Validator::isInt()
101-
->coerce() // Empty strings become null (not dangerous 0)
102-
->validate(''); // Returns: null
103-
104-
// Float with precision
105-
$price = Validator::isFloat()
106-
->positive()
107-
->multipleOf(0.01) // Cents precision
108-
->coerce() // Empty strings become null (not dangerous 0.0)
109-
->validate(19.99);
110-
```
111-
112-
### Array Validation
113-
```php
114-
// Array filtering with auto-reindexing
115-
$tags = Validator::isArray()
116-
->filterEmpty() // Removes '', null but keeps 0, false, []
117-
->validate(['php', '', 'javascript', null, 'react']);
118-
// Returns: ['php', 'javascript', 'react'] (properly indexed)
119-
120-
// With item validation
121-
$numbers = Validator::isArray()
122-
->items(Validator::isInt()->positive())
123-
->filterEmpty()
124-
->validate([1, '', 2, null, 3]);
125-
// Returns: [1, 2, 3]
126-
```
127-
128-
### Data Transformations
129-
```php
130-
// Type-preserving transformations with pipe()
131-
$name = Validator::isString()
132-
->pipe('trim', 'strtoupper') // Maintains string type
133-
->validate(' john doe '); // Returns: "JOHN DOE"
134-
135-
// Type-changing transformations with transform()
136-
$count = Validator::isString()
137-
->transform(fn($v) => explode(',', $v)) // String → Array
138-
->pipe('array_unique') // Array operations (auto-reindexed)
139-
->transform('count') // Array → Int
140-
->validate('a,b,a,c'); // Returns: 3
141-
142-
// Complex multi-type chains
143-
$result = Validator::isArray()
144-
->pipe('array_unique', 'array_reverse') // Array operations
145-
->transform(fn($v) => implode(',', $v)) // Array → String
146-
->pipe('trim', 'strtoupper') // String operations
147-
->transform('strlen') // String → Int
148-
->validate(['a', 'b', 'a']); // Returns: 3
149-
```
150-
151-
### Custom Validation
152-
```php
153-
// Context-aware validation with optional error message
154-
$passwordConfirm = Validator::isString()->satisfies(
155-
function ($value, $key, $input) {
156-
return isset($input['password']) && $value === $input['password'];
157-
},
158-
'Password confirmation must match password'
159-
);
160-
161-
// Shorter syntax with default error message
162-
$positiveNumber = Validator::isInt()->satisfies(fn($v) => $v > 0);
163-
```
164-
165-
### Advanced Logic
166-
```php
167-
// Logical combinators
168-
$flexibleId = Validator::anyOf([
169-
Validator::isInt()->positive(),
170-
Validator::isString()->uuid()
171-
]);
172-
173-
$strictUser = Validator::allOf([
174-
Validator::isAssociative(['name' => Validator::isString()]),
175-
Validator::isAssociative(['email' => Validator::isString()->email()])
176-
]);
177-
178-
$notBanned = Validator::not(
179-
Validator::isString()->oneOf(['banned', 'suspended']),
180-
'User cannot be banned or suspended'
181-
);
182-
```
91+
- [Form Validation](docs/examples/form-validation.md)
18392

184-
## 🤝 Contributing
93+
## Contributing
18594

18695
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
18796

188-
## 📄 License
97+
## License
18998

19099
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
191100

192-
## 🔗 Links
101+
## Links
193102

194103
- [Packagist](https://packagist.org/packages/lemmon/validator)
195104
- [GitHub Repository](https://github.com/lemmon/validator-php)

0 commit comments

Comments
 (0)