PHPackages                             ghorwood/phelo - 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. ghorwood/phelo

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

ghorwood/phelo
==============

An elo ranking system library for php.

1.0.0(7y ago)241MITPHP &gt;=7.1

Since Feb 16Compare

[ Source](https://github.com/gbhorwood/phelo)[ Packagist](https://packagist.org/packages/ghorwood/phelo)[ Docs](https://github.com/gbhorwood/phelo)[ RSS](/packages/ghorwood-phelo/feed)WikiDiscussions Synced yesterday

READMEChangelogDependencies (3)Versions (6)Used By (0)

Phelo
=====

[](#phelo)

[![License](https://camo.githubusercontent.com/023ccc6dbcecd439d0182cd6353e5da50332591d0bd5a7b7b627581108aec088/687474703a2f2f706f7365722e707567782e6f72672f67686f72776f6f642f7068656c6f2f6c6963656e7365)](https://packagist.org/packages/ghorwood/phelo)[![PHP Version Require](https://camo.githubusercontent.com/d5f92540cb05d635a57a79e18a5428a2773159ce8e7679033ea4caa096a8edec/687474703a2f2f706f7365722e707567782e6f72672f67686f72776f6f642f7068656c6f2f726571756972652f706870)](https://packagist.org/packages/ghorwood/phelo)[![Dependents](https://camo.githubusercontent.com/2b3ab9a5591bd20ddc5039c6d56778a479c45bd0fed6de1f3ba5a5b9c37df71a/687474703a2f2f706f7365722e707567782e6f72672f67686f72776f6f642f7068656c6f2f646570656e64656e7473)](https://packagist.org/packages/ghorwood/phelo)[![Latest Stable Version](https://camo.githubusercontent.com/6401a4d29a2b752a349b2adc2b9ea21fb612cd7c51be6294189cccc231177fd9/687474703a2f2f706f7365722e707567782e6f72672f67686f72776f6f642f7068656c6f2f76)](https://packagist.org/packages/ghorwood/phelo)

Phelo is a simple library for managing the [elo rating system](https://en.wikipedia.org/wiki/Elo_rating_system).

The elo system is a rating method used in chess and other comptetitive games to calculate an estimate of the strength of the player, based on his or her performance versus other players.

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

[](#installation)

The preferred installation method is via composer

```
composer require ghorwood/phelo
```

Usage
-----

[](#usage)

Phelo works by creating an object to which you can add an arbitrary number of players and their associated initial elo scores. You can then:

- Calculate the percentage chance of a given player defeating another player
- Match two players against each other, setting a winner, and harvest the resulting elos

### Instantiation

[](#instantiation)

Presuming you have used an autoloader, you can use and instantiate phelo as such:

```
use ghorwood\Phelo\Phelo;

$phelo = new Phelo();
```

### Adding players

[](#adding-players)

Players can be set directly into the Phelo object as such

```
$phelo = new Phelo();

// Create player 'jasminder' with elo of 1000
$phelo->jasminder = 1000;

// You can also use variables. This is the method you should use for multi-word names.
$player1 = 'jasminder';
$phelo->$player1 = 1000;

$player2 = 'Barry Clarke';
$phelo->$player2 = 1000;

$player3 = "白百柏";
$phelo->$player3 = 1000;
```

### Getting a players elo

[](#getting-a-players-elo)

An individual player's elo can be retreived by referencing their name

```
$phelo = new Phelo();

$phelo->jasminder = 1000;

print $phelo->jasminder; // 1000
```

All players can be retreived using getAll() which returns an array keyed by the player name.

```
$phelo = new Phelo();

$phelo->jasminder = 1000;
$phelo->ahmed = 1200;

$all = $phelo->getAll();

print_r($all); // ['jasminder' => 1000, 'ahmed' => 1200]
```

### Calculating chance of win

[](#calculating-chance-of-win)

If two players with different elo ratings are matched against each other, it is assumed the player with the higher elo score has a greater probability of winning. Phelo can calculate the percent chance of a given player defeating another player with the chance() method.

The chance() method takes two player names as arguments. The first argument is the player for whom the chance of winning will be calculated

```
$phelo = new Phelo();

$phelo->Jerry = 1000;
$phelo->Sigrid = 910;

// Calculate the percent chance of Jerry winning by passing as first argument
$chanceJerryWins = $phelo->chance("Jerry", "Sigrid");
// Repeat, but for Sigrid
$chanceSigridWins = $phelo->chance("Sigrid", "Jerry");

// Chance of winning is a percent to two decimal places.
print $chanceJerryWins; // 62.67
print $chanceSigridWins; // 37.33

// Percentage chances add up to 100.00
print $chanceSigridWins + $chanceJerryWins; // 100.00
```

### Running matches to calculate elo changes

[](#running-matches-to-calculate-elo-changes)

Elo scores change for players after they win or lose matches. Phelo provides the method match() to simulate a contest between two players. The leftmost of the two players is the winner. After a call to match() the new elo scores for the contestants is updated in the object and can be retreived.

```
$phelo = new \ghorwood\Phelo\Phelo();

$phelo->Tyrone = 1200;
$phelo->Katarina = 800;

// Katarina defeats Tyrone
$phelo->match('Katarina', 'Tyrone');

// Get the updated elo scores
print $phelo->Katarina; // 827
print $phelo->Tyrone; // 1173
```

Calls to match() can be chained to simulate several consecutive contests.

```
$phelo = new \ghorwood\Phelo\Phelo();

$phelo->Tyrone = 1200;
$phelo->Katarina = 800;

// Katarina defeats Tyrone in four consecutive matches
$phelo->match("Katarina", "Tyrone")
    ->match("Katarina", "Tyrone")
    ->match("Katarina", "Tyrone")
    ->match("Katarina", "Tyrone");

// Get the updated elo scores
print $phelo->Katarina; // 902
print $phelo->Tyrone; // 1099
```

### Errors

[](#errors)

Phelo will throw an Exception in the following cases:

- Attempt to get a player that does not exist
- Attempt a match() or chance() on a player that does not exist
- Attempt to create a player with an elo less than 1

The use of try/catch blocks for Exception is encouraged.

### K factor

[](#k-factor)

The K factor affects the sensitivity of changes: a higher K factor increases the changes in elo scores created by matches.

Choosig a K factor that is right for your requirements can be difficult. A good starting place to read on K factor is the ['Most accurate K-factor'](https://en.wikipedia.org/wiki/Elo_rating_system#Most_accurate_K-factor) sectionof the [wikipedia entry on elo](https://en.wikipedia.org/wiki/Elo_rating_system).

Phelo's default K factor is 30. You can change this to your custom value at instation by passing a new value to the contructor:

```
// K factor FIDE uses for players under 18.
$phelo = new \ghorwood\Phelo\Phelo(40);
```

Gradation of K factor for different elo ratings is not supported in Phelo as this time.

Getting support or contributing
-------------------------------

[](#getting-support-or-contributing)

Any prs should conform to PSR-2 formatting, pass phpstan static analysis at level 7 and be accompanied by tests.

The precommit.sh script is provided to do the formatting, analysis and tests.

Support requests, questions or bug reports should also be accompanied by a twitter dm to @gbhorwood, because i'm terrible at email.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity59

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

Total

3

Last Release

2689d ago

Major Versions

0.0.2 → 1.0.02019-02-17

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4615659?v=4)[grant horwood](/maintainers/gbhorwood)[@gbhorwood](https://github.com/gbhorwood)

---

Top Contributors

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

---

Tags

gamesRatingrankingelochess

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ghorwood-phelo/health.svg)

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

###  Alternatives

[rubix/ml

A high-level machine learning and deep learning library for the PHP language.

2.2k1.5M28](/packages/rubix-ml)[kartik-v/bootstrap-star-rating

A simple yet powerful JQuery star rating plugin for Bootstrap.

1.1k4.6M5](/packages/kartik-v-bootstrap-star-rating)[willvincent/laravel-rateable

Allows multiple models to be rated with a fivestar like system.

415463.7k3](/packages/willvincent-laravel-rateable)[codebyray/laravel-review-rateable

Review &amp; Rating system for Laravel 10, 11 &amp; 12

309355.2k](/packages/codebyray-laravel-review-rateable)[kartik-v/yii2-widget-rating

A Yii2 widget for the simple yet powerful bootstrap-star-rating plugin with fractional rating support (sub repo split from yii2-widgets)

444.3M8](/packages/kartik-v-yii2-widget-rating)[phpskills/phpskills

Implementation of Microsoft's TrueSkill matchmaking system for PHP

773.8k](/packages/phpskills-phpskills)

PHPackages © 2026

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