Skip to content

Allows user to calculate the points that a fantasy team has reached after a soccer match. The total can be altered through some bonus like the defense one.

License

Notifications You must be signed in to change notification settings

astronati/php-fantasy-football-calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Codacy Badge Codacy Badge Dependency Status Latest Stable Version MIT licensed

Fantasy Football Calculator

This library allows user to calculate the points that a team has reached after a soccer match. The total can be altered through some bonus like the defense one.

Installation

You can install the library and its dependencies using composer running:

$ composer require astronati/fantasy-football-calculator

Usage

The library returns a result:

  • A MatchResult when a fantasyteam is against another one
  • A simple Result when a fantasyteam plays against all others

Rules

Calculator can be configured with different rules in order to apply different bonus/malus to the final result. Rules can be applied to a single team or in a match context: take a look at following folders to see which bonus are supported:

Each rule can be added to the Calculator configuration as shown in the example as follows.

NOTE: To request another rule please file a new issue.

Formation and Footballers

Calculator needs one or two formations: so developer has to provide Formation instances.

// Prepare formation
$formation = new Formation();
$formation->addFirstString(new Footballer())...

NOTE Footballer abstract class needs to be extended by developer that has to set the code property. The code property is the one provided by the Quotation(s) instances.

Take a look at the Footballer class that has been implemented in the example folder.

Example

A couple of examples are provided in order to figure out better how this library can be integrated in the own system.

// Configure calculator
$configuration = new Configuration();
$configuration
  ->addRule(RuleFactory::create(RuleFactory::BEST_DEFENDERS_RULE))
  ->addRule(RuleFactory::create(RuleFactory::HOME_RULE))
;
$calculator = new Calculator($quotations, $configuration);
Match Result

The following snippet is extracted from the example/sample.php file and shows how configuring a calculator in a match.

// Show match results...
$matchResult = $calculator->getMatchResult($formationA, $formationB);
$homeResult = $matchResult->getHomeResult();
echo '(' . $homeResult->getMagicPoints() . ' ' . $homeResult->getBonus() . ') '. $matchResult->getHomeGoals();
Result

The following snippet is extracted from the example/sample.php file and shows how configuring a calculator when a fantasyteam plays alone or against all others.

// Show single result...
$singleResult = $calculator->getSingleResult($formation);
echo $singleResult->getMagicPoints() . ' ' . $singleResult->getBonus();

Development

The environment requires phpunit, that has been already included in the dev-dependencies of the composer.json.

Dependencies

To install all modules you just need to run following command:

$ composer install

Testing

Tests files are created in dedicates folders that replicate the src structure as follows:

.
+-- src
|   +-- [folder-name]
|   |   +-- [file-name].php
|   ...
+-- tests
|   +-- [folder-name]
|   |   +-- [file-name]Test.php

Execute following command to run the tests suite:

$ composer test

Run what follows to see the code coverage:

$ composer coverage

License

This package is released under the MIT license.

About

Allows user to calculate the points that a fantasy team has reached after a soccer match. The total can be altered through some bonus like the defense one.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages