haspadar / primus
Primitive wrappers for PHP: strong typing for strings, ints, arrays, and more
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/haspadar/primus
Requires
- php: 8.2.*
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3
- haspadar/psalm-eo-rules: dev-main
- infection/infection: ^0.29.14
- nunomaduro/collision: ^8.0
- phpmetrics/phpmetrics: ^3.0
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^10.5
- rector/rector: ^2.0
- vimeo/psalm: ^6.13
- dev-main
- v0.2.0
- v0.1.0
- dev-feature/func-scalar
- dev-ci/infection-badge
- dev-feature/text-components
- dev-chore/rename-to-primus
- dev-mono-rename
- dev-kill-mutants
- dev-15-validations
- dev-12-scalar
- dev-9-disable-deptrac
- dev-8-text-envelope
- dev-feature/6-text-component
- dev-chore/4-ci-pipeline
- dev-chore/2-test-scripts-and-lock
This package is auto-updated.
Last update: 2025-11-12 07:17:14 UTC
README
๐ฆ About
Primus 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:
Lowered,Trimmed,Sub(strings)Yes,No,IsEmpty,IsEmail,IsUuid,LogicEnvelope(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
$text = new Sub( new Lowered( new Trimmed(" Hello, world! ") ), 5 ); echo $text->value(); // "hello"
Each wrapper adds one behavior:
Trimmedremoves whitespaceTruncatedRightshortens the string
All wrappers implement the same interface and can be freely composed.
๐งฑ Modules
- Text โ
Trimmed,Uppered,Lowered,Sub,WithoutTags,LengthOfText,Abbreviated,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
๐งฉ Static Analysis Rules
Primus enforces Elegant Objects design principles using
haspadar/psalm-eo-rules โ a custom Psalm plugin that forbids:
staticmethods and propertiesnull,isset(), andempty()- non-
readonlymutable state - traits and inheritance misuse
These checks guarantee immutability and strict object boundaries across all modules.
๐ฅ Installation
composer require haspadar/primus
Requires PHP 8.2