Last active
January 15, 2020 22:35
-
-
Save dersonsena/fdabc11f10e081927564c16d06903bf7 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->addOrRemovePoints($amount, 'add'); | |
} | |
public function removePoints($amount) | |
{ | |
return $this->addOrRemovePoints($amount, 'remove'); | |
} | |
private function addOrRemovePoints($amount, $action) | |
{ | |
$currentPointsAvailable = (float)$this->get('points_available'); | |
$conversionRate = (float)$this->get('points_per_base_ccy_unit'); | |
switch ($action) { | |
case 'add': | |
$newPoints = $currentPointsAvailable + ($amount * $conversionRate); | |
break; | |
case 'remove': | |
$newPoints = $currentPointsAvailable - ($amount * $conversionRate); | |
break; | |
default: | |
throw new Exception('Invalid call to this method.'); | |
} | |
// SAVE THE PORRA TODA! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment