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

v0.2.0 2025-11-08 19:55 UTC

README

Primus logo

CI Coverage Mutation testing badge PHPStan Level Psalm CodeRabbit Pull Request Reviews

๐Ÿ“ฆ 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:

  • Trimmed removes whitespace
  • TruncatedRight shortens 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:

  • static methods and properties
  • null, isset(), and empty()
  • non-readonly mutable 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

๐Ÿ“„ License

MIT