-
-
Save wilcorrea/df64c4affa6d45d460c1a2a655e45f08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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