PHPackages                             alex-patterson-webdev/tennis-game - 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. alex-patterson-webdev/tennis-game

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

alex-patterson-webdev/tennis-game
=================================

Simple Tennis score calculator

1.1.0(6y ago)06PHPPHP &gt;=7.4CI failing

Since Jul 4Pushed 6y ago1 watchersCompare

[ Source](https://github.com/alex-patterson-webdev/tennis-game)[ Packagist](https://packagist.org/packages/alex-patterson-webdev/tennis-game)[ RSS](/packages/alex-patterson-webdev-tennis-game/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (1)Versions (4)Used By (0)

[![Build Status](https://camo.githubusercontent.com/a5e50c8c6089d02b344028fcd1a35575948cfeb0ae5217ac698b63dc361b3889/68747470733a2f2f7472617669732d63692e636f6d2f616c65782d706174746572736f6e2d7765626465762f74656e6e69732d67616d652e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/alex-patterson-webdev/tennis-game)[![codecov](https://camo.githubusercontent.com/d3ce5c22feead4ac769cac2c4c70744659ee26f4daacef4ad35750f3e93e1386/68747470733a2f2f636f6465636f762e696f2f67682f616c65782d706174746572736f6e2d7765626465762f74656e6e69732d67616d652f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/alex-patterson-webdev/tennis-game)

Arp\\TennisGame
===============

[](#arptennisgame)

About
-----

[](#about)

A PHP solution to the Tennis scoring challenge.

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

[](#installation)

Installation via [composer](https://getcomposer.org).

```
require alex-patterson-webdev/tennis-game ^1

```

Usage
-----

[](#usage)

In order to calculate the Tennis score, first create a new instance of the `Arp\TennisGame\TennisGame` class.

```
use Arp\TennisGame\TennisGame;
$tennisGame = new TennisGame();

```

Once created, we can record scores for `PlayerOne` and `PlayerTwo` by calling either `playerOneWinsShot()` or `playerTwoWinsShot()`. Internally the `TennisGame` class will keep a record of each player's score, regardless of the order of the winning shots.

```
$tennisGame->playerOneWinsShot(); // Increase PlayerOne score by 1 point
$tennisGame->playerTwoWinsShot(); // Increase PlayerOne score by 1 point

```

By default, score for both players start at a value of `love` (zero). At any time we can review the score of each of the players by calling the `renderScore()` method. The score for both players will be returned as a string, `x-y`where `x` represents the first players' score and `y` represents the seconds players' score.

```
echo $tennisGame->renderScore(); // output string 'love-love'

$tennisGame->playerOneWinsShot();
echo $tennisGame->renderScore(); // output string 'fifteen-love'

$tennisGame->playerTwoWinsShot();
echo $tennisGame->renderScore(); // output string 'fifteen-fifteen'

```

In accordance with the rules of Tennis, when players tie and have both reached a score of at least `forty`, then the result of the call to `renderScore()` will be `deuce`, indicating the scores are level.

```
$tennisGame->playerOneWinsShot();
$tennisGame->playerOneWinsShot();
$tennisGame->playerOneWinsShot();

$tennisGame->playerTwoWinsShot();
$tennisGame->playerTwoWinsShot();
$tennisGame->playerTwoWinsShot();

echo $tennisGame->renderScore(); // output string 'deuce'

```

If the score is a tie at `deuce`, players must then score 1 additional point to gain an `advantage`. In these cases, calls to method `renderScore()` will display the player who has the current advantage.

```
$tennisGame->playerOneWinsShot(); // 15
$tennisGame->playerOneWinsShot(); // 30
$tennisGame->playerOneWinsShot(); // 40

$tennisGame->playerTwoWinsShot(); // 15
$tennisGame->playerTwoWinsShot(); // 30
$tennisGame->playerTwoWinsShot(); // 40 (Deuce)
$tennisGame->playerTwoWinsShot(); // advantage PlayerOne

echo $tennisGame->renderScore(); // output string 'advantage PlayerTwo';

```

In order to win the game, players must have a score which exceeds `forty` points and have at least two points more than the competing player. Calls to `renderScore()` will show the name of the player who is the winner.

```
$tennisGame->playerOneWinsShot(); // 15

$tennisGame->playerTwoWinsShot(); // 15
$tennisGame->playerTwoWinsShot(); // 30
$tennisGame->playerTwoWinsShot(); // 40
$tennisGame->playerTwoWinsShot(); // win

echo $tennisGame->renderScore(); // output string 'win PlayerTwo';

```

Unit Tests
----------

[](#unit-tests)

Unit test can be run using [PHPUnit](https://phpunit.de/).

```
php vendor/bin/phpunit

```

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

Total

2

Last Release

2191d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1563851?v=4)[Alex Patterson](/maintainers/alex-patterson-webdev)[@alex-patterson-webdev](https://github.com/alex-patterson-webdev)

---

Top Contributors

[![alex-patterson-webdev](https://avatars.githubusercontent.com/u/1563851?v=4)](https://github.com/alex-patterson-webdev "alex-patterson-webdev (26 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/alex-patterson-webdev-tennis-game/health.svg)

```
[![Health](https://phpackages.com/badges/alex-patterson-webdev-tennis-game/health.svg)](https://phpackages.com/packages/alex-patterson-webdev-tennis-game)
```

###  Alternatives

[bramdeleeuw/cookieconsent

GDPR compliant cookie bar and consent checker

1511.7k2](/packages/bramdeleeuw-cookieconsent)[tioncico/curd-automatic-generation

401.7k1](/packages/tioncico-curd-automatic-generation)[voodoophp/paginator

Paginator is a simple class that allows you to create pagination. It doesn't require any database connection. It is compatible with Twitter's Bootstrap Framework, by using the CSS class pagination that is also attached.

351.5k1](/packages/voodoophp-paginator)

PHPackages © 2026

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