Skip to content

Commit 44c73d1

Browse files
committed
Refactor documentation, examples, and scripts for clarity and usability improvements
- Streamlined README and usage examples for improved readability. - Enhanced descriptions and formatting of features and type examples. - Refined installation and development guides to include new Composer scripts (`oncheckout`, `oncommit`). - Consolidated and updated static type usage examples across docs. - Improved alignment of documentation with recent architectural changes and naming conventions.
1 parent 5209343 commit 44c73d1

File tree

4 files changed

+207
-129
lines changed

4 files changed

+207
-129
lines changed

README.md

Lines changed: 26 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
PHP Typed Values
22
================
33

4-
Typed value objects for common PHP data types. Make primitives explicit, safe, and self-documenting with tiny immutable value objects.
4+
PHP 8.2 typed value objects for common PHP data types.
55

66
[![Latest Version on Packagist](https://img.shields.io/packagist/v/georgii-web/php-typed-values.svg?style=flat-square)](https://packagist.org/packages/georgii-web/php-typed-values)
77
[![Tests](https://github.com/georgii-web/php-typed-values/actions/workflows/php.yml/badge.svg)](https://github.com/georgii-web/php-typed-values/actions/workflows/php.yml)
88
[![Total Downloads](https://img.shields.io/packagist/dt/georgii-web/php-typed-values.svg?style=flat-square)](https://packagist.org/packages/georgii-web/php-typed-values)
99

10-
- Requires PHP 8.2+
11-
- Zero runtime dependencies
12-
- Tooling: Pest, PHPUnit, Psalm, PHP-CS-Fixer
10+
## Why Use This Library?
1311

14-
Quick links:
15-
- Install: docs/INSTALL.md
16-
- Usage: docs/USAGE.md
17-
- Development: docs/DEVELOP.md
12+
- Make data safer through strong typing and validation.
13+
- Improve readability with self-documenting types.
14+
- Use tiny immutable objects as building blocks for larger value objects.
15+
- Fit naturally into DDD (Domain-Driven Design) shared domain models.
16+
- Work well with CQRS by expressing clear intent in commands and queries.
1817

1918
Install
2019
-------
@@ -28,80 +27,36 @@ composer require georgii-web/php-typed-values
2827
Usage
2928
-----
3029

31-
Create and use typed values with validation built in.
30+
Create and use typed values with validation built in:
3231

3332
```php
34-
// Integers
35-
use PhpTypedValues\Integer\IntegerBasic;
36-
use PhpTypedValues\Integer\PositiveInt;
37-
use PhpTypedValues\Integer\NonNegativeInt;
38-
use PhpTypedValues\Integer\WeekDayInt;
39-
40-
$age = new PositiveInt(27); // ok (positive-int)
41-
$retries = new NonNegativeInt(0); // ok (0 or positive)
42-
$weekday = new WeekDayInt(5); // ok (1..7)
43-
$anyInt = new IntegerBasic(-42); // ok (any integer)
44-
45-
$fromString = PositiveInt::fromString('123');
46-
47-
// Strings
48-
use PhpTypedValues\String\StringBasic;
49-
use PhpTypedValues\String\NonEmptyStr;
50-
51-
$greeting = StringBasic::fromString('hello');
52-
$name = new NonEmptyStr('Alice'); // throws if empty
53-
54-
// Floats
55-
use PhpTypedValues\Float\FloatBasic;
56-
use PhpTypedValues\Float\NonNegativeFloat;
57-
58-
$price = FloatBasic::fromString('19.99');
59-
$ratio = new NonNegativeFloat(0.5); // >= 0 allowed
60-
61-
// Access the underlying scalar value / string form
62-
$ageValue = $age->value(); // 27
63-
echo $weekday->toString(); // "5"
64-
echo $price->toString(); // "19.99"
33+
$id = PositiveInt::fromString('123');
6534
```
6635

67-
All value objects are immutable; invalid input throws an exception with a helpful message.
68-
69-
Provided types (so far):
70-
71-
- Integers
72-
- IntegerBasic — any PHP integer
73-
- PositiveInt — positive integer (> 0)
74-
- NonNegativeInt — zero or positive integer (>= 0)
75-
- WeekDayInt — integer in range 1..7
76-
- Strings
77-
- StringBasic — any PHP string
78-
- NonEmptyStr — non-empty string
79-
- Floats
80-
- FloatBasic — any PHP float
81-
- NonNegativeFloat — zero or positive float (>= 0)
36+
instead of duplicating this logic across your application like:
8237

83-
- DateTime
84-
- DateTimeBasic — immutable DateTime value (parses common ISO-8601 formats)
38+
```php
39+
$id = (int) '123';
40+
if ($id <= 0) {
41+
throw new InvalidArgumentException('Invalid ID');
42+
}
43+
```
8544

86-
Why
87-
---
45+
## Key Features
8846

89-
- Replace loose primitives with explicit, intention-revealing types
90-
- Centralize validation in one place
91-
- Improve static analysis and readability
47+
- **Static analysis** – Designed for tools like Psalm and PHPStan with precise type annotations.
48+
- **Strict types** – Uses `declare(strict_types=1);` and strict type hints throughout.
49+
- **Validation** – Validates input on construction so objects can’t be created in an invalid state.
50+
- **Immutable** – Value objects are read‑only and never change after creation.
51+
- **No external dependencies** – Pure PHP implementation without requiring third‑party packages.
9252

93-
Scripts
53+
More information
9454
-------
9555

96-
Helpful Composer scripts are included:
97-
98-
- composer test - run tests (Pest)
99-
- composer type - 100% type coverage gate
100-
- composer coverage - code coverage gate
101-
- composer sca - static analysis (Psalm)
102-
- composer cs - coding standards (PHP-CS-Fixer)
56+
See [docs/INSTALL.md](docs/INSTALL.md) for installation instructions.
57+
See [docs/USAGE.md](docs/USAGE.md) for usage examples.
58+
See [docs/DEVELOP.md](docs/DEVELOP.md) for development details.
10359

104-
See docs/DEVELOP.md for details.
10560

10661
License
10762
-------

docs/DEVELOP.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,50 @@ Convenient scripts are defined in composer.json:
2323

2424
- composer test — run test suite (Pest)
2525
- composer type — enforce 100% type coverage via Pest plugin
26-
- composer coverage — run tests with coverage threshold
26+
- composer coverage — run tests with a coverage threshold
2727
- composer sca — static analysis via Psalm
2828
- composer cs — fix coding style with PHP-CS-Fixer
2929

30-
You can chain pre-commit checks via:
30+
After checkout: prepare the project
31+
-----------------------------------
32+
33+
Before you start developing or running examples/tests, run the following Composer script to ensure your local environment is ready and all the latest packages are installed:
34+
35+
```
36+
composer oncheckout
37+
```
38+
39+
This script will:
40+
41+
- install/update Composer dependencies
42+
- regenerate the autoloader (composer dump-autoload)
43+
- clear Psalm cache to avoid stale analysis state
44+
45+
Run it right after cloning the repository or switching branches so that you work against the latest dependencies and tools.
46+
47+
Before PR: run full checks
48+
--------------------------
49+
50+
Before opening a Pull Request, run the following Composer script to execute the full local QA pipeline and ensure your changes pass all checks:
3151

3252
```
3353
composer oncommit
3454
```
3555

56+
This script will run, in order:
57+
58+
- composer validate (strict mode)
59+
- coding style fix/checks (PHP-CS-Fixer)
60+
- static analysis (Psalm)
61+
- test suite (Pest)
62+
- type coverage check (100% via Pest plugin)
63+
- code coverage check (100% minimum)
64+
- mutation tests (threshold as configured)
65+
66+
If this command succeeds locally, your PR should pass CI checks.
67+
68+
69+
3670
Project layout
3771
--------------
3872

@@ -81,5 +115,5 @@ Contributing
81115

82116
1. Fork and create a feature branch
83117
2. Make changes with tests
84-
3. Run composer oncommit to ensure checks pass
118+
3. Run `composer oncommit` to ensure checks pass
85119
4. Open a PR

docs/INSTALL.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ require __DIR__ . '/vendor/autoload.php';
3333

3434
use PhpTypedValues\Integer\PositiveInt;
3535

36-
$age = new PositiveInt(21);
37-
echo $age->value(); // 21
36+
echo PositiveInt::fromString('21')->value(); // 21
3837
```
3938

4039
Run it:
@@ -43,4 +42,4 @@ Run it:
4342
php demo.php
4443
```
4544

46-
If you see 21 printed, the library is installed correctly.
45+
If you see '21' printed, the library is installed correctly.

0 commit comments

Comments
 (0)