Skip to content

Instantly share code, notes, and snippets.

@wilcorrea
Forked from dersonsena/xpto.php
Last active January 16, 2020 11:46
Show Gist options
  • Save wilcorrea/df64c4affa6d45d460c1a2a655e45f08 to your computer and use it in GitHub Desktop.
Save wilcorrea/df64c4affa6d45d460c1a2a655e45f08 to your computer and use it in GitHub Desktop.
<?php
class Xpto
{
public function addPoints($amount)
{
return $this->processPoints($amount, function ($amount, $currentPointsAvailable, $conversionRate) {
return $currentPointsAvailable + ($amount * $conversionRate)
});
}
public function removePoints($amount)
{
return $this->processPoints($amount, function ($amount, $currentPointsAvailable, $conversionRate) {
return $currentPointsAvailable - ($amount * $conversionRate)
});
}
private function processPoints($amount, $action)
{
$currentPointsAvailable = (float)$this->get('points_available');
$conversionRate = (float)$this->get('points_per_base_ccy_unit');
if (!is_callable($action)) {
throw new InvalidArgument('Action must be a callable');
}
$newPoints = $action($amount, $currentPointsAvailable, $conversionRate);
// SAVE THE PORRA TODA!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment