{"action":"created","comment":{"url":"https://api.github.com/repos/BitLucid/ninjawars/pulls/comments/56098266","id":56098266,"diff_hunk":"@@ -0,0 +1,117 @@\n+<?php\n+namespace NinjaWars\\core\\control;\n+use \\model\\News as News;\n+use \\model\\Base;\n+use \\InvalidArgumentException;\n+use Symfony\\Component\\HttpFoundation\\RedirectResponse;\n+use \\Player;\n+use \\NinjaWars\\core\\data\\AccountFactory;\n+\n+/**\n+ * Allows creation of news and displaying of news by admins\n+ */\n+class NewsController {\n+    const ALIVE = false;\n+    const PRIV  = false;\n+\n+    protected $pc = null;\n+\n+    public function __construct(){\n+        $this->pc = Player::find(self_char_id());\n+    }\n+\n+    private function hasCreateRole(Player $pc){\n+        if(!($pc instanceof Player)){\n+            throw new InvalidArgumentException(\"Can't check the role of a nonexistent player.\");\n+        }\n+        return $pc->isAdmin();\n+    }\n+\n+    /**\n+     * Display listing of posts\n+     */\n+    public function index(){\n+        $view = 'news.tpl';\n+        $create_successful = (bool) in('create_successful');\n+        $parts = [\n+            'create_successful'=>$create_successful,\n+            'all_news'=>[],\n+            'error'=>in('error'),\n+            'create_role'=>$this->pc? $this->hasCreateRole($this->pc) : null,\n+        ];\n+\n+        // Fetch all the posts\n+        try {\n+            $news = new News();\n+\n+            if ($tag = in('tag_query')) {\n+                // Search for specific tag\n+                $parts['all_news'] = $news->findByTag($tag);\n+                $parts['search_title'] = 'Result for #'.htmlentities(in('tag_query'));\n+            } else {\n+                $parts['all_news'] = $news->all();\n+            }\n+        } catch (InvalidArgumentException $e) {\n+            $parts['error'] = 'Unable to find any news like that';\n+        }\n+\n+        return [\n+            'title'=>'News Board',\n+            'template'=>$view,\n+            'parts'=>$parts,\n+            'options'=>[],\n+            ];\n+    }\n+\n+    /**\n+     * Create new post\n+     */\n+    public function create(){\n+        if($this->pc === null || !$this->hasCreateRole($this->pc)){\n+            return new RedirectResponse('/news/?error='.url(\"Sorry, you can't create a news post\"));\n+        }\n+        $title = 'Make New Post';\n+        $error = (bool) in('error');\n+        $parts = array(\n+            'error'=>$error,\n+            'heading'=>$title,\n+        );\n+\n+        return [\n+            'title'=>$title,\n+            'template'=>'news-create.tpl',\n+            'parts'=>$parts,\n+            'options'=>[],\n+            ];\n+    }\n+\n+    /**\n+     * Try to store a posted post, and redirect on successes or errors.\n+     * @return RedirectResponse\n+     */\n+    public function store(){\n+        if($this->pc === null || !$this->hasCreateRole($this->pc)){\n+            return RedirectResponse('/news/?error='.url(\"Sorry, you don't have permission to create a news post.\"));\n+        }\n+        $pc = Player::find(self_char_id());","path":"deploy/lib/control/NewsController.php","position":null,"original_position":96,"commit_id":"ba35f3a2cca60468ce5961fea1a92037f82cd324","original_commit_id":"8a22a5c07b838cbd2def13627d52e3d51cf05d9c","user":{"login":"Beagle","id":106455,"avatar_url":"https://avatars.githubusercontent.com/u/106455?v=3","gravatar_id":"","url":"https://api.github.com/users/Beagle","html_url":"https://github.com/Beagle","followers_url":"https://api.github.com/users/Beagle/followers","following_url":"https://api.github.com/users/Beagle/following{/other_user}","gists_url":"https://api.github.com/users/Beagle/gists{/gist_id}","starred_url":"https://api.github.com/users/Beagle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Beagle/subscriptions","organizations_url":"https://api.github.com/users/Beagle/orgs","repos_url":"https://api.github.com/users/Beagle/repos","events_url":"https://api.github.com/users/Beagle/events{/privacy}","received_events_url":"https://api.github.com/users/Beagle/received_events","type":"User","site_admin":false},"body":"The constructor already calls Player::find and stores the result. Why do it again, after running a guard statement that could throw without catching?","created_at":"2016-03-15T00:16:55Z","updated_at":"2016-03-15T00:16:55Z","html_url":"https://github.com/BitLucid/ninjawars/pull/572#discussion_r56098266","pull_request_url":"https://api.github.com/repos/BitLucid/ninjawars/pulls/572","_links":{"self":{"href":"https://api.github.com/repos/BitLucid/ninjawars/pulls/comments/56098266"},"html":{"href":"https://github.com/BitLucid/ninjawars/pull/572#discussion_r56098266"},"pull_request":{"href":"https://api.github.com/repos/BitLucid/ninjawars/pulls/572"}}},"pull_request":{"url":"https://api.github.com/repos/BitLucid/ninjawars/pulls/572","id":62807818,"html_url":"https://github.com/BitLucid/ninjawars/pull/572","diff_url":"https://github.com/BitLucid/ninjawars/pull/572.diff","patch_url":"https://github.com/BitLucid/ninjawars/pull/572.patch","issue_url":"https://api.github.com/repos/BitLucid/ninjawars/issues/572","number":572,"state":"open","locked":false,"title":"News controllerified.","user":{"login":"tchalvak","id":23353,"avatar_url":"https://avatars.githubusercontent.com/u/23353?v=3","gravatar_id":"","url":"https://api.github.com/users/tchalvak","html_url":"https://github.com/tchalvak","followers_url":"https://api.github.com/users/tchalvak/followers","following_url":"https://api.github.com/users/tchalvak/following{/other_user}","gists_url":"https://api.github.com/users/tchalvak/gists{/gist_id}","starred_url":"https://api.github.com/users/tchalvak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tchalvak/subscriptions","organizations_url":"https://api.github.com/users/tchalvak/orgs","repos_url":"https://api.github.com/users/tchalvak/repos","events_url":"https://api.github.com/users/tchalvak/events{/privacy}","received_events_url":"https://api.github.com/users/tchalvak/received_events","type":"User","site_admin":false},"body":"-","created_at":"2016-03-14T19:58:30Z","updated_at":"2016-03-15T00:16:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"973fcc041356a9dbbde1931ef75caf597c4ac6e6","assignee":{"login":"Beagle","id":106455,"avatar_url":"https://avatars.githubusercontent.com/u/106455?v=3","gravatar_id":"","url":"https://api.github.com/users/Beagle","html_url":"https://github.com/Beagle","followers_url":"https://api.github.com/users/Beagle/followers","following_url":"https://api.github.com/users/Beagle/following{/other_user}","gists_url":"https://api.github.com/users/Beagle/gists{/gist_id}","starred_url":"https://api.github.com/users/Beagle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Beagle/subscriptions","organizations_url":"https://api.github.com/users/Beagle/orgs","repos_url":"https://api.github.com/users/Beagle/repos","events_url":"https://api.github.com/users/Beagle/events{/privacy}","received_events_url":"https://api.github.com/users/Beagle/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/BitLucid/ninjawars/pulls/572/commits","review_comments_url":"https://api.github.com/repos/BitLucid/ninjawars/pulls/572/comments","review_comment_url":"https://api.github.com/repos/BitLucid/ninjawars/pulls/comments{/number}","comments_url":"https://api.github.com/repos/BitLucid/ninjawars/issues/572/comments","statuses_url":"https://api.github.com/repos/BitLucid/ninjawars/statuses/ba35f3a2cca60468ce5961fea1a92037f82cd324","head":{"label":"BitLucid:news_controllerify_2","ref":"news_controllerify_2","sha":"ba35f3a2cca60468ce5961fea1a92037f82cd324","user":{"login":"BitLucid","id":1019944,"avatar_url":"https://avatars.githubusercontent.com/u/1019944?v=3","gravatar_id":"","url":"https://api.github.com/users/BitLucid","html_url":"https://github.com/BitLucid","followers_url":"https://api.github.com/users/BitLucid/followers","following_url":"https://api.github.com/users/BitLucid/following{/other_user}","gists_url":"https://api.github.com/users/BitLucid/gists{/gist_id}","starred_url":"https://api.github.com/users/BitLucid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BitLucid/subscriptions","organizations_url":"https://api.github.com/users/BitLucid/orgs","repos_url":"https://api.github.com/users/BitLucid/repos","events_url":"https://api.github.com/users/BitLucid/events{/privacy}","received_events_url":"https://api.github.com/users/BitLucid/received_events","type":"Organization","site_admin":false},"repo":{"id":278312,"name":"ninjawars","full_name":"BitLucid/ninjawars","owner":{"login":"BitLucid","id":1019944,"avatar_url":"https://avatars.githubusercontent.com/u/1019944?v=3","gravatar_id":"","url":"https://api.github.com/users/BitLucid","html_url":"https://github.com/BitLucid","followers_url":"https://api.github.com/users/BitLucid/followers","following_url":"https://api.github.com/users/BitLucid/following{/other_user}","gists_url":"https://api.github.com/users/BitLucid/gists{/gist_id}","starred_url":"https://api.github.com/users/BitLucid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BitLucid/subscriptions","organizations_url":"https://api.github.com/users/BitLucid/orgs","repos_url":"https://api.github.com/users/BitLucid/repos","events_url":"https://api.github.com/users/BitLucid/events{/privacy}","received_events_url":"https://api.github.com/users/BitLucid/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/BitLucid/ninjawars","description":"The code repository where ninjas are prototyped for the ninja game @ ninjawars.net","fork":false,"url":"https://api.github.com/repos/BitLucid/ninjawars","forks_url":"https://api.github.com/repos/BitLucid/ninjawars/forks","keys_url":"https://api.github.com/repos/BitLucid/ninjawars/keys{/key_id}","collaborators_url":"https://api.github.com/repos/BitLucid/ninjawars/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/BitLucid/ninjawars/teams","hooks_url":"https://api.github.com/repos/BitLucid/ninjawars/hooks","issue_events_url":"https://api.github.com/repos/BitLucid/ninjawars/issues/events{/number}","events_url":"https://api.github.com/repos/BitLucid/ninjawars/events","assignees_url":"https://api.github.com/repos/BitLucid/ninjawars/assignees{/user}","branches_url":"https://api.github.com/repos/BitLucid/ninjawars/branches{/branch}","tags_url":"https://api.github.com/repos/BitLucid/ninjawars/tags","blobs_url":"https://api.github.com/repos/BitLucid/ninjawars/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/BitLucid/ninjawars/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/BitLucid/ninjawars/git/refs{/sha}","trees_url":"https://api.github.com/repos/BitLucid/ninjawars/git/trees{/sha}","statuses_url":"https://api.github.com/repos/BitLucid/ninjawars/statuses/{sha}","languages_url":"https://api.github.com/repos/BitLucid/ninjawars/languages","stargazers_url":"https://api.github.com/repos/BitLucid/ninjawars/stargazers","contributors_url":"https://api.github.com/repos/BitLucid/ninjawars/contributors","subscribers_url":"https://api.github.com/repos/BitLucid/ninjawars/subscribers","subscription_url":"https://api.github.com/repos/BitLucid/ninjawars/subscription","commits_url":"https://api.github.com/repos/BitLucid/ninjawars/commits{/sha}","git_commits_url":"https://api.github.com/repos/BitLucid/ninjawars/git/commits{/sha}","comments_url":"https://api.github.com/repos/BitLucid/ninjawars/comments{/number}","issue_comment_url":"https://api.github.com/repos/BitLucid/ninjawars/issues/comments{/number}","contents_url":"https://api.github.com/repos/BitLucid/ninjawars/contents/{+path}","compare_url":"https://api.github.com/repos/BitLucid/ninjawars/compare/{base}...{head}","merges_url":"https://api.github.com/repos/BitLucid/ninjawars/merges","archive_url":"https://api.github.com/repos/BitLucid/ninjawars/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/BitLucid/ninjawars/downloads","issues_url":"https://api.github.com/repos/BitLucid/ninjawars/issues{/number}","pulls_url":"https://api.github.com/repos/BitLucid/ninjawars/pulls{/number}","milestones_url":"https://api.github.com/repos/BitLucid/ninjawars/milestones{/number}","notifications_url":"https://api.github.com/repos/BitLucid/ninjawars/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/BitLucid/ninjawars/labels{/name}","releases_url":"https://api.github.com/repos/BitLucid/ninjawars/releases{/id}","deployments_url":"https://api.github.com/repos/BitLucid/ninjawars/deployments","created_at":"2009-08-14T22:17:27Z","updated_at":"2016-01-01T05:10:52Z","pushed_at":"2016-03-14T23:58:42Z","git_url":"git://github.com/BitLucid/ninjawars.git","ssh_url":"git@github.com:BitLucid/ninjawars.git","clone_url":"https://github.com/BitLucid/ninjawars.git","svn_url":"https://github.com/BitLucid/ninjawars","homepage":"http://ninjawars.net","size":42709,"stargazers_count":7,"watchers_count":7,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":99,"forks":6,"open_issues":99,"watchers":7,"default_branch":"master"}},"base":{"label":"BitLucid:master","ref":"master","sha":"c4e20a1c9d4024742f7d4460c835b4dddc6d5772","user":{"login":"BitLucid","id":1019944,"avatar_url":"https://avatars.githubusercontent.com/u/1019944?v=3","gravatar_id":"","url":"https://api.github.com/users/BitLucid","html_url":"https://github.com/BitLucid","followers_url":"https://api.github.com/users/BitLucid/followers","following_url":"https://api.github.com/users/BitLucid/following{/other_user}","gists_url":"https://api.github.com/users/BitLucid/gists{/gist_id}","starred_url":"https://api.github.com/users/BitLucid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BitLucid/subscriptions","organizations_url":"https://api.github.com/users/BitLucid/orgs","repos_url":"https://api.github.com/users/BitLucid/repos","events_url":"https://api.github.com/users/BitLucid/events{/privacy}","received_events_url":"https://api.github.com/users/BitLucid/received_events","type":"Organization","site_admin":false},"repo":{"id":278312,"name":"ninjawars","full_name":"BitLucid/ninjawars","owner":{"login":"BitLucid","id":1019944,"avatar_url":"https://avatars.githubusercontent.com/u/1019944?v=3","gravatar_id":"","url":"https://api.github.com/users/BitLucid","html_url":"https://github.com/BitLucid","followers_url":"https://api.github.com/users/BitLucid/followers","following_url":"https://api.github.com/users/BitLucid/following{/other_user}","gists_url":"https://api.github.com/users/BitLucid/gists{/gist_id}","starred_url":"https://api.github.com/users/BitLucid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BitLucid/subscriptions","organizations_url":"https://api.github.com/users/BitLucid/orgs","repos_url":"https://api.github.com/users/BitLucid/repos","events_url":"https://api.github.com/users/BitLucid/events{/privacy}","received_events_url":"https://api.github.com/users/BitLucid/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/BitLucid/ninjawars","description":"The code repository where ninjas are prototyped for the ninja game @ ninjawars.net","fork":false,"url":"https://api.github.com/repos/BitLucid/ninjawars","forks_url":"https://api.github.com/repos/BitLucid/ninjawars/forks","keys_url":"https://api.github.com/repos/BitLucid/ninjawars/keys{/key_id}","collaborators_url":"https://api.github.com/repos/BitLucid/ninjawars/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/BitLucid/ninjawars/teams","hooks_url":"https://api.github.com/repos/BitLucid/ninjawars/hooks","issue_events_url":"https://api.github.com/repos/BitLucid/ninjawars/issues/events{/number}","events_url":"https://api.github.com/repos/BitLucid/ninjawars/events","assignees_url":"https://api.github.com/repos/BitLucid/ninjawars/assignees{/user}","branches_url":"https://api.github.com/repos/BitLucid/ninjawars/branches{/branch}","tags_url":"https://api.github.com/repos/BitLucid/ninjawars/tags","blobs_url":"https://api.github.com/repos/BitLucid/ninjawars/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/BitLucid/ninjawars/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/BitLucid/ninjawars/git/refs{/sha}","trees_url":"https://api.github.com/repos/BitLucid/ninjawars/git/trees{/sha}","statuses_url":"https://api.github.com/repos/BitLucid/ninjawars/statuses/{sha}","languages_url":"https://api.github.com/repos/BitLucid/ninjawars/languages","stargazers_url":"https://api.github.com/repos/BitLucid/ninjawars/stargazers","contributors_url":"https://api.github.com/repos/BitLucid/ninjawars/contributors","subscribers_url":"https://api.github.com/repos/BitLucid/ninjawars/subscribers","subscription_url":"https://api.github.com/repos/BitLucid/ninjawars/subscription","commits_url":"https://api.github.com/repos/BitLucid/ninjawars/commits{/sha}","git_commits_url":"https://api.github.com/repos/BitLucid/ninjawars/git/commits{/sha}","comments_url":"https://api.github.com/repos/BitLucid/ninjawars/comments{/number}","issue_comment_url":"https://api.github.com/repos/BitLucid/ninjawars/issues/comments{/number}","contents_url":"https://api.github.com/repos/BitLucid/ninjawars/contents/{+path}","compare_url":"https://api.github.com/repos/BitLucid/ninjawars/compare/{base}...{head}","merges_url":"https://api.github.com/repos/BitLucid/ninjawars/merges","archive_url":"https://api.github.com/repos/BitLucid/ninjawars/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/BitLucid/ninjawars/downloads","issues_url":"https://api.github.com/repos/BitLucid/ninjawars/issues{/number}","pulls_url":"https://api.github.com/repos/BitLucid/ninjawars/pulls{/number}","milestones_url":"https://api.github.com/repos/BitLucid/ninjawars/milestones{/number}","notifications_url":"https://api.github.com/repos/BitLucid/ninjawars/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/BitLucid/ninjawars/labels{/name}","releases_url":"https://api.github.com/repos/BitLucid/ninjawars/releases{/id}","deployments_url":"https://api.github.com/repos/BitLucid/ninjawars/deployments","created_at":"2009-08-14T22:17:27Z","updated_at":"2016-01-01T05:10:52Z","pushed_at":"2016-03-14T23:58:42Z","git_url":"git://github.com/BitLucid/ninjawars.git","ssh_url":"git@github.com:BitLucid/ninjawars.git","clone_url":"https://github.com/BitLucid/ninjawars.git","svn_url":"https://github.com/BitLucid/ninjawars","homepage":"http://ninjawars.net","size":42709,"stargazers_count":7,"watchers_count":7,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":99,"forks":6,"open_issues":99,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/BitLucid/ninjawars/pulls/572"},"html":{"href":"https://github.com/BitLucid/ninjawars/pull/572"},"issue":{"href":"https://api.github.com/repos/BitLucid/ninjawars/issues/572"},"comments":{"href":"https://api.github.com/repos/BitLucid/ninjawars/issues/572/comments"},"review_comments":{"href":"https://api.github.com/repos/BitLucid/ninjawars/pulls/572/comments"},"review_comment":{"href":"https://api.github.com/repos/BitLucid/ninjawars/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/BitLucid/ninjawars/pulls/572/commits"},"statuses":{"href":"https://api.github.com/repos/BitLucid/ninjawars/statuses/ba35f3a2cca60468ce5961fea1a92037f82cd324"}}}}