{"action":"created","comment":{"url":"https://api.github.com/repos/monicahq/monica/pulls/comments/243363602","pull_request_review_id":187114786,"id":243363602,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI0MzM2MzYwMg==","diff_hunk":"@@ -0,0 +1,124 @@\n+<?php\n+\n+namespace App\\Services\\Contact\\Contact;\n+\n+use App\\Services\\BaseService;\n+use App\\Models\\Contact\\Contact;\n+use App\\Models\\Instance\\SpecialDate;\n+\n+class UpdateBirthdayInformation extends BaseService\n+{\n+    private $contact;\n+\n+    /**\n+     * Get the validation rules that apply to the service.\n+     *\n+     * @return array\n+     */\n+    public function rules()\n+    {\n+        return [\n+            'account_id' => 'required|integer|exists:accounts,id',\n+            'contact_id' => 'required|integer',\n+            'is_date_known' => 'required|boolean',\n+            'day' => 'nullable|integer',\n+            'month' => 'nullable|integer',\n+            'year' => 'nullable|integer',\n+            'is_age_based' => 'nullable|boolean',\n+            'age' => 'nullable|integer',\n+            'add_reminder' => 'nullable|boolean',\n+        ];\n+    }\n+\n+    /**\n+     * Update the information about the birthday.\n+     *\n+     * @param array $data\n+     * @return Contact\n+     */\n+    public function execute(array $data)\n+    {\n+        $this->validate($data);\n+\n+        $this->contact = Contact::where('account_id', $data['account_id'])\n+            ->findOrFail($data['contact_id']);\n+\n+        $this->contact->removeSpecialDate('birthdate');\n+\n+        $this->manageBirthday($data);\n+\n+        return $this->contact;\n+    }\n+\n+    /**\n+     * Update birthday information depending on the type of information.\n+     *\n+     * @param array $data\n+     * @return void|null\n+     */\n+    private function manageBirthday(array $data)\n+    {\n+        if ($data['is_date_known'] == false) {\n+            return;\n+        }\n+\n+        if ($data['is_age_based'] == true) {\n+            $this->approximate($data);\n+        }\n+\n+        if ($data['is_age_based'] == false) {\n+            $this->exact($data);\n+        }\n+    }\n+\n+    /**\n+     * Case where the birthday is approximate. That means the birthdate is based\n+     * on the estimated age of the contact.\n+     *\n+     * @param array $data\n+     * @return void\n+     */\n+    private function approximate(array $data)\n+    {\n+        $this->contact->setSpecialDateFromAge('birthdate', $data['age']);\n+    }\n+\n+    /**\n+     * Case where we have a year, month and day for the birthday.\n+     *\n+     * @param  array  $data\n+     * @return void\n+     */\n+    private function exact(array $data)\n+    {\n+        $specialDate = $specialDate = $this->contact->setSpecialDate(\n+            'birthdate',\n+            (is_null($data['year']) ? 0 : $data['year']),\n+            $data['month'],\n+            $data['day']\n+        );\n+\n+        $this->setReminder($data, $specialDate);\n+    }\n+\n+    /**\n+     * Set a reminder for the given special date, if required.\n+     *\n+     * @param array  $data\n+     * @param SpecialDate $specialDate\n+     * @return void\n+     */\n+    private function setReminder(array $data, SpecialDate $specialDate)\n+    {\n+        if ($data['add_reminder'] == true) {","path":"app/Services/Contact/Contact/UpdateBirthdayInformation.php","position":113,"original_position":113,"commit_id":"9b7999bae692aa219a445e21a46149daf49593a7","original_commit_id":"9b7999bae692aa219a445e21a46149daf49593a7","user":{"login":"sonarcloud[bot]","id":39514782,"node_id":"MDM6Qm90Mzk1MTQ3ODI=","avatar_url":"https://avatars2.githubusercontent.com/in/12526?v=4","gravatar_id":"","url":"https://api.github.com/users/sonarcloud%5Bbot%5D","html_url":"https://github.com/apps/sonarcloud","followers_url":"https://api.github.com/users/sonarcloud%5Bbot%5D/followers","following_url":"https://api.github.com/users/sonarcloud%5Bbot%5D/following{/other_user}","gists_url":"https://api.github.com/users/sonarcloud%5Bbot%5D/gists{/gist_id}","starred_url":"https://api.github.com/users/sonarcloud%5Bbot%5D/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sonarcloud%5Bbot%5D/subscriptions","organizations_url":"https://api.github.com/users/sonarcloud%5Bbot%5D/orgs","repos_url":"https://api.github.com/users/sonarcloud%5Bbot%5D/repos","events_url":"https://api.github.com/users/sonarcloud%5Bbot%5D/events{/privacy}","received_events_url":"https://api.github.com/users/sonarcloud%5Bbot%5D/received_events","type":"Bot","site_admin":false},"body":"![Code Smell](https://sonarsource.github.io/sonar-github/code_smell.png 'Code Smell') Code Smell: Remove the literal \"true\" boolean value. ([php:S1125](https://sonarcloud.io/organizations/monicahq/rules#rule_key=php%3AS1125))\n\n[See it in SonarCloud](https://sonarcloud.io/project/issues?id=monica&pullRequest=2168&issues=AWfMwsuUP9uNp_grytgM&open=AWfMwsuUP9uNp_grytgM)\n\n[ISSUE_KEY]: AWfMwsuUP9uNp_grytgM","created_at":"2018-12-20T17:56:23Z","updated_at":"2018-12-20T17:56:24Z","html_url":"https://github.com/monicahq/monica/pull/2168#discussion_r243363602","pull_request_url":"https://api.github.com/repos/monicahq/monica/pulls/2168","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/monicahq/monica/pulls/comments/243363602"},"html":{"href":"https://github.com/monicahq/monica/pull/2168#discussion_r243363602"},"pull_request":{"href":"https://api.github.com/repos/monicahq/monica/pulls/2168"}}},"pull_request":{"url":"https://api.github.com/repos/monicahq/monica/pulls/2168","id":239552545,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM5NTUyNTQ1","html_url":"https://github.com/monicahq/monica/pull/2168","diff_url":"https://github.com/monicahq/monica/pull/2168.diff","patch_url":"https://github.com/monicahq/monica/pull/2168.patch","issue_url":"https://api.github.com/repos/monicahq/monica/issues/2168","number":2168,"state":"open","locked":false,"title":"chore: refactor contact management with services","user":{"login":"djaiss","id":61099,"node_id":"MDQ6VXNlcjYxMDk5","avatar_url":"https://avatars3.githubusercontent.com/u/61099?v=4","gravatar_id":"","url":"https://api.github.com/users/djaiss","html_url":"https://github.com/djaiss","followers_url":"https://api.github.com/users/djaiss/followers","following_url":"https://api.github.com/users/djaiss/following{/other_user}","gists_url":"https://api.github.com/users/djaiss/gists{/gist_id}","starred_url":"https://api.github.com/users/djaiss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/djaiss/subscriptions","organizations_url":"https://api.github.com/users/djaiss/orgs","repos_url":"https://api.github.com/users/djaiss/repos","events_url":"https://api.github.com/users/djaiss/events{/privacy}","received_events_url":"https://api.github.com/users/djaiss/received_events","type":"User","site_admin":false},"body":"This PR refactors how contacts are created/updated/deleted using services.","created_at":"2018-12-18T16:30:29Z","updated_at":"2018-12-20T17:56:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e1ce028eb1f2f044bf7abc685bcbaf03f3b7eadd","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/monicahq/monica/pulls/2168/commits","review_comments_url":"https://api.github.com/repos/monicahq/monica/pulls/2168/comments","review_comment_url":"https://api.github.com/repos/monicahq/monica/pulls/comments{/number}","comments_url":"https://api.github.com/repos/monicahq/monica/issues/2168/comments","statuses_url":"https://api.github.com/repos/monicahq/monica/statuses/9b7999bae692aa219a445e21a46149daf49593a7","head":{"label":"monicahq:2018-12-18-add-contact-services","ref":"2018-12-18-add-contact-services","sha":"9b7999bae692aa219a445e21a46149daf49593a7","user":{"login":"monicahq","id":25832602,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI1ODMyNjAy","avatar_url":"https://avatars3.githubusercontent.com/u/25832602?v=4","gravatar_id":"","url":"https://api.github.com/users/monicahq","html_url":"https://github.com/monicahq","followers_url":"https://api.github.com/users/monicahq/followers","following_url":"https://api.github.com/users/monicahq/following{/other_user}","gists_url":"https://api.github.com/users/monicahq/gists{/gist_id}","starred_url":"https://api.github.com/users/monicahq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monicahq/subscriptions","organizations_url":"https://api.github.com/users/monicahq/orgs","repos_url":"https://api.github.com/users/monicahq/repos","events_url":"https://api.github.com/users/monicahq/events{/privacy}","received_events_url":"https://api.github.com/users/monicahq/received_events","type":"Organization","site_admin":false},"repo":{"id":82238168,"node_id":"MDEwOlJlcG9zaXRvcnk4MjIzODE2OA==","name":"monica","full_name":"monicahq/monica","private":false,"owner":{"login":"monicahq","id":25832602,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI1ODMyNjAy","avatar_url":"https://avatars3.githubusercontent.com/u/25832602?v=4","gravatar_id":"","url":"https://api.github.com/users/monicahq","html_url":"https://github.com/monicahq","followers_url":"https://api.github.com/users/monicahq/followers","following_url":"https://api.github.com/users/monicahq/following{/other_user}","gists_url":"https://api.github.com/users/monicahq/gists{/gist_id}","starred_url":"https://api.github.com/users/monicahq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monicahq/subscriptions","organizations_url":"https://api.github.com/users/monicahq/orgs","repos_url":"https://api.github.com/users/monicahq/repos","events_url":"https://api.github.com/users/monicahq/events{/privacy}","received_events_url":"https://api.github.com/users/monicahq/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/monicahq/monica","description":"Personal CRM. Remember everything about your friends and family.","fork":false,"url":"https://api.github.com/repos/monicahq/monica","forks_url":"https://api.github.com/repos/monicahq/monica/forks","keys_url":"https://api.github.com/repos/monicahq/monica/keys{/key_id}","collaborators_url":"https://api.github.com/repos/monicahq/monica/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/monicahq/monica/teams","hooks_url":"https://api.github.com/repos/monicahq/monica/hooks","issue_events_url":"https://api.github.com/repos/monicahq/monica/issues/events{/number}","events_url":"https://api.github.com/repos/monicahq/monica/events","assignees_url":"https://api.github.com/repos/monicahq/monica/assignees{/user}","branches_url":"https://api.github.com/repos/monicahq/monica/branches{/branch}","tags_url":"https://api.github.com/repos/monicahq/monica/tags","blobs_url":"https://api.github.com/repos/monicahq/monica/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/monicahq/monica/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/monicahq/monica/git/refs{/sha}","trees_url":"https://api.github.com/repos/monicahq/monica/git/trees{/sha}","statuses_url":"https://api.github.com/repos/monicahq/monica/statuses/{sha}","languages_url":"https://api.github.com/repos/monicahq/monica/languages","stargazers_url":"https://api.github.com/repos/monicahq/monica/stargazers","contributors_url":"https://api.github.com/repos/monicahq/monica/contributors","subscribers_url":"https://api.github.com/repos/monicahq/monica/subscribers","subscription_url":"https://api.github.com/repos/monicahq/monica/subscription","commits_url":"https://api.github.com/repos/monicahq/monica/commits{/sha}","git_commits_url":"https://api.github.com/repos/monicahq/monica/git/commits{/sha}","comments_url":"https://api.github.com/repos/monicahq/monica/comments{/number}","issue_comment_url":"https://api.github.com/repos/monicahq/monica/issues/comments{/number}","contents_url":"https://api.github.com/repos/monicahq/monica/contents/{+path}","compare_url":"https://api.github.com/repos/monicahq/monica/compare/{base}...{head}","merges_url":"https://api.github.com/repos/monicahq/monica/merges","archive_url":"https://api.github.com/repos/monicahq/monica/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/monicahq/monica/downloads","issues_url":"https://api.github.com/repos/monicahq/monica/issues{/number}","pulls_url":"https://api.github.com/repos/monicahq/monica/pulls{/number}","milestones_url":"https://api.github.com/repos/monicahq/monica/milestones{/number}","notifications_url":"https://api.github.com/repos/monicahq/monica/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/monicahq/monica/labels{/name}","releases_url":"https://api.github.com/repos/monicahq/monica/releases{/id}","deployments_url":"https://api.github.com/repos/monicahq/monica/deployments","created_at":"2017-02-17T00:02:58Z","updated_at":"2018-12-20T15:58:57Z","pushed_at":"2018-12-20T17:48:17Z","git_url":"git://github.com/monicahq/monica.git","ssh_url":"git@github.com:monicahq/monica.git","clone_url":"https://github.com/monicahq/monica.git","svn_url":"https://github.com/monicahq/monica","homepage":"https://monicahq.com","size":62351,"stargazers_count":6280,"watchers_count":6280,"language":"PHP","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":708,"mirror_url":null,"archived":false,"open_issues_count":363,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0","node_id":"MDc6TGljZW5zZTE="},"forks":708,"open_issues":363,"watchers":6280,"default_branch":"master"}},"base":{"label":"monicahq:master","ref":"master","sha":"7a95057bb8dfeb23857ddb151aa944640fdb6cbd","user":{"login":"monicahq","id":25832602,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI1ODMyNjAy","avatar_url":"https://avatars3.githubusercontent.com/u/25832602?v=4","gravatar_id":"","url":"https://api.github.com/users/monicahq","html_url":"https://github.com/monicahq","followers_url":"https://api.github.com/users/monicahq/followers","following_url":"https://api.github.com/users/monicahq/following{/other_user}","gists_url":"https://api.github.com/users/monicahq/gists{/gist_id}","starred_url":"https://api.github.com/users/monicahq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monicahq/subscriptions","organizations_url":"https://api.github.com/users/monicahq/orgs","repos_url":"https://api.github.com/users/monicahq/repos","events_url":"https://api.github.com/users/monicahq/events{/privacy}","received_events_url":"https://api.github.com/users/monicahq/received_events","type":"Organization","site_admin":false},"repo":{"id":82238168,"node_id":"MDEwOlJlcG9zaXRvcnk4MjIzODE2OA==","name":"monica","full_name":"monicahq/monica","private":false,"owner":{"login":"monicahq","id":25832602,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI1ODMyNjAy","avatar_url":"https://avatars3.githubusercontent.com/u/25832602?v=4","gravatar_id":"","url":"https://api.github.com/users/monicahq","html_url":"https://github.com/monicahq","followers_url":"https://api.github.com/users/monicahq/followers","following_url":"https://api.github.com/users/monicahq/following{/other_user}","gists_url":"https://api.github.com/users/monicahq/gists{/gist_id}","starred_url":"https://api.github.com/users/monicahq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monicahq/subscriptions","organizations_url":"https://api.github.com/users/monicahq/orgs","repos_url":"https://api.github.com/users/monicahq/repos","events_url":"https://api.github.com/users/monicahq/events{/privacy}","received_events_url":"https://api.github.com/users/monicahq/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/monicahq/monica","description":"Personal CRM. Remember everything about your friends and family.","fork":false,"url":"https://api.github.com/repos/monicahq/monica","forks_url":"https://api.github.com/repos/monicahq/monica/forks","keys_url":"https://api.github.com/repos/monicahq/monica/keys{/key_id}","collaborators_url":"https://api.github.com/repos/monicahq/monica/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/monicahq/monica/teams","hooks_url":"https://api.github.com/repos/monicahq/monica/hooks","issue_events_url":"https://api.github.com/repos/monicahq/monica/issues/events{/number}","events_url":"https://api.github.com/repos/monicahq/monica/events","assignees_url":"https://api.github.com/repos/monicahq/monica/assignees{/user}","branches_url":"https://api.github.com/repos/monicahq/monica/branches{/branch}","tags_url":"https://api.github.com/repos/monicahq/monica/tags","blobs_url":"https://api.github.com/repos/monicahq/monica/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/monicahq/monica/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/monicahq/monica/git/refs{/sha}","trees_url":"https://api.github.com/repos/monicahq/monica/git/trees{/sha}","statuses_url":"https://api.github.com/repos/monicahq/monica/statuses/{sha}","languages_url":"https://api.github.com/repos/monicahq/monica/languages","stargazers_url":"https://api.github.com/repos/monicahq/monica/stargazers","contributors_url":"https://api.github.com/repos/monicahq/monica/contributors","subscribers_url":"https://api.github.com/repos/monicahq/monica/subscribers","subscription_url":"https://api.github.com/repos/monicahq/monica/subscription","commits_url":"https://api.github.com/repos/monicahq/monica/commits{/sha}","git_commits_url":"https://api.github.com/repos/monicahq/monica/git/commits{/sha}","comments_url":"https://api.github.com/repos/monicahq/monica/comments{/number}","issue_comment_url":"https://api.github.com/repos/monicahq/monica/issues/comments{/number}","contents_url":"https://api.github.com/repos/monicahq/monica/contents/{+path}","compare_url":"https://api.github.com/repos/monicahq/monica/compare/{base}...{head}","merges_url":"https://api.github.com/repos/monicahq/monica/merges","archive_url":"https://api.github.com/repos/monicahq/monica/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/monicahq/monica/downloads","issues_url":"https://api.github.com/repos/monicahq/monica/issues{/number}","pulls_url":"https://api.github.com/repos/monicahq/monica/pulls{/number}","milestones_url":"https://api.github.com/repos/monicahq/monica/milestones{/number}","notifications_url":"https://api.github.com/repos/monicahq/monica/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/monicahq/monica/labels{/name}","releases_url":"https://api.github.com/repos/monicahq/monica/releases{/id}","deployments_url":"https://api.github.com/repos/monicahq/monica/deployments","created_at":"2017-02-17T00:02:58Z","updated_at":"2018-12-20T15:58:57Z","pushed_at":"2018-12-20T17:48:17Z","git_url":"git://github.com/monicahq/monica.git","ssh_url":"git@github.com:monicahq/monica.git","clone_url":"https://github.com/monicahq/monica.git","svn_url":"https://github.com/monicahq/monica","homepage":"https://monicahq.com","size":62351,"stargazers_count":6280,"watchers_count":6280,"language":"PHP","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":708,"mirror_url":null,"archived":false,"open_issues_count":363,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0","node_id":"MDc6TGljZW5zZTE="},"forks":708,"open_issues":363,"watchers":6280,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/monicahq/monica/pulls/2168"},"html":{"href":"https://github.com/monicahq/monica/pull/2168"},"issue":{"href":"https://api.github.com/repos/monicahq/monica/issues/2168"},"comments":{"href":"https://api.github.com/repos/monicahq/monica/issues/2168/comments"},"review_comments":{"href":"https://api.github.com/repos/monicahq/monica/pulls/2168/comments"},"review_comment":{"href":"https://api.github.com/repos/monicahq/monica/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/monicahq/monica/pulls/2168/commits"},"statuses":{"href":"https://api.github.com/repos/monicahq/monica/statuses/9b7999bae692aa219a445e21a46149daf49593a7"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"sonarcloud"}}