Skip to content

Instantly share code, notes, and snippets.

@dersonsena
Last active January 15, 2020 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dersonsena/fdabc11f10e081927564c16d06903bf7 to your computer and use it in GitHub Desktop.
Save dersonsena/fdabc11f10e081927564c16d06903bf7 to your computer and use it in GitHub Desktop.
<?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