PHPackages                             xtompie/result - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. xtompie/result

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

xtompie/result
==============

Functional handling failures, input errors

1.9(1y ago)08.4k↓82.8%3MITPHPPHP &gt;=8.0

Since Dec 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/xtompie/result)[ Packagist](https://packagist.org/packages/xtompie/result)[ RSS](/packages/xtompie-result/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (12)Used By (3)

Result
======

[](#result)

Simple class for handling failures, input errors

```
use Xtompie\Result\Result;

$rand = rand(0, 1);
$result = $rand%2 == 0 ? Result::ofSuccess($rand) : Result::ofErrorMsg("the number $rand is not even");
if ($result->success()) {
    echo "OK: {$result->value()}";
}
else if ($result->fail()) {
    echo "Error: {$result->errors()->first()->message()}";
}
```

Requiments
----------

[](#requiments)

PHP &gt;= 8.0

Installation
------------

[](#installation)

Using [composer](https://getcomposer.org/)

```
composer require xtompie/result

```

Docs
----

[](#docs)

Result is in state success or fail. Success optionaly contains value. Fail optionaly contains errors. Error can have message, key and space. Message is for human readable text. Key is for error idetify for programs. Space is for idetify property or path of error.

### Creation

[](#creation)

```
Result::ofSuccess(); // success without value
Result::ofValue(mixed $value); // success with value
Result::ofFail(); // fail without errors
Result::ofError(Error $error); // fail with one error
Result::ofErrorMsg(?string $message, ?string $key = null, ?string $space = null); // fail with one error
Result::ofErrors(ErrorCollection $errors); // fail with errors
Result::ofCombine(Result ...$results):
// combined many results, fail when any of results fail
// when fail errors are merged
// when success, first value is used
```

Usage example
-------------

[](#usage-example)

```
namespace App\User\Application\Service\CreateUser;

use Xtompie\Result\Result;

class CreateUserResult extends Result
{
    public static function ofUserId(strign $userId): static
    {
        return parent::ofValue($userId);
    }

    public function userId(): string
    {
        return $this->value();
    }
}

class CreateUserService
{
    public function __invoke(string $email): Result
    {
        if (strlen($email) === 0) {
            return Result::ofErrorMsg('Email required', 'required', 'email');
        }

        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            return Result::ofErrorMsg('Invalid email', 'email', 'email');
        }

        if ($this->dao->exists('user', ['email' => $email])) {
            return Result::ofErrorMsg('Email exists', 'exists', 'email');
        }

        $id = $this->dao->insert('user', ['email' => $email]);

        return Result::ofUserId($id);
    }
}

namespace App\User\UI\Controller;

use App\User\Application\Service\CreateUser\CreateUserService;
use App\User\UI\Request\Request;

class ApiUsersPostController
{
    public function __construct(
        protected CreateUserService $createUserService,
        protected Request $request,
    ) {}

    public function __invoke()
    {
        $result = ($this->createUserService)((string)$this->request->input('email'));
        if ($result->fail()) {
            return [
                'success' => false,
                'error' => [
                    'msg' => $result->errors()->first()?->message(),
                    'key' => $result->errors()->first()?->key(),
                    'space' => $result->errors()->first()?->space(),
                ],
            ];
        }

        return [
            'success' => true,
            'body' => [
                'id' => $result->userId(),
            ],
        ];
    }
}
```

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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 ~104 days

Recently: every ~151 days

Total

11

Last Release

634d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0c1316cdb671814b72350d75b23d7cafbde97ead0c21ac5613171a298bb15736?d=identicon)[xtompie](/maintainers/xtompie)

---

Top Contributors

[![xtompie](https://avatars.githubusercontent.com/u/69162230?v=4)](https://github.com/xtompie "xtompie (12 commits)")

---

Tags

errorresultfail

### Embed Badge

![Health badge](/badges/xtompie-result/health.svg)

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

###  Alternatives

[genesis/behat-fail-aid

Get more out of your test suite by getting it to work with you when tests fail. Screenshots and more. Works with Goutte and MinkExtension.

271.6M20](/packages/genesis-behat-fail-aid)[liliuwei/thinkphp-jump

适用于thinkphp6.0+的跳转扩展

2876.7k1](/packages/liliuwei-thinkphp-jump)

PHPackages © 2026

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