PHPackages                             cedriccourteau/variant - 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. cedriccourteau/variant

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

cedriccourteau/variant
======================

A simple ValueObject and ResultType generator for PHP

v0.1(1y ago)094PHPPHP ^8.0

Since Sep 27Pushed 1y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (3)Versions (3)Used By (0)

Variant
=======

[](#variant)

 A simple ValueObject and ResultType generator for PHP

About The Project
-----------------

[](#about-the-project)

[![Screenshot](screenshot.png)](screenshot.png)

Creating Value Objects or Result Types in PHP can be time-consuming compared to creating custom types in other languages. Variant aims to simplify this process by providing a custom, easy-to-use language for prototyping them.

Here's an example of how a type can be generated with Variant:

```
type UserKind {
	User(string name, int companyId)
	Moderator(string name, int companyId)
	Admin(string name)
}

type UpdateError {
	Unauhtorized
	NotFound
}

record Company(string name, int id)

result UpdateCompanyResult(Company, UpdateError)
```

Getting Started
---------------

[](#getting-started)

This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.

### Installation

[](#installation)

```
composer require cedriccourteau/variant
```

Usage
-----

[](#usage)

1. Add a file with the `.variant` extension the desired folder, such as `src/Users/Types/users.variant`
2. Define your types in this file
3. Launch `php ./vendor/bin/variant`
4. Voilà

Syntax of `.variant` files
--------------------------

[](#syntax-of-variant-files)

### Overview

[](#overview)

```
type UserKind {
    User(string name, int companyId)
    Moderator(string name, int companyId)
    Admin(string name)
}

type GetUserError{
    NotFound
    InvalidCredentials
    Unauthorized
    BusyDB
}

result GetUserResult(UserKind, GetUserError)
```

### Available instructions

[](#available-instructions)

### record

[](#record)

Hold a single ValueObject with custom constructor. Everything between the parenthesis are like in php but without the `$` for param declaration.

```
record ( , etc)
```

#### type

[](#type)

It encapsulates records into a global type, translated into a `Interface`. Between the `{}` you add custom variants for this type

```
type  {

  ( , ...)
}
```

### result

[](#result)

Create a custom Result type with an `Ok` value and an `Error` type.

```
result (, )
```

If the `ERROR_TYPE` is a defined type in the current `.variant` file, it binds the type to a type union of all of its variants.

Example:

```
type GetUserError{
    NotFound
    InvalidCredentials
    Unauthorized
    BusyDB
}

# It will translate GetUserError onto NotFound|InvalidCredentials|Unauthorized|BusyDB
result GetUserResult(UserKind, GetUserError)
```

Cli options
-----------

[](#cli-options)

```
Options:
  --force          Force mode; recreate files even if they exist.
  --path=    Specify the path to search in (default: src/).
  --namespace= Specify the namespace to use.
  --help           Display this help message.

```

Contributing
------------

[](#contributing)

Contributions are welcome! Feel free to fork, use, and improve the project.

License
-------

[](#license)

Distributed under the MIT License. Fork it, use it, make it better.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

589d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/91459aa54c8652be2702e825b6664a27f0a8128390ab9a515728bf5ff4a49a40?d=identicon)[AsymetricData](/maintainers/AsymetricData)

---

Top Contributors

[![AsymetricData](https://avatars.githubusercontent.com/u/95305150?v=4)](https://github.com/AsymetricData "AsymetricData (6 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/cedriccourteau-variant/health.svg)

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

###  Alternatives

[symfony/polyfill-php72

Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions

4.8k674.7M31](/packages/symfony-polyfill-php72)[symfony/polyfill-intl-icu

Symfony polyfill for intl's ICU-related data and classes

2.6k251.4M96](/packages/symfony-polyfill-intl-icu)[nette/php-generator

🐘 Nette PHP Generator: generates neat PHP code for you. Supports new PHP 8.5 features.

2.2k64.2M574](/packages/nette-php-generator)[consolidation/site-process

A thin wrapper around the Symfony Process Component that allows applications to use the Site Alias library to specify the target for a remote call.

5345.3M8](/packages/consolidation-site-process)[sycho/flarum-profile-cover

Adds the ability to add a cover image to a profile.

1836.6k](/packages/sycho-flarum-profile-cover)

PHPackages © 2026

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