PHPackages                             mudandstars/sync-enum-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. mudandstars/sync-enum-types

ActiveLibrary

mudandstars/sync-enum-types
===========================

This is my package sync-enum-types

v1.3(2y ago)34.8kMITPHPPHP ^8.1

Since May 3Pushed 2y ago1 watchersCompare

[ Source](https://github.com/mudandstars/sync-enum-types)[ Packagist](https://packagist.org/packages/mudandstars/sync-enum-types)[ Docs](https://github.com/mudandstars/sync-enum-types)[ RSS](/packages/mudandstars-sync-enum-types/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (10)Versions (7)Used By (0)

This is my package sync-enum-types
==================================

[](#this-is-my-package-sync-enum-types)

[![Latest Version on Packagist](https://camo.githubusercontent.com/036f97a5d05c9671c1670ca3f4e631e91b7c84ad01fb9782532a2233429680a8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d7564616e6473746172732f73796e632d656e756d2d74797065732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mudandstars/sync-enum-types)[![GitHub Tests Action Status](https://camo.githubusercontent.com/3ad11b136c9101f41d66b15abedbf3aaad06f5ca387375c3d40be544e1dd7c90/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d7564616e6473746172732f73796e632d656e756d2d74797065732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/mudandstars/sync-enum-types/actions?query=workflow%3Arun-tests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/01df1abaad825aea5bc0619fc00d8d2bac796ee92c365c6bb37c8e1521dd0f5b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d7564616e6473746172732f73796e632d656e756d2d74797065732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mudandstars/sync-enum-types)

This package ships a command that creates typescript declaration files for your php Enums. This command can be set so it automatically runs on-save, for example.

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

[](#installation)

You can install the package via composer:

```
composer require mudandstars/sync-enum-types --dev
```

Usage (VS Code)
---------------

[](#usage-vs-code)

1. Check if the published config needs changes, based on your project structure
2. Install the 'Run on Save' Extension
3. Add the 'Run on Save' command to your settings.json (I like the workspace settings for this):

```
{
	...other settings

	"emeraldwalk.runonsave": {
		"commands": [
			{
				"match": ".*/Enum/.*\\.php$",
				"cmd": "php artisan sync-enum-types"
			}
		]
	}
}
```

Configuration
-------------

[](#configuration)

You can publish the config file with:

```
php artisan vendor:publish --tag="sync-enum-types-config"
```

The recommended config has SYNC\_CASES set to true to provide the enum cases as typed array for use in the frontend. Its latest version looks like this:

```
// config/sync-enum-types.php
return [
    'PHP_ENUM_FOLDER_DESTINATION' => app_path('Enum'),
    'TYPESCRIPT_ENUM_FOLDER_DESTINATION' => app_path('../resources/ts/types/Enum'),

    'SYNC_CASES' => true,
    'CASES_FOLDER_DESTINATION' => app_path('../resources/ts/EnumCases'),

    'EXCEPTIONS' => [],
]
```

Possible Enum Features and Flags
--------------------------------

[](#possible-enum-features-and-flags)

### Using Custom Method's Description

[](#using-custom-methods-description)

To avoid conflicts with existing data when changing Enum values in your database, some engineers prefer to use simple integers as their values and make use of functions to describe what the values represent, like the following:

```
enum MyEnum: int
{
    case FIRST_CASE = 1;
    case SECOND_CASE = 2;

    public function description(): string
    {
        return match($this) {
            self::FIRST_CASE => 'first case description',
            self::SECOND_CASE => 'second case description',
        };
    }

    public function someOtherFunction()...
}
```

If you want to sync the descriptions from an Enum's method instead of its cases' values, put the sync-using-method flag above the corresponding function like so:

```
enum MyEnum: int
{
    case FIRST_CASE = 1;
    case SECOND_CASE = 2;

    // @sync-enum-types: sync-using-method
    public function description(): string
    {
        return match($this) {
            self::FIRST_CASE => 'first case description',
            self::SECOND_CASE => 'second case description',
        };
    }

    public function someOtherFunction()...
}
```

### Linking Other Enums

[](#linking-other-enums)

To maintain a single source of truth when using many Enums, sometimes it is necessary to define a case like this:

```
    case MY_CASE = MyOtherEnum::ITS_CASE->value;
```

This is automatically handled correctly and resolves the value of the other Enum, as long as its source file also resides in the same directory.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Paul Sochiera](https://github.com/mudandstars)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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

Recently: every ~6 days

Total

6

Last Release

991d ago

Major Versions

v0.8 → v1.02023-08-05

### Community

Maintainers

![](https://www.gravatar.com/avatar/79c95fd7f8a8a9305aa0b66cbcf3d05862f4069a505355d6e57cf8f914ee4405?d=identicon)[mudandstars](/maintainers/mudandstars)

---

Top Contributors

[![mudandstars](https://avatars.githubusercontent.com/u/94740279?v=4)](https://github.com/mudandstars "mudandstars (44 commits)")

---

Tags

laravelmudandstarssync-enum-types

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/mudandstars-sync-enum-types/health.svg)

```
[![Health](https://phpackages.com/badges/mudandstars-sync-enum-types/health.svg)](https://phpackages.com/packages/mudandstars-sync-enum-types)
```

###  Alternatives

[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[spatie/laravel-prometheus

Export Laravel metrics to Prometheus

2651.3M6](/packages/spatie-laravel-prometheus)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)[scalar/laravel

Render your OpenAPI-based API reference

6183.9k2](/packages/scalar-laravel)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)[musahmusah/laravel-multipayment-gateways

A Laravel Package that makes implementation of multiple payment Gateways endpoints and webhooks seamless

852.2k1](/packages/musahmusah-laravel-multipayment-gateways)

PHPackages © 2026

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