PHPackages                             trehinos/thor-safe-types - 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. trehinos/thor-safe-types

Abandoned → [trehinos/thor-common](/?search=trehinos%2Fthor-common)Library[Utility &amp; Helpers](/categories/utility)

trehinos/thor-safe-types
========================

Some safe types for PHP 8.4 and above.

11PHP

Since Feb 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Trehinos/thor-safe-types)[ Packagist](https://packagist.org/packages/trehinos/thor-safe-types)[ RSS](/packages/trehinos-thor-safe-types/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Thor Safe Types package
=======================

[](#thor-safe-types-package)

Provides some safe types.

Interfaces
----------

[](#interfaces)

- `Unwrap` &amp;`Matchable`, extended by :
    - `Option`
    - `Either`
    - `Validate`

Types hierarchy
---------------

[](#types-hierarchy)

- `Validator` : a derivable `Closure` class which encapsulate a `fn(mixed): bool`.
- Unwrap :
    - `final Result` (with `enum ResultType`),
    - with Matchable :
        - Option (with `enum Maybe`) :
            - `abstract SomeOrNone` :
                - `final Some`
                - `final None`,
        - Either (with `enum EitherCase`) :
            - `final Neither`
            - `final Both`,
            - `abstract LeftOrRight` :
                - `final Left`
                - `final Right`,
        - Validate :
            - `final Validated`

Types details
-------------

[](#types-details)

### Unwrap

[](#unwrap)

An interface defining utility methods for extracting contained values from a structure.

- `unwrapOrElse(callable $ifNot): mixed` : returns the contained value if it is safe to return or else calls the function `$ifNot` and returns its returned value.
- `unwrapOr(mixed $default): mixed` : returns the contained value if it is safe to return or else returns `$default`.
- `unwrapOrThrow(Throwable): mixed` : returns the contained value if it is safe to return or else throws the specified `Throwable`.
- `unwrap(): mixed` : returns the contained value if it is safe to return or else throws a predefined `Throwable`.

> - Extended by the interfaces `Option`, `Either` and `Validate`.
> - Implemented partially by the trait `UnwrapOrThrow` :
>     - needs `unwrapOrElse()`.
> - Implemented by the final class `Result`.

---

### Matchable

[](#matchable)

- `match(callable $ifA, callable $ifB)` : Call the function `$ifA` if some conditions are met or else `$ifB`. It returns the value returned by the called function.

> - Extended by the interfaces `Option`, `Either` and `Validate`.

---

### Option

[](#option)

> Extends `Unwrap` and `Matchable`.

The `Maybe` enumeration has the cases `SOME` and `NONE`.

- `is(): Maybe` : returns the nature of the Option `Maybe::SOME` or `Maybe::NONE`.
- `isNone(): bool` : this function return `true` if the Option contains no value.
- `isSome(): bool` : this function return `false` if the Option contains a value.
- `isA(Maybe $maybe): bool` : returns true if the `Option` corresponds the nature described by the specified `Maybe`.
- `map(callable(mixed): mixed $f): $this` : returns a `Some($value)` if this `Option::isSome()` else returns a `None`.
- `from(mixed $data): static` : creates an `Option` according to the specified value.

> - Partially implemented by the abstract class `SomeOrNone` :
>     - needs `match()` and `is()`,
> - Implemented by the final types `Some` and `None`.

---

### Either

[](#either)

> Extends `Unwrap` and `Matchable`.

The `EitherCase` enumeration has the cases `LEFT` and `RIGHT`.

- `isA(EitherCAse): bool`
- `isLeft(): bool`
- `toLeft(): Left`
- `left(): Option`
- `leftOr(mixed): mixed`
- `isRight(): bool`
- `toRight(): Right`
- `right(): Option`
- `rightOr(mixed): mixed`

> - Partially implemented by the abstract class `LeftOrRight` :
>     - needs `is()`,
>     - implemented by the final types `Left` and `Right`,
> - Implemented by the final types `Both` and `Neither`.

---

### Validate

[](#validate)

> Extends `Unwrap` and `Matchable`.

- `toOption(): Option`
- `isValid(): bool`
- `isInvalid(): bool`

> Implemented by `Validated`.

License
-------

[](#license)

Copyright 2025 Sébastien GELDREICH

License MIT

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity17

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![Trehinos](https://avatars.githubusercontent.com/u/3908278?v=4)](https://github.com/Trehinos "Trehinos (10 commits)")

### Embed Badge

![Health badge](/badges/trehinos-thor-safe-types/health.svg)

```
[![Health](https://phpackages.com/badges/trehinos-thor-safe-types/health.svg)](https://phpackages.com/packages/trehinos-thor-safe-types)
```

PHPackages © 2026

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