Skip to content

Commit

Permalink
Drop the internal intdiv polyfill
Browse files Browse the repository at this point in the history
The library doesn't actually use the method that requires the
`intdiv()` function so it can be an optional dependency for users.
  • Loading branch information
cs278 committed Feb 8, 2016
1 parent 2cffb9e commit 25ea07c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 110 deletions.
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@
},
"require-dev": {
"cs278/coding-standard": "^1",
"michaelc/intdiv-compat": "^1.0.1",
"phpunit/phpunit": "^4.8.21"
},
"suggest": {
"michaelc/intdiv-compat": "Provides intdiv() which is needed if you use the modulus algorithms yourself.",
"symfony/polyfill-php70": "Provides intdiv() which is needed if you use the modulus algorithms yourself."
},
"autoload": {
"psr-4": {
"Cs278\\BankModulus\\": "src/"
Expand Down
24 changes: 13 additions & 11 deletions src/ModulusAlgorithm/BaseAlgorithm.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,21 @@ public function __construct($result, $divisor)
/** @return int */
final public function quotient()
{
if (null === self::$ourIntdiv) {
self::$ourIntdiv = !function_exists('intdiv');

if (self::$ourIntdiv && !function_exists('Cs278\BankModulus\intdiv')) {
require __DIR__.'/../intdiv.php';
}
if (!function_exists('intdiv')) {
// This method isn't actually used internally by the library
// currently so no hard dependency on these polyfills.

// @codeCoverageIgnoreStart
throw new \LogicException(sprintf(
'%s() requires the intdiv() function which was added in PHP 7'
.' you could use a polyfill such as michaelc/intdiv-compat or'
.' symfony/polyfill-php70 to provide this function',
__METHOD__
));
// @codeCoverageIgnoreEnd
}

if (self::$ourIntdiv) {
return \Cs278\BankModulus\intdiv($this->result, $this->divisor);
} else {
return intdiv($this->result, $this->divisor);
}
return intdiv($this->result, $this->divisor);
}

/** @return int */
Expand Down
44 changes: 0 additions & 44 deletions src/intdiv.php

This file was deleted.

55 changes: 0 additions & 55 deletions tests/IntdivTest.php

This file was deleted.

0 comments on commit 25ea07c

Please sign in to comment.