{"action":"created","comment":{"url":"https://api.github.com/repos/mathiasverraes/money/pulls/comments/48482897","id":48482897,"diff_hunk":"@@ -0,0 +1,188 @@\n+<?php\n+/**\n+ * This file is part of the Money library\n+ *\n+ * Copyright (c) 2011-2013 Mathias Verraes\n+ *\n+ * For the full copyright and license information, please view the LICENSE\n+ * file that was distributed with this source code.\n+ */\n+\n+namespace Money\\Calculator;\n+\n+use InvalidArgumentException;\n+use Money\\CalculatorInterface;\n+use Money\\Money;\n+use Money\\Number;\n+\n+/**\n+ * Class BcMathCalculator\n+ * @package Money\\Calculator\n+ */\n+final class BcMathCalculator implements CalculatorInterface\n+{\n+\n+    /**\n+     * @var string\n+     */\n+    private $scale;\n+\n+    /**\n+     * BcMathCalculator constructor.\n+     * @param int $scale\n+     */\n+    public function __construct($scale = 14)\n+    {\n+        $this->scale = $scale;\n+    }\n+\n+\n+    /**\n+     * @return bool\n+     */\n+    public function supported()\n+    {\n+        return extension_loaded('bcmath');\n+    }\n+\n+    /**\n+     * @param $a\n+     * @param $b\n+     * @return int\n+     */\n+    public function compare($a, $b)\n+    {\n+        return bccomp($a, $b);\n+    }\n+\n+    /**\n+     * @param $amount\n+     * @param $addend\n+     * @return mixed\n+     */\n+    public function add($amount, $addend)\n+    {\n+        return bcadd($amount, $addend);\n+    }\n+\n+    /**\n+     * @param $amount\n+     * @param $subtrahend\n+     * @return mixed\n+     */\n+    public function subtract($amount, $subtrahend)\n+    {\n+        return bcsub($amount, $subtrahend);\n+    }\n+\n+    /**\n+     * @param $amount\n+     * @param $multiplier\n+     * @return mixed\n+     */\n+    public function multiply($amount, $multiplier)\n+    {\n+        return bcmul($amount, $multiplier, $this->scale);\n+    }\n+\n+    /**\n+     * @param $amount\n+     * @param $divisor\n+     * @return mixed\n+     */\n+    public function divide($amount, $divisor)\n+    {\n+        return bcdiv($amount, $divisor, $this->scale);\n+    }\n+\n+    /**\n+     * @param $number\n+     * @return mixed\n+     */\n+    public function ceil($number)\n+    {\n+        $decimal_separator_position = strpos($number, '.');\n+        if ($decimal_separator_position === false) {\n+            return $number;\n+        }\n+\n+        return bcadd($number, '1', 0);\n+    }\n+\n+    /**\n+     * @param $number\n+     * @return mixed\n+     */\n+    public function floor($number)\n+    {\n+        return bcadd($number, '0', 0);\n+    }\n+\n+    /**\n+     * @param $number\n+     * @param $roundingMode\n+     * @return mixed\n+     */\n+    public function round($number, $roundingMode)\n+    {\n+        $number = new Number($number);\n+        if ($number->isDecimal() === false) {\n+            return (string) $number;\n+        }\n+\n+        if ($number->isHalf() === false) {\n+            return $this->roundDigit($number);\n+        }\n+\n+        if ($roundingMode === Money::ROUND_HALF_DOWN) {\n+            return $this->floor((string) $number);\n+        }\n+\n+        if ($roundingMode === Money::ROUND_HALF_UP) {\n+            return $this->ceil((string) $number);\n+        }\n+\n+        if ($roundingMode === Money::ROUND_HALF_EVEN) {\n+            if ($number->isCurrentEven() === true) {\n+                return $this->floor((string) $number);\n+            } else {\n+                return $this->ceil((string) $number);\n+            }\n+        }\n+\n+        if ($roundingMode === Money::ROUND_HALF_ODD) {\n+            if ($number->isCurrentEven() === true) {\n+                return $this->ceil((string) $number);\n+            } else {\n+                return $this->floor((string) $number);\n+            }\n+        }\n+\n+        throw new InvalidArgumentException('Unknown rounding mode');\n+    }\n+\n+    /**\n+     * @param $number\n+     * @return string\n+     */\n+    private function roundDigit(Number $number)\n+    {\n+        if ($number->isCloserToNext()) {\n+            return $this->ceil($number);\n+        }\n+\n+        return $this->floor($number);\n+    }\n+\n+    /**\n+     * @param $amount\n+     * @param $ratio\n+     * @param $total\n+     * @return mixed\n+     */\n+    public function share($amount, $ratio, $total)\n+    {\n+        return $this->floor(bcdiv(bcmul($amount, $ratio, $this->scale), $total, $this->scale));\n+    }\n+\n+}","path":"src/Calculator/BcMathCalculator.php","position":188,"original_position":188,"commit_id":"8521b60cc14545eab4218d33de6e80da4f21c1f9","original_commit_id":"8521b60cc14545eab4218d33de6e80da4f21c1f9","user":{"login":"sagikazarmark","id":1226384,"avatar_url":"https://avatars.githubusercontent.com/u/1226384?v=3","gravatar_id":"","url":"https://api.github.com/users/sagikazarmark","html_url":"https://github.com/sagikazarmark","followers_url":"https://api.github.com/users/sagikazarmark/followers","following_url":"https://api.github.com/users/sagikazarmark/following{/other_user}","gists_url":"https://api.github.com/users/sagikazarmark/gists{/gist_id}","starred_url":"https://api.github.com/users/sagikazarmark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sagikazarmark/subscriptions","organizations_url":"https://api.github.com/users/sagikazarmark/orgs","repos_url":"https://api.github.com/users/sagikazarmark/repos","events_url":"https://api.github.com/users/sagikazarmark/events{/privacy}","received_events_url":"https://api.github.com/users/sagikazarmark/received_events","type":"User","site_admin":false},"body":"Missing newline","created_at":"2015-12-28T14:47:28Z","updated_at":"2015-12-28T14:47:28Z","html_url":"https://github.com/mathiasverraes/money/pull/115#discussion_r48482897","pull_request_url":"https://api.github.com/repos/mathiasverraes/money/pulls/115","_links":{"self":{"href":"https://api.github.com/repos/mathiasverraes/money/pulls/comments/48482897"},"html":{"href":"https://github.com/mathiasverraes/money/pull/115#discussion_r48482897"},"pull_request":{"href":"https://api.github.com/repos/mathiasverraes/money/pulls/115"}}},"pull_request":{"url":"https://api.github.com/repos/mathiasverraes/money/pulls/115","id":54472142,"html_url":"https://github.com/mathiasverraes/money/pull/115","diff_url":"https://github.com/mathiasverraes/money/pull/115.diff","patch_url":"https://github.com/mathiasverraes/money/pull/115.patch","issue_url":"https://api.github.com/repos/mathiasverraes/money/issues/115","number":115,"state":"open","locked":false,"title":"deal with integer limits","user":{"login":"frederikbosch","id":1552577,"avatar_url":"https://avatars.githubusercontent.com/u/1552577?v=3","gravatar_id":"","url":"https://api.github.com/users/frederikbosch","html_url":"https://github.com/frederikbosch","followers_url":"https://api.github.com/users/frederikbosch/followers","following_url":"https://api.github.com/users/frederikbosch/following{/other_user}","gists_url":"https://api.github.com/users/frederikbosch/gists{/gist_id}","starred_url":"https://api.github.com/users/frederikbosch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frederikbosch/subscriptions","organizations_url":"https://api.github.com/users/frederikbosch/orgs","repos_url":"https://api.github.com/users/frederikbosch/repos","events_url":"https://api.github.com/users/frederikbosch/events{/privacy}","received_events_url":"https://api.github.com/users/frederikbosch/received_events","type":"User","site_admin":false},"body":"Solves #111.\r\n\r\nProbably has quite some impact on the library. Review carefully. Rather see some more comments on the design decisions than on some PSR-2 compliance. The latter will be solved - if there is any compliance oversights - when there is agreement on the design.\r\n\r\nHard aspect of this PR was rounding in GMP and BC Math libraries. Had a look at some other libraries for this to implement.","created_at":"2015-12-23T14:05:42Z","updated_at":"2015-12-28T14:47:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"473b941f36234abfc9e3c9d3dc78615a9d7af7cf","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mathiasverraes/money/pulls/115/commits","review_comments_url":"https://api.github.com/repos/mathiasverraes/money/pulls/115/comments","review_comment_url":"https://api.github.com/repos/mathiasverraes/money/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mathiasverraes/money/issues/115/comments","statuses_url":"https://api.github.com/repos/mathiasverraes/money/statuses/8521b60cc14545eab4218d33de6e80da4f21c1f9","head":{"label":"frederikbosch:nextrelease","ref":"nextrelease","sha":"8521b60cc14545eab4218d33de6e80da4f21c1f9","user":{"login":"frederikbosch","id":1552577,"avatar_url":"https://avatars.githubusercontent.com/u/1552577?v=3","gravatar_id":"","url":"https://api.github.com/users/frederikbosch","html_url":"https://github.com/frederikbosch","followers_url":"https://api.github.com/users/frederikbosch/followers","following_url":"https://api.github.com/users/frederikbosch/following{/other_user}","gists_url":"https://api.github.com/users/frederikbosch/gists{/gist_id}","starred_url":"https://api.github.com/users/frederikbosch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frederikbosch/subscriptions","organizations_url":"https://api.github.com/users/frederikbosch/orgs","repos_url":"https://api.github.com/users/frederikbosch/repos","events_url":"https://api.github.com/users/frederikbosch/events{/privacy}","received_events_url":"https://api.github.com/users/frederikbosch/received_events","type":"User","site_admin":false},"repo":{"id":37968848,"name":"money","full_name":"frederikbosch/money","owner":{"login":"frederikbosch","id":1552577,"avatar_url":"https://avatars.githubusercontent.com/u/1552577?v=3","gravatar_id":"","url":"https://api.github.com/users/frederikbosch","html_url":"https://github.com/frederikbosch","followers_url":"https://api.github.com/users/frederikbosch/followers","following_url":"https://api.github.com/users/frederikbosch/following{/other_user}","gists_url":"https://api.github.com/users/frederikbosch/gists{/gist_id}","starred_url":"https://api.github.com/users/frederikbosch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frederikbosch/subscriptions","organizations_url":"https://api.github.com/users/frederikbosch/orgs","repos_url":"https://api.github.com/users/frederikbosch/repos","events_url":"https://api.github.com/users/frederikbosch/events{/privacy}","received_events_url":"https://api.github.com/users/frederikbosch/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/frederikbosch/money","description":"PHP implementation of Fowler's Money pattern. NOTE: all work is happening in the \"nextrelease\" branch, which will break BC.","fork":true,"url":"https://api.github.com/repos/frederikbosch/money","forks_url":"https://api.github.com/repos/frederikbosch/money/forks","keys_url":"https://api.github.com/repos/frederikbosch/money/keys{/key_id}","collaborators_url":"https://api.github.com/repos/frederikbosch/money/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/frederikbosch/money/teams","hooks_url":"https://api.github.com/repos/frederikbosch/money/hooks","issue_events_url":"https://api.github.com/repos/frederikbosch/money/issues/events{/number}","events_url":"https://api.github.com/repos/frederikbosch/money/events","assignees_url":"https://api.github.com/repos/frederikbosch/money/assignees{/user}","branches_url":"https://api.github.com/repos/frederikbosch/money/branches{/branch}","tags_url":"https://api.github.com/repos/frederikbosch/money/tags","blobs_url":"https://api.github.com/repos/frederikbosch/money/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/frederikbosch/money/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/frederikbosch/money/git/refs{/sha}","trees_url":"https://api.github.com/repos/frederikbosch/money/git/trees{/sha}","statuses_url":"https://api.github.com/repos/frederikbosch/money/statuses/{sha}","languages_url":"https://api.github.com/repos/frederikbosch/money/languages","stargazers_url":"https://api.github.com/repos/frederikbosch/money/stargazers","contributors_url":"https://api.github.com/repos/frederikbosch/money/contributors","subscribers_url":"https://api.github.com/repos/frederikbosch/money/subscribers","subscription_url":"https://api.github.com/repos/frederikbosch/money/subscription","commits_url":"https://api.github.com/repos/frederikbosch/money/commits{/sha}","git_commits_url":"https://api.github.com/repos/frederikbosch/money/git/commits{/sha}","comments_url":"https://api.github.com/repos/frederikbosch/money/comments{/number}","issue_comment_url":"https://api.github.com/repos/frederikbosch/money/issues/comments{/number}","contents_url":"https://api.github.com/repos/frederikbosch/money/contents/{+path}","compare_url":"https://api.github.com/repos/frederikbosch/money/compare/{base}...{head}","merges_url":"https://api.github.com/repos/frederikbosch/money/merges","archive_url":"https://api.github.com/repos/frederikbosch/money/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/frederikbosch/money/downloads","issues_url":"https://api.github.com/repos/frederikbosch/money/issues{/number}","pulls_url":"https://api.github.com/repos/frederikbosch/money/pulls{/number}","milestones_url":"https://api.github.com/repos/frederikbosch/money/milestones{/number}","notifications_url":"https://api.github.com/repos/frederikbosch/money/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/frederikbosch/money/labels{/name}","releases_url":"https://api.github.com/repos/frederikbosch/money/releases{/id}","created_at":"2015-06-24T07:18:20Z","updated_at":"2015-06-24T07:18:20Z","pushed_at":"2015-12-28T14:20:27Z","git_url":"git://github.com/frederikbosch/money.git","ssh_url":"git@github.com:frederikbosch/money.git","clone_url":"https://github.com/frederikbosch/money.git","svn_url":"https://github.com/frederikbosch/money","homepage":"http://blog.verraes.net/2011/04/fowler-money-pattern-in-php/","size":211,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mathiasverraes:nextrelease","ref":"nextrelease","sha":"76a46df375d4c8fde3c1476c491301aab2c3561f","user":{"login":"mathiasverraes","id":489516,"avatar_url":"https://avatars.githubusercontent.com/u/489516?v=3","gravatar_id":"","url":"https://api.github.com/users/mathiasverraes","html_url":"https://github.com/mathiasverraes","followers_url":"https://api.github.com/users/mathiasverraes/followers","following_url":"https://api.github.com/users/mathiasverraes/following{/other_user}","gists_url":"https://api.github.com/users/mathiasverraes/gists{/gist_id}","starred_url":"https://api.github.com/users/mathiasverraes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mathiasverraes/subscriptions","organizations_url":"https://api.github.com/users/mathiasverraes/orgs","repos_url":"https://api.github.com/users/mathiasverraes/repos","events_url":"https://api.github.com/users/mathiasverraes/events{/privacy}","received_events_url":"https://api.github.com/users/mathiasverraes/received_events","type":"User","site_admin":false},"repo":{"id":1543827,"name":"money","full_name":"mathiasverraes/money","owner":{"login":"mathiasverraes","id":489516,"avatar_url":"https://avatars.githubusercontent.com/u/489516?v=3","gravatar_id":"","url":"https://api.github.com/users/mathiasverraes","html_url":"https://github.com/mathiasverraes","followers_url":"https://api.github.com/users/mathiasverraes/followers","following_url":"https://api.github.com/users/mathiasverraes/following{/other_user}","gists_url":"https://api.github.com/users/mathiasverraes/gists{/gist_id}","starred_url":"https://api.github.com/users/mathiasverraes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mathiasverraes/subscriptions","organizations_url":"https://api.github.com/users/mathiasverraes/orgs","repos_url":"https://api.github.com/users/mathiasverraes/repos","events_url":"https://api.github.com/users/mathiasverraes/events{/privacy}","received_events_url":"https://api.github.com/users/mathiasverraes/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mathiasverraes/money","description":"PHP implementation of Fowler's Money pattern. NOTE: all work is happening in the \"nextrelease\" branch, which will break BC.","fork":false,"url":"https://api.github.com/repos/mathiasverraes/money","forks_url":"https://api.github.com/repos/mathiasverraes/money/forks","keys_url":"https://api.github.com/repos/mathiasverraes/money/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mathiasverraes/money/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mathiasverraes/money/teams","hooks_url":"https://api.github.com/repos/mathiasverraes/money/hooks","issue_events_url":"https://api.github.com/repos/mathiasverraes/money/issues/events{/number}","events_url":"https://api.github.com/repos/mathiasverraes/money/events","assignees_url":"https://api.github.com/repos/mathiasverraes/money/assignees{/user}","branches_url":"https://api.github.com/repos/mathiasverraes/money/branches{/branch}","tags_url":"https://api.github.com/repos/mathiasverraes/money/tags","blobs_url":"https://api.github.com/repos/mathiasverraes/money/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mathiasverraes/money/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mathiasverraes/money/git/refs{/sha}","trees_url":"https://api.github.com/repos/mathiasverraes/money/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mathiasverraes/money/statuses/{sha}","languages_url":"https://api.github.com/repos/mathiasverraes/money/languages","stargazers_url":"https://api.github.com/repos/mathiasverraes/money/stargazers","contributors_url":"https://api.github.com/repos/mathiasverraes/money/contributors","subscribers_url":"https://api.github.com/repos/mathiasverraes/money/subscribers","subscription_url":"https://api.github.com/repos/mathiasverraes/money/subscription","commits_url":"https://api.github.com/repos/mathiasverraes/money/commits{/sha}","git_commits_url":"https://api.github.com/repos/mathiasverraes/money/git/commits{/sha}","comments_url":"https://api.github.com/repos/mathiasverraes/money/comments{/number}","issue_comment_url":"https://api.github.com/repos/mathiasverraes/money/issues/comments{/number}","contents_url":"https://api.github.com/repos/mathiasverraes/money/contents/{+path}","compare_url":"https://api.github.com/repos/mathiasverraes/money/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mathiasverraes/money/merges","archive_url":"https://api.github.com/repos/mathiasverraes/money/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mathiasverraes/money/downloads","issues_url":"https://api.github.com/repos/mathiasverraes/money/issues{/number}","pulls_url":"https://api.github.com/repos/mathiasverraes/money/pulls{/number}","milestones_url":"https://api.github.com/repos/mathiasverraes/money/milestones{/number}","notifications_url":"https://api.github.com/repos/mathiasverraes/money/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mathiasverraes/money/labels{/name}","releases_url":"https://api.github.com/repos/mathiasverraes/money/releases{/id}","created_at":"2011-03-29T22:58:09Z","updated_at":"2015-12-27T10:46:31Z","pushed_at":"2015-12-28T14:20:28Z","git_url":"git://github.com/mathiasverraes/money.git","ssh_url":"git@github.com:mathiasverraes/money.git","clone_url":"https://github.com/mathiasverraes/money.git","svn_url":"https://github.com/mathiasverraes/money","homepage":"http://blog.verraes.net/2011/04/fowler-money-pattern-in-php/","size":276,"stargazers_count":618,"watchers_count":618,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":95,"mirror_url":null,"open_issues_count":21,"forks":95,"open_issues":21,"watchers":618,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mathiasverraes/money/pulls/115"},"html":{"href":"https://github.com/mathiasverraes/money/pull/115"},"issue":{"href":"https://api.github.com/repos/mathiasverraes/money/issues/115"},"comments":{"href":"https://api.github.com/repos/mathiasverraes/money/issues/115/comments"},"review_comments":{"href":"https://api.github.com/repos/mathiasverraes/money/pulls/115/comments"},"review_comment":{"href":"https://api.github.com/repos/mathiasverraes/money/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mathiasverraes/money/pulls/115/commits"},"statuses":{"href":"https://api.github.com/repos/mathiasverraes/money/statuses/8521b60cc14545eab4218d33de6e80da4f21c1f9"}}}}