Passed
Push — master ( df89c7...32bb00 )
by Francis
01:21
created
models/BlogManager.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 
12 12
   function __construct() {
13 13
     parent::__construct();
14
-    $this->ci =& get_instance();
14
+    $this->ci = & get_instance();
15 15
     $this->ci->load->database();
16 16
   }
17 17
   /**
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
    *                         database. Returns 0 if the post couldn't be
45 45
    *                         created.
46 46
    */
47
-  function createPost(string $title, string $content, int $adminId=null): int {
47
+  function createPost(string $title, string $content, int $adminId = null): int {
48 48
     $this->ci->load->helper("url");
49 49
     $data = array(
50 50
       "title"   => $title,
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
    * @param  [type] $adminId [description]
64 64
    * @return [type]          [description]
65 65
    */
66
-  function createAndPublishPost($title, $content, $adminId=null) {
66
+  function createAndPublishPost($title, $content, $adminId = null) {
67 67
     $data = array(
68 68
       "title"          => $title,
69 69
       "content"        => $content,
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
    * @param  boolean $hits   order by hits.
87 87
    * @return array           Array of posts for a given page.
88 88
    */
89
-  function getPosts($page=1, $limit=5, $filter=false, $hits=false) {
89
+  function getPosts($page = 1, $limit = 5, $filter = false, $hits = false) {
90 90
     if ($limit != 0) $this->db->limit($limit, ($page * $limit) - $limit);
91 91
     if ($filter) $this->db->where("published", 1);
92 92
     if ($hits) {
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
    * @param  boolean $filter [description]
103 103
    * @return [type]          [description]
104 104
    */
105
-  function getRecentPosts($limit=5, $filter=false) {
105
+  function getRecentPosts($limit = 5, $filter = false) {
106 106
     if ($limit != null && $limit != null) $this->db->limit($limit);
107 107
     if ($filter) $this->db->where("published", 1);
108 108
     $this->db->order_by("id", "DESC");
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
    * @return bool            True on success, False if not.
118 118
    */
119 119
   function savePost($postId, $title, $content): bool {
120
-    $data = array (
120
+    $data = array(
121 121
       "title"   => $title,
122 122
       "content" => $content,
123 123
       "slug"    => url_title($title)
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
    * @param  int   $postId ID of the post to retrieve.
132 132
    * @return array An associative array for the Posts's data.
133 133
    */
134
-  function getPost($postId, $hit=true) {
134
+  function getPost($postId, $hit = true) {
135 135
     if (is_numeric($postId)) {
136 136
       $this->db->where("id", $postId);
137 137
     } else {
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
           $this->db->update($this->table_name);
148 148
         }
149 149
       }
150
-      $post =  $query->result_array()[0];
150
+      $post = $query->result_array()[0];
151 151
       $images = array();
152 152
       // Fetch all images in post.
153 153
       preg_match("/<img\s[^>]*?src\s*=\s*['\"]([^'\"]*?)['\"][^>]*?>/", $post["content"], $images);
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
    * [getPostsCount get the total number of posts in the database.]
190 190
    * @return [type] [description]
191 191
    */
192
-  function getPostsCount(bool $filter=true): int {
192
+  function getPostsCount(bool $filter = true): int {
193 193
     if ($filter) $this->db->where("published", 1);
194 194
     $this->db->select("COUNT(title) as posts");
195 195
     return (int) $this->db->get($this->table_name)->result()[0]->posts;
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
    * @param  boolean $filter [description]
212 212
    * @return [type]          [description]
213 213
    */
214
-  function searchPosts($words, $page, $limit=0, $filter=false) {
214
+  function searchPosts($words, $page, $limit = 0, $filter = false) {
215 215
     if ($limit != 0) $this->db->limit($limit, ($page * $limit) - $limit);
216 216
     if ($filter) $this->db->where("published", 1);
217 217
     $this->db->like("title", $words);
Please login to merge, or discard this patch.
Braces   +45 added lines, -15 removed lines patch added patch discarded remove patch
@@ -51,9 +51,15 @@  discard block
 block discarded – undo
51 51
       "content" => $content,
52 52
       "slug"    => url_title($title)
53 53
     );
54
-    if (is_numeric($title)) $data["slug"] = "_" . $data["slug"];
55
-    if ($adminId !== null) $data["poster_id"] = $adminId;
56
-    if ($this->db->insert($this->table_name, $data)) return $this->db->insert_id();
54
+    if (is_numeric($title)) {
55
+      $data["slug"] = "_" . $data["slug"];
56
+    }
57
+    if ($adminId !== null) {
58
+      $data["poster_id"] = $adminId;
59
+    }
60
+    if ($this->db->insert($this->table_name, $data)) {
61
+      return $this->db->insert_id();
62
+    }
57 63
     return 0;
58 64
   }
59 65
   /**
@@ -71,9 +77,15 @@  discard block
 block discarded – undo
71 77
       "published"      => 1,
72 78
       "date_published" => date("Y-m-d H:i:s")
73 79
     );
74
-    if (is_numeric($title)) $data["slug"] = "_" . $data["slug"];
75
-    if ($adminId != null) $data["poster_id"] = $adminId;
76
-    if ($this->db->insert($this->table_name, $data)) return $this->db->insert_id();
80
+    if (is_numeric($title)) {
81
+      $data["slug"] = "_" . $data["slug"];
82
+    }
83
+    if ($adminId != null) {
84
+      $data["poster_id"] = $adminId;
85
+    }
86
+    if ($this->db->insert($this->table_name, $data)) {
87
+      return $this->db->insert_id();
88
+    }
77 89
     return false;
78 90
   }
79 91
   /**
@@ -87,8 +99,12 @@  discard block
 block discarded – undo
87 99
    * @return array           Array of posts for a given page.
88 100
    */
89 101
   function getPosts($page=1, $limit=5, $filter=false, $hits=false) {
90
-    if ($limit != 0) $this->db->limit($limit, ($page * $limit) - $limit);
91
-    if ($filter) $this->db->where("published", 1);
102
+    if ($limit != 0) {
103
+      $this->db->limit($limit, ($page * $limit) - $limit);
104
+    }
105
+    if ($filter) {
106
+      $this->db->where("published", 1);
107
+    }
92 108
     if ($hits) {
93 109
       $this->db->order_by("hits", "DESC");
94 110
     } else {
@@ -103,8 +119,12 @@  discard block
 block discarded – undo
103 119
    * @return [type]          [description]
104 120
    */
105 121
   function getRecentPosts($limit=5, $filter=false) {
106
-    if ($limit != null && $limit != null) $this->db->limit($limit);
107
-    if ($filter) $this->db->where("published", 1);
122
+    if ($limit != null && $limit != null) {
123
+      $this->db->limit($limit);
124
+    }
125
+    if ($filter) {
126
+      $this->db->where("published", 1);
127
+    }
108 128
     $this->db->order_by("id", "DESC");
109 129
     return $this->db->get($this->table_name)->result_array();
110 130
   }
@@ -156,7 +176,9 @@  discard block
 block discarded – undo
156 176
       $src = array();
157 177
       // Get the contents of the src tag.
158 178
       preg_match("/(http|https):\/\/[a-zA-Z0-9-._\/]+/", $share_image, $src);
159
-      if (count($src) == 0) return $post;
179
+      if (count($src) == 0) {
180
+        return $post;
181
+      }
160 182
       $post["share_image"] = $src[0];
161 183
       return $post;
162 184
     }
@@ -170,7 +192,9 @@  discard block
 block discarded – undo
170 192
   function getHits($postId) {
171 193
     $this->db->where("id", $postId);
172 194
     $query = $this->db->get($this->table_name);
173
-    if ($query->num_rows() > 0) return $query->result()[0]->hits;
195
+    if ($query->num_rows() > 0) {
196
+      return $query->result()[0]->hits;
197
+    }
174 198
     return 0;
175 199
   }
176 200
   /**
@@ -190,7 +214,9 @@  discard block
 block discarded – undo
190 214
    * @return [type] [description]
191 215
    */
192 216
   function getPostsCount(bool $filter=true): int {
193
-    if ($filter) $this->db->where("published", 1);
217
+    if ($filter) {
218
+      $this->db->where("published", 1);
219
+    }
194 220
     $this->db->select("COUNT(title) as posts");
195 221
     return (int) $this->db->get($this->table_name)->result()[0]->posts;
196 222
   }
@@ -212,8 +238,12 @@  discard block
 block discarded – undo
212 238
    * @return [type]          [description]
213 239
    */
214 240
   function searchPosts($words, $page, $limit=0, $filter=false) {
215
-    if ($limit != 0) $this->db->limit($limit, ($page * $limit) - $limit);
216
-    if ($filter) $this->db->where("published", 1);
241
+    if ($limit != 0) {
242
+      $this->db->limit($limit, ($page * $limit) - $limit);
243
+    }
244
+    if ($filter) {
245
+      $this->db->where("published", 1);
246
+    }
217 247
     $this->db->like("title", $words);
218 248
     $this->db->or_like("content", $words);
219 249
     return $this->db->get($this->table_name)->result_array();
Please login to merge, or discard this patch.
unit_tests/BlogTest.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
    * Prerquisites for the Unit Tests.
20 20
    */
21 21
   public static function setUpBeforeClass(): void {
22
-    self::$ci =& get_instance();
22
+    self::$ci = & get_instance();
23 23
     self::$ci->load->database('mysqli://root@localhost/test_db');
24 24
     $queries = [
25 25
       "CREATE TABLE IF NOT EXISTS admins (id INT(7) AUTO_INCREMENT PRIMARY KEY, name VARCHAR(20) NOT NULL, password TEXT NOT NULL) Engine=InnoDB;",
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
    */
79 79
   public function testEmptyBlog(): void {
80 80
     self::$ci->blogger->setBlog("test_blog");
81
-    $this->setOutputCallback(function ($output) {
81
+    $this->setOutputCallback(function($output) {
82 82
       $this->assertRegExp("/<h3 class=\"w3-center w3-margin\">No Posts.<\/h3>/", $output);
83 83
       $this->assertRegExp("/<div class=\"w3-padding\">/", $output);
84 84
     });
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
   public function testEditor(): void {
97 97
 
98 98
     // === Collect Output ===
99
-    $this->setOutputCallback(function () {});
99
+    $this->setOutputCallback(function() {});
100 100
     $this->assertTrue(self::$ci->blogger->loadEditor("my_callback")); // Outputs Editor HTML.
101 101
     $o = $this->getActualOutput();
102 102
     // ==/ Collect Output ===
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
     $this->assertRegExp("/\/my_callback/", $o);
110 110
 
111 111
     // Reset Output Callback.
112
-    $this->setOutputCallback(function ($o) { return $o;});
112
+    $this->setOutputCallback(function($o) { return $o; });
113 113
 
114 114
     $this->expectOutputRegex("/value=\"1\"\/>/");
115 115
     $this->assertTrue(self::$ci->blogger->loadEditor("my_callback", 1)); // Outputs Editor HTML.
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
    */
238 238
   public function testEditPostUI(): void {
239 239
     // === Collect Output ===
240
-    $this->setOutputCallback(function () {});
240
+    $this->setOutputCallback(function() {});
241 241
     $this->assertTrue(self::$ci->blogger->loadEditor("a_callback", 1)); // Outputs Editor HTML.
242 242
     $o = $this->getActualOutput();
243 243
     // ==/ Collect Output ===
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
    */
355 355
   public function testRenderPostItems(): void {
356 356
     // === Collect Output ===
357
-    $this->setOutputCallback(function () {});
357
+    $this->setOutputCallback(function() {});
358 358
     $this->assertTrue(self::$ci->blogger->renderPostItems("../splints/" . self::PACKAGE . "/unit_tests/views/test_post_card_item", "the_gunners"));
359 359
     $o = $this->getActualOutput();
360 360
     // ==/ Collect Output ===
Please login to merge, or discard this patch.
libraries/Blogger.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -74,8 +74,8 @@  discard block
 block discarded – undo
74 74
    * Constructor
75 75
    * @param mixed $params associative array of parameters. See README.md
76 76
    */
77
-  function __construct($params=null) {
78
-    $this->ci =& /** @scrutinizer ignore-call */ get_instance();
77
+  function __construct($params = null) {
78
+    $this->ci = & /** @scrutinizer ignore-call */ get_instance();
79 79
     $this->ci->load->database();
80 80
     $this->table_name = self::TABLE_PREFIX . (isset($params["name"]) ? "_" . $params["name"] : "");
81 81
     $this->ci->load->database();
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
    *
100 100
    * @return bool                            True on Success, False if Not.
101 101
    */
102
-  public function install(string $blogName=null, string $adminTableName=null, string $adminIdColumnName=null, int $adminIdColumnConstraint=null): bool {
102
+  public function install(string $blogName = null, string $adminTableName = null, string $adminIdColumnName = null, int $adminIdColumnConstraint = null): bool {
103 103
     $blogName = $blogName === null ? $this->table_name : self::TABLE_PREFIX . "_" . $blogName;
104 104
     $this->ci->load->dbforge();
105 105
     $this->ci->dbforge->add_field("id");
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
    *
216 216
    * @return bool              True  if sucessfull without errors, false if not.
217 217
    */
218
-  public function loadEditor(string $callback, int $postId=null, bool $w3css=true): bool {
218
+  public function loadEditor(string $callback, int $postId = null, bool $w3css = true): bool {
219 219
     $this->loadScripts($w3css);
220 220
     $this->ci->load->helper("form");
221 221
     $data = array(
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
    *                       inputs. These are public string constants declared in
246 246
    *                       this file.
247 247
    */
248
-  public function savePost(int $posterId=null): string {
248
+  public function savePost(int $posterId = null): string {
249 249
     $action = $this->ci->security->xss_clean($this->ci->input->post("action"));
250 250
     switch ($action) {
251 251
       case "save":
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
    *
270 270
    * @return string             Action taken during the pocess; Blogger::CREATE Or Blogger::EDIT
271 271
    */
272
-  private function handleSavePost(int $posterId=null): string {
272
+  private function handleSavePost(int $posterId = null): string {
273 273
     $id = $this->ci->security->xss_clean($this->ci->input->post("id"));
274 274
     if ($id != "") {
275 275
       if (!$this->ci->bmanager->savePost($this->ci->input->post("id"), $this->ci->security->xss_clean($this->ci->input->post("title")), $this->ci->security->xss_clean($this->ci->input->post("editor")), $posterId)) return self::ABORT;
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
 
288 288
    * @return string           Action reached while processing form inputs.
289 289
    */
290
-  private function handlePublishPost(int $posterId=null): string {
290
+  private function handlePublishPost(int $posterId = null): string {
291 291
     $id = $this->ci->security->xss_clean($this->ci->input->post("id"));
292 292
     if ($id == "") return self::ABORT;
293 293
     if (!$this->ci->bmanager->savePost($id, $this->ci->security->xss_clean($this->ci->input->post("title")), $this->ci->security->xss_clean($this->ci->input->post("editor")), $posterId)) return self::ABORT;
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
    *
310 310
    * @return array           Array of posts for a given page.
311 311
    */
312
-  public function getPosts(int $page, int $limit, bool $filter=false, bool $hits=false): array {
312
+  public function getPosts(int $page, int $limit, bool $filter = false, bool $hits = false): array {
313 313
     return $this->ci->bmanager->getPosts($page, $limit, $filter, $hits);
314 314
   }
315 315
   /**
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
    *
336 336
    * @return bool                True if successful, false if not.
337 337
    */
338
-  public function renderPostItems(string $view=null, string $callback=null, string $empty_view=null, int $page=1, int $limit=5, bool $filter=false, bool $hits=false, bool $slug=true): bool {
338
+  public function renderPostItems(string $view = null, string $callback = null, string $empty_view = null, int $page = 1, int $limit = 5, bool $filter = false, bool $hits = false, bool $slug = true): bool {
339 339
     if ($view === null || $empty_view === null) $this->ci->load->bind("francis94c/blog", $blogger);
340 340
     $posts = $this->getPosts($page, $limit, $filter, $hits);
341 341
     if (count($posts) == 0) {
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
    *
365 365
    * @return array          [description]
366 366
    */
367
-  public function getRecentPosts($limit=5, $filter=false): array {
367
+  public function getRecentPosts($limit = 5, $filter = false): array {
368 368
     return $this->ci->bmanager->getRecentPosts($limit, $filter);
369 369
   }
370 370
   /**
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
    *
379 379
    * @return bool             True if successful, false if not.
380 380
    */
381
-  public function renderPost($post, $view=null): bool {
381
+  public function renderPost($post, $view = null): bool {
382 382
     if (!is_array($post)) $post = $this->ci->bmanager->getPost($post);
383 383
     if (!$post) return false;
384 384
     $post["content"] = $this->ci->parsedown->text($post["content"]);
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
    *
418 418
    * @return int  Posts count.
419 419
    */
420
-  public function getPostsCount($filter=true): int {
420
+  public function getPostsCount($filter = true): int {
421 421
     return $this->ci->bmanager->getPostsCount($filter);
422 422
   }
423 423
   /**
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
    * @param  [type] $postId [description]
426 426
    * @return [type]         [description]
427 427
    */
428
-  public function getPost($postId, $hit=true) {
428
+  public function getPost($postId, $hit = true) {
429 429
     return $this->ci->bmanager->getPost($postId, $hit);
430 430
   }
431 431
   /**
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
    * @param  boolean $filter [description]
462 462
    * @return [type]          [description]
463 463
    */
464
-  public function searchPosts($words, $page, $limit=0, $filter=false) {
464
+  public function searchPosts($words, $page, $limit = 0, $filter = false) {
465 465
     return $this->ci->bmanager->searchPosts($words, $page, $limit, $filter);
466 466
   }
467 467
 }
Please login to merge, or discard this patch.