PHPackages                             haspadar/primus - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. haspadar/primus

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

haspadar/primus
===============

Primitive wrappers for PHP: strong typing for strings, ints, arrays, and more

v0.5.0(6mo ago)43MITPHPPHP 8.2.\*CI passing

Since Jun 4Pushed 6mo agoCompare

[ Source](https://github.com/haspadar/primus)[ Packagist](https://packagist.org/packages/haspadar/primus)[ RSS](/packages/haspadar-primus/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (9)Versions (25)Used By (0)

   ![Primus logo](docs/primus-banner-light.svg)

[![CI](https://github.com/haspadar/primus/actions/workflows/ci.yml/badge.svg)](https://github.com/haspadar/primus/actions/workflows/ci.yml)[![Coverage](https://camo.githubusercontent.com/b98593b89787fd315fa9c31a996447d7d46e3fd23cc054c5fb433f82166daa25/68747470733a2f2f636f6465636f762e696f2f67682f68617370616461722f7072696d75732f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/haspadar/primus)[![Mutation testing badge](https://camo.githubusercontent.com/90bf1b87f989d9285305f9506f3ec3807098adf8a09340dd422c9488ce8a4db9/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d25324668617370616461722532467072696d75732532466d61696e)](https://dashboard.stryker-mutator.io/reports/github.com/haspadar/primus/main)[![PHPStan Level](https://camo.githubusercontent.com/942bdbddc7b2adea1d63ed80793492d06d72ef41911edcba33310d0745581548/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c253230392d627269676874677265656e)](https://phpstan.org/)[![Psalm](https://camo.githubusercontent.com/8ed831918c897d26a357e18e30ccfe73b2882f59ffe3b9980abbc1b9f57257f4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7073616c6d2d6c6576656c253230382d627269676874677265656e)](https://psalm.dev)

[![Hits-of-Code](https://camo.githubusercontent.com/a0e28d09868834343f01851c209dc64b80f231d0cdc29e9aea37181079118161/68747470733a2f2f686974736f66636f64652e636f6d2f6769746875622f68617370616461722f7072696d75733f6272616e63683d6d61696e)](https://hitsofcode.com/github/haspadar/primus/view?branch=main)[![CodeRabbit Pull Request Reviews](https://camo.githubusercontent.com/91ddf93ac83132d5e534b52d0eb0ad14dc6717385fb26fc762b71aabdcb1b518/68747470733a2f2f696d672e736869656c64732e696f2f636f64657261626269742f7072732f6769746875622f68617370616461722f7072696d75733f6c6162656c436f6c6f723d31373137313726636f6c6f723d464635373041266c6162656c3d436f64655261626269742b52657669657773)](https://coderabbit.ai)

---

Object‑Oriented PHP Primitives
==============================

[](#objectoriented-php-primitives)

Primus is a library of object‑oriented PHP primitives.
It provides common operations as small composable objects instead of functions.

Inspired by **Elegant Objects** and **cactoos**.

---

📦 Core Idea
-----------

[](#-core-idea)

Procedural PHP:

```
strtolower(trim(substr($s, 0, 5)));
```

Primus:

```
(new Sub(
    new Lowered(
        new Trimmed($s)
    ),
    5
))->value();
```

Each object represents exactly one operation.
Objects are immutable, final, and easy to combine.

---

🧭 Quick Reference
-----------------

[](#-quick-reference)

ProceduralPrimus`trim($s)``new Trimmed($s)``strtolower($s)``new Lowered($s)``substr($s, 0, 5)``new Sub($s, 5)``strip_tags($s)``new WithoutTags($s)``strlen($s)``new LengthOfText($s)``array_map(fn, $a)``new Mapped($a, new FuncOf(fn))``array_filter($a, fn)``new Filtered($a, new PredicateOf(fn))`---

🧱 Modules
---------

[](#-modules)

### **Text**

[](#text)

Trimmed, Lowered, Uppered, Sub, WithoutTags, Abbreviated, LengthOfText, TextOf

### **Logic**

[](#logic)

Yes, No, IsEmpty, IsEmail, IsUuid, IsUrl, ThrowsIf, LogicEnvelope

### **Scalar**

[](#scalar)

ScalarOf, ScalarEnvelope, EqualTo, GreaterThan, LessThan, Ternary, Sticky

### **Func**

[](#func)

Func, FuncOf, FuncEnvelope, BiFunc, Proc, Predicate, StickyFunc, Repeated

### **Iterator**

[](#iterator)

IteratorOf, Mapped, Filtered, Joined, NoNulls

### **Iterable**

[](#iterable)

IterableOf, Mapped, Filtered, Joined, NoNulls

### **Numeric (WIP)**

[](#numeric-wip)

Positive, NonZero, Rounded

---

🧠 Design Principles
-------------------

[](#-design-principles)

- No `null`
- No `static`
- No procedural helpers
- No mutable state
- Immutable objects
- Final classes
- One class = one behavior
- Composition over inheritance

---

🧪 Testing &amp; Static Analysis
-------------------------------

[](#-testing--static-analysis)

Primus includes:

- Custom PHPUnit constraints (`HasIteratorValues`, `EqualsValue`, …)
- Mutation testing (Infection)
- Static analysis:
    - PHPStan level 9
    - Psalm + `haspadar/psalm-eo-rules`

The Psalm rules enforce:

- No `static`
- No `null`
- No `isset()` / `empty()`
- All state must be `readonly`
- No traits or unnecessary inheritance

---

📥 Installation
--------------

[](#-installation)

```
composer require haspadar/primus
```

Requires **PHP ≥ 8.2**

---

📄 License
---------

[](#-license)

[MIT](LICENSE)

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance69

Regular maintenance activity

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~34 days

Total

5

Last Release

180d ago

PHP version history (2 changes)v0.1.0PHP 8.4.\*

v0.2.0PHP 8.2.\*

### Community

Maintainers

![](https://www.gravatar.com/avatar/ec73106a22454440d5cce0b20c1aa2704983da11ba9249dd98e98bad9bb70b58?d=identicon)[haspadar](/maintainers/haspadar)

---

Top Contributors

[![haspadar](https://avatars.githubusercontent.com/u/1282194?v=4)](https://github.com/haspadar "haspadar (52 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/haspadar-primus/health.svg)

```
[![Health](https://phpackages.com/badges/haspadar-primus/health.svg)](https://phpackages.com/packages/haspadar-primus)
```

###  Alternatives

[symfony/polyfill-apcu

Symfony polyfill backporting apcu\_\* functions to lower PHP versions

63280.0M153](/packages/symfony-polyfill-apcu)[pentatrion/vite-bundle

Vite integration for your Symfony app

2755.3M13](/packages/pentatrion-vite-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
