Skip to content

Commit

Permalink
little cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
krowinski committed Jul 30, 2017
1 parent 390ece1 commit 786e1fc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 40 deletions.
2 changes: 1 addition & 1 deletion composer.json
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"ext-bcmath": "*"
},
"require-dev": {
"phpunit/phpunit": "*"
"phpunit/phpunit": "~5.7"
},
"license": "MIT",
"authors": [
Expand Down
58 changes: 20 additions & 38 deletions src/BCMathExtended/BC.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class BC
{
/**
* @param null|int $scale
* @param int $scale
*/
public static function setScale($scale)
{
Expand All @@ -24,11 +24,9 @@ public static function ceil($number)
{
$number = (string)$number;

if (true === self::checkIsFloat($number) and true === self::checkIsFloatCleanZeros($number))
{
if (self::checkIsFloat($number) && self::checkIsFloatCleanZeros($number)) {
$result = 1;
if (true === self::isNegative($number))
{
if (self::isNegative($number)) {
--$result;
}
$number = bcadd($number, $result, 0);
Expand Down Expand Up @@ -71,8 +69,7 @@ private static function isNegative($number)
private static function checkNumber($number)
{
$number = str_replace('+', '', filter_var($number, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION));
if ('-0' === $number || !is_numeric($number))
{
if ('-0' === $number || !is_numeric($number)) {
return '0';
}
return $number;
Expand All @@ -87,10 +84,8 @@ public static function round($number, $precision = 0)
{
$number = (string)$number;

if (true === self::checkIsFloat($number))
{
if (true === self::isNegative($number))
{
if (self::checkIsFloat($number)) {
if (self::isNegative($number)) {
return bcsub($number, '0.' . str_repeat('0', $precision) . '5', $precision);
}

Expand All @@ -108,11 +103,9 @@ public static function floor($number)
{
$number = (string)$number;

if (true === self::checkIsFloat($number) and true === self::checkIsFloatCleanZeros($number))
{
if (self::checkIsFloat($number) && self::checkIsFloatCleanZeros($number)) {
$result = 0;
if (true === self::isNegative($number))
{
if (self::isNegative($number)) {
--$result;
}
$number = bcadd($number, $result, 0);
Expand All @@ -129,9 +122,8 @@ public static function abs($number)
{
$number = (string)$number;

if (true === self::isNegative($number))
{
$number = substr($number, 1);
if (self::isNegative($number)) {
$number = (string)substr($number, 1);
}

return self::checkNumber($number);
Expand All @@ -148,9 +140,9 @@ public static function rand($min, $max)
$min = (string)$min;

$difference = bcadd(bcsub($max, $min), 1);
$rand_percent = bcdiv(mt_rand(), mt_getrandmax(), 8);
$randPercent = bcdiv(mt_rand(), mt_getrandmax(), 8);

return bcadd($min, bcmul($difference, $rand_percent, 8), 0);
return bcadd($min, bcmul($difference, $randPercent, 8), 0);
}

/**
Expand All @@ -160,16 +152,11 @@ public static function rand($min, $max)
public static function max()
{
$max = null;
foreach (func_get_args() as $value)
{
if (null === $max)
{
foreach (func_get_args() as $value) {
if (null === $max) {
$max = $value;
}
else
{
if (bccomp($max, $value) < 0)
{
} else {
if (bccomp($max, $value) < 0) {
$max = $value;
}
}
Expand All @@ -185,16 +172,11 @@ public static function max()
public static function min()
{
$min = null;
foreach (func_get_args() as $value)
{
if (null === $min)
{
foreach (func_get_args() as $value) {
if (null === $min) {
$min = $value;
}
else
{
if (bccomp($min, $value) > 0)
{
} else {
if (bccomp($min, $value) > 0) {
$min = $value;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/BCTest.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Class BcTest
*/
class BcTest extends \PHPUnit_Framework_TestCase
class BCTest extends \PHPUnit_Framework_TestCase
{
/**
* @test
Expand Down

0 comments on commit 786e1fc

Please sign in to comment.