This library allows user to calculate the points/magic points that a team has reached after a soccer match. The total can be altered through some bonus like the defense one.
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.
You can install the library and its dependencies using
$ composer require astronati/fantasy-football-calculator
The library returns a result:
- A MatchResult when a fantasyteam is against another one
- A simple Result when a fantasyteam plays against all others
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.
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.
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);
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();
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();
The environment requires phpunit, that has been already included in the
dev-dependencies of the
To install all modules you just need to run following command:
$ composer install
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
This package is released under the MIT license.