haspadar / solo
Primitive wrappers for PHP: strong typing for strings, ints, arrays, and more
v0.1.0
2025-07-04 09:30 UTC
Requires
- php: 8.4.*
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3
- infection/infection: ^0.29.14
- nunomaduro/collision: ^8.8
- phpmetrics/phpmetrics: ^3.0
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.2
- rector/rector: ^2.1
- roave/security-advisories: dev-latest
- vimeo/psalm: ^6.10
This package is auto-updated.
Last update: 2025-07-04 21:17:12 UTC
README
๐ฆ About
Mono is a library of immutable value objects that wrap primitive types like string
, int
, bool
, and array
.
Instead of passing around loose values, you use small, self-contained wrappers like:
Lowercased
,Trimmed
,TruncatedRight
(strings)Yes
,IsEmail
,ThrowsIf
(logic)Mapped
,SequenceOf
(collections)
Each class encapsulates one behavior and can be composed with others to form robust, intention-revealing objects.
๐ง Philosophy
- โ No
null
,static
, or shared state in the public API - โ One object = one responsibility
- โ Final classes, immutability by default
- โ Composition over inheritance
- โ Behavior and data live together
Inspired by Elegant Objects and cactoos.
โจ Example
use Mono\Text\Lowercased; use Mono\Text\TruncatedRight; use Mono\Text\Trimmed; $text = new TruncatedRight( new Lowercased( new Trimmed(" Hello, world! ") ), 5 ); echo $text->toString(); // "hello"
Each wrapper adds one behavior:
Trimmed
removes whitespaceTruncatedRight
shortens the string
All wrappers implement the same interface and can be freely composed.
๐งฑ Modules
- Text โ
Trimmed
,Uppercased
,Lowercased
,TruncatedRight
,HtmlSanitized
,LengthOf
,Preview
,TextOf
- Logic โ
Yes
,No
,ThrowsIf
,IsEmpty
,IsEmail
,IsUuid
,LogicEnvelope
- Iterable โ
Sequence
,SequenceOf
,Mapped
,Filtered
- Number โ (coming soon)
Positive
,NonZero
,Rounded
, etc.
๐งช Quality & CI
Every push and pull request is checked via GitHub Actions:
- โ Static analysis with PHPStan (level 9) and Psalm (level 8)
- โ Type coverage report via Shepherd
- โ Code style check with PHP-CS-Fixer (only changed files)
- โ Unit tests with PHPUnit
- โ Code coverage via Codecov
- โ Mutation testing with Infection
- โ Composer validation, platform checks, security audit
- โ Automatic refactoring via Rector
๐ฅ Installation
composer require haspadar/mono
Requires PHP 8.4