PHPackages                             mstovicek/state-machine - 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. mstovicek/state-machine

AbandonedLibrary

mstovicek/state-machine
=======================

Simple state machine

010PHP

Since Jan 16Pushed 8y agoCompare

[ Source](https://github.com/mstovicek/showcase-state-machine)[ Packagist](https://packagist.org/packages/mstovicek/state-machine)[ RSS](/packages/mstovicek-state-machine/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Objection
---------

[](#objection)

Create a library which will be validating transitions between states and implement the following graph of advert states using it:

```
               ,---------.
      |------> | Limited |
      |        `---------'
      |            |
      |            ˅
   ,-----.     ,--------.     ,----------.     ,---------.
   | New | --> | Active | --> | Outdated | --> | Removed |
   `-----'     `--------'     `----------'     `---------'
                   ˄               |
                   |---------------|

```

**Package is for demonstration purpose only!**

Usage
-----

[](#usage)

### Install as a project dependency

[](#install-as-a-project-dependency)

```
$ composer require mstovicek/state-machine

```

### Classes and methods

[](#classes-and-methods)

`\StateMachine\StateMachine` implements `\StateMachine\StateMachineInterface` with following methods:

- `allowStates` - accepts array of allowed states as an only parameter, transitions are allowed only for such states
- `allowTransition` - accepts 2 parameters - `from` and `to` - and registers a transition between them
- `canTransit` - accepts 2 parameters - `from` and `to` and return boolean `true` if such transition is allowed, `false` otherwise

Developer usage
---------------

[](#developer-usage)

### Install dependencies

[](#install-dependencies)

```
$ composer install

```

### Run tests

[](#run-tests)

```
$ composer tests

```

### Run example

[](#run-example)

```
$ cd examples/user-account

# install dependencies, incl. mstovicek/state-machine
$ composer install

# get current state
$ php index.php get

# set state
$ php index.php set

# reset state to default
$ php index.php reset

```

### Example output:

[](#example-output)

```
$ php index.php get
Current state: new

$ php index.php set active
State was set to: active

$ php index.php get
Current state: active

$ php index.php set outdated
State was set to: outdated

$ php index.php get
Current state: outdated

$ php index.php set limited
Cannot set state to limited! Check current state and allowed transitions.

$ php index.php get
Current state: outdated

$ php index.php set removed
State was set to: removed

$ php index.php get
Current state: removed
This state is terminal.

$ php index.php set active
Cannot set state to active! Check current state and allowed transitions.

$ php index.php reset
State was reset to default

$ php index.php get
Current state: new

```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/8ab1d4f12a104c9b82cd9fff70c2bdac4a695017ad37a6b81f63b241b04e9569?d=identicon)[mstovicek](/maintainers/mstovicek)

---

Top Contributors

[![mstovicek](https://avatars.githubusercontent.com/u/4922479?v=4)](https://github.com/mstovicek "mstovicek (9 commits)")

### Embed Badge

![Health badge](/badges/mstovicek-state-machine/health.svg)

```
[![Health](https://phpackages.com/badges/mstovicek-state-machine/health.svg)](https://phpackages.com/packages/mstovicek-state-machine)
```

PHPackages © 2026

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