Passed
Push — RefactoringPosts ( 524f9b...ccb44d )
by Stone
02:19
created
App/Modules/Pagination.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@
 block discarded – undo
26 26
             throw new \Exception("Pagination Error", "404");
27 27
         }
28 28
         $pageNo = $this->removeFromBeginning($page, "page-");
29
-        if(!filter_var($pageNo, FILTER_VALIDATE_INT)){
29
+        if (!filter_var($pageNo, FILTER_VALIDATE_INT)) {
30 30
             throw new \Exception("Invalid page number");
31 31
         }
32 32
         $offset = ($pageNo - 1) * $rowsPerPage;
Please login to merge, or discard this patch.
App/Controllers/Admin/Post.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -196,10 +196,12 @@
 block discarded – undo
196 196
             $this->alertBox->setAlert("empty slug not allowed", "error");
197 197
         }
198 198
 
199
-        if ($postSlug != $originalPostSlug) //if the slug has been updated
199
+        if ($postSlug != $originalPostSlug) {
200
+            //if the slug has been updated
200 201
         {
201 202
             if (!$this->slugModel->isUnique($postSlug, "posts", "posts_slug")) {
202 203
                 $error = true;
204
+        }
203 205
                 $originalPostSlug = $this->slugModel->getSlugFromId($postId, "posts", "idposts", "posts_slug");
204 206
                 $this->alertBox->setAlert("Slug not unique", "error");
205 207
             }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
         $totalPosts = $this->postModel->totalNumberFullPosts();
81 81
         $pagination = $this->pagination->getPagination($page, $totalPosts, $postsPerPage);
82 82
 
83
-        if($postsPerPage !== Constant::LIST_PER_PAGE){
83
+        if ($postsPerPage !== Constant::LIST_PER_PAGE) {
84 84
             $this->data['paginationPostsPerPage'] = $postsPerPage;
85 85
         }
86 86
 
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
         $onFrontpage = $posts["isOnFrontPage"];
136 136
         $idUser = $userSessionId;
137 137
 
138
-        if(!is_int($idUser) || $idUser === null)
138
+        if (!is_int($idUser) || $idUser === null)
139 139
         {
140 140
             throw new \Error("Invalid userID");
141 141
         }
@@ -169,10 +169,10 @@  discard block
 block discarded – undo
169 169
 
170 170
         //checking result and redirecting
171 171
         if ($postId != null) {
172
-            $this->alertBox->setAlert("Post " . $title . " Created");
173
-            $this->container->getResponse()->redirect("admin/post/modify/" . $postSlug);
172
+            $this->alertBox->setAlert("Post ".$title." Created");
173
+            $this->container->getResponse()->redirect("admin/post/modify/".$postSlug);
174 174
         }
175
-        $this->alertBox->setAlert("Error creating " . $title, "error");
175
+        $this->alertBox->setAlert("Error creating ".$title, "error");
176 176
         $this->container->getResponse()->redirect("admin/post/new");
177 177
 
178 178
     }
@@ -241,11 +241,11 @@  discard block
 block discarded – undo
241 241
 
242 242
         //checking result and redirecting
243 243
         if ($postUpdate) {
244
-            $this->alertBox->setAlert("Post " . $title . " Updated");
245
-            $this->container->getResponse()->redirect("admin/post/modify/" . $postSlug);
244
+            $this->alertBox->setAlert("Post ".$title." Updated");
245
+            $this->container->getResponse()->redirect("admin/post/modify/".$postSlug);
246 246
         }
247
-        $this->alertBox->setAlert("Error updating " . $title, "error");
248
-        $this->container->getResponse()->redirect("admin/post/modify/" . $originalPostSlug);
247
+        $this->alertBox->setAlert("Error updating ".$title, "error");
248
+        $this->container->getResponse()->redirect("admin/post/modify/".$originalPostSlug);
249 249
     }
250 250
 
251 251
 
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
         $this->tagModel->removeTagsOnPost($postId);
262 262
         $removedPost = $this->postModel->deletePost($postId);
263 263
 
264
-        if($removedPost)
264
+        if ($removedPost)
265 265
         {
266 266
             $this->alertBox->setAlert("Post ".$postTitle." deleted");
267 267
         }
Please login to merge, or discard this patch.
App/Controllers/Admin/Home.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
 {
9 9
     public function index()
10 10
     {
11
-        if(!$this->auth->isUser()){
11
+        if (!$this->auth->isUser()) {
12 12
             $this->alertBox->setAlert("You must be connected to access the admin interface", 'warning');
13 13
             $this->container->getResponse()->redirect();
14 14
         }
Please login to merge, or discard this patch.
App/Models/PostModel.php 2 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -225,13 +225,13 @@
 block discarded – undo
225 225
     }
226 226
 
227 227
     /**
228
- * get the list of all the posts.
229
- * @param int $offset
230
- * @param array $select array of limiters [$key => $val] will convert to "where $key = $val"
231
- * @param int $limit
232
- * @return array
233
- * @throws \ErrorException
234
- */
228
+     * get the list of all the posts.
229
+     * @param int $offset
230
+     * @param array $select array of limiters [$key => $val] will convert to "where $key = $val"
231
+     * @param int $limit
232
+     * @return array
233
+     * @throws \ErrorException
234
+     */
235 235
     public function getPosts(int $offset = 0, array $select = [], int $limit = Constant::POSTS_PER_PAGE): array
236 236
     {
237 237
         return $this->getAllPublishedPosts($offset, $limit, false, $select);
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
         $this->query($sql);
114 114
         if ($select != null) {
115 115
             foreach ($select as $col => $val) {
116
-                $this->bind(":" . $col, $val);
116
+                $this->bind(":".$col, $val);
117 117
             }
118 118
         }
119 119
         $this->bind(":limit", $limit);
@@ -130,13 +130,13 @@  discard block
 block discarded – undo
130 130
      * @return int number of posts
131 131
      * @throws Exception
132 132
      */
133
-    private function countNumberPosts(array $select = [], $published=true): int
133
+    private function countNumberPosts(array $select = [], $published = true): int
134 134
     {
135 135
         $sql = "SELECT COUNT(*) FROM $this->postsTbl";
136 136
         if ($this->queryWithTags) {
137 137
             $sql .= " LEFT JOIN $this->postTagTbl ON $this->postsTbl.idposts = $this->postTagTbl.post_idposts";
138 138
         }
139
-        if($published)
139
+        if ($published)
140 140
         {
141 141
             $sql .= " WHERE published = 1";
142 142
         }
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
         $this->query($sql);
152 152
         if ($select != null) {
153 153
             foreach ($select as $col => $val) {
154
-                $this->bind(":" . $col, $val);
154
+                $this->bind(":".$col, $val);
155 155
             }
156 156
         }
157 157
         $this->execute();
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
 
335 335
         $this->execute();
336 336
 
337
-        return (int)$this->dbh->lastInsertId();
337
+        return (int) $this->dbh->lastInsertId();
338 338
     }
339 339
 
340 340
     /**
Please login to merge, or discard this patch.
App/Controllers/Ajax/postModification.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 use Core\AjaxController;
7 7
 use Core\Container;
8 8
 
9
-class postModification extends AjaxController{
9
+class postModification extends AjaxController {
10 10
 
11 11
 
12 12
     private $postModule;
@@ -23,8 +23,8 @@  discard block
 block discarded – undo
23 23
         if (!$this->container->getRequest()->isPost()) {
24 24
             throw new \Core\JsonException('Call is not post');
25 25
         }
26
-        $state = (bool)($this->request->getData("state") === 'true');
27
-        $postId = (int)$this->request->getData("postId");
26
+        $state = (bool) ($this->request->getData("state") === 'true');
27
+        $postId = (int) $this->request->getData("postId");
28 28
 
29 29
         $result["success"] = $this->postModule->setPublished(!$state, $postId);
30 30
         $result["state"] = !$state;
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
             throw new \Core\JsonException('Call is not post');
40 40
         }
41 41
         $state = ($this->request->getData("state") === 'true');
42
-        $postId = (int)$this->request->getData("postId");
42
+        $postId = (int) $this->request->getData("postId");
43 43
 
44 44
         $result["success"] = $this->postModule->setOnFrontPage(!$state, $postId);
45 45
         $result["state"] = !$state;
Please login to merge, or discard this patch.
App/Controllers/Ajax/PostVerification.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
         $postId = $this->request->getData("postId");
28 28
 
29 29
         $data = false;
30
-        if(!$this->isAlphaNum($postSlug))
30
+        if (!$this->isAlphaNum($postSlug))
31 31
         {
32 32
             echo json_encode($data);
33 33
             return;
@@ -37,10 +37,10 @@  discard block
 block discarded – undo
37 37
 
38 38
         $data = $slugModel->isUnique($postSlug, "posts", "posts_slug");
39 39
 
40
-        if($data == false) //slug is not unique, but could be from the same post
40
+        if ($data == false) //slug is not unique, but could be from the same post
41 41
         {
42
-            $slugOfId = $slugModel->getSlugFromId($postId, "posts", "idposts","posts_slug");
43
-            if($slugOfId === $postSlug)
42
+            $slugOfId = $slugModel->getSlugFromId($postId, "posts", "idposts", "posts_slug");
43
+            if ($slugOfId === $postSlug)
44 44
             {
45 45
                 //it's the same post, return true
46 46
                 $data = true;
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,9 +37,11 @@
 block discarded – undo
37 37
 
38 38
         $data = $slugModel->isUnique($postSlug, "posts", "posts_slug");
39 39
 
40
-        if($data == false) //slug is not unique, but could be from the same post
40
+        if($data == false) {
41
+            //slug is not unique, but could be from the same post
41 42
         {
42 43
             $slugOfId = $slugModel->getSlugFromId($postId, "posts", "idposts","posts_slug");
44
+        }
43 45
             if($slugOfId === $postSlug)
44 46
             {
45 47
                 //it's the same post, return true
Please login to merge, or discard this patch.
Core/Constant.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,5 +23,5 @@
 block discarded – undo
23 23
     const POSTS_PER_PAGE = 4;
24 24
     const LIST_PER_PAGE = 10;
25 25
 
26
-    const EXCERPT_WORD_COUNT =50;
26
+    const EXCERPT_WORD_COUNT = 50;
27 27
 }
28 28
\ No newline at end of file
Please login to merge, or discard this patch.
App/Controllers/Admin/Category.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 use Core\Constant;
9 9
 use Core\Container;
10 10
 
11
-class Category extends AdminController{
11
+class Category extends AdminController {
12 12
 
13 13
     protected $siteConfig;
14 14
     protected $pagination;
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
         $totalCategories = $this->categoryModel->countCategories();
48 48
         $pagination = $this->pagination->getPagination($page, $totalCategories, $linesPerPage);
49 49
 
50
-        if($linesPerPage !== Constant::LIST_PER_PAGE){
50
+        if ($linesPerPage !== Constant::LIST_PER_PAGE) {
51 51
             $this->data['paginationPostsPerPage'] = $linesPerPage;
52 52
         }
53 53
 
@@ -75,21 +75,21 @@  discard block
 block discarded – undo
75 75
         $categorySlug = $category["categories_slug"];
76 76
 
77 77
         //Sanity check on ID
78
-        if($categoryId == null )
78
+        if ($categoryId == null)
79 79
         {
80 80
             throw new \ErrorException("invalid category ID");
81 81
         }
82 82
 
83
-        $originalCategorySlug = $this->slugModel->getSlugFromId($categoryId, "categories", "idcategories","categories_slug");
83
+        $originalCategorySlug = $this->slugModel->getSlugFromId($categoryId, "categories", "idcategories", "categories_slug");
84 84
 
85 85
         //Error checking
86 86
         $error = false;
87
-        if($categoryName == "")
87
+        if ($categoryName == "")
88 88
         {
89 89
             $error = true;
90 90
             $this->alertBox->setAlert("empty name not allowed", "error");
91 91
         }
92
-        if($categorySlug == "")
92
+        if ($categorySlug == "")
93 93
         {
94 94
             $error = true;
95 95
             $this->alertBox->setAlert("empty slug not allowed", "error");
@@ -107,10 +107,10 @@  discard block
 block discarded – undo
107 107
 
108 108
         //checking result and redirecting
109 109
         if ($categoryUpdate) {
110
-            $this->alertBox->setAlert("Category " . $categoryName . " updated");
110
+            $this->alertBox->setAlert("Category ".$categoryName." updated");
111 111
             $this->container->getResponse()->redirect("/admin/category/list/");
112 112
         }
113
-        $this->alertBox->setAlert("Error updating " . $categoryName, "error");
113
+        $this->alertBox->setAlert("Error updating ".$categoryName, "error");
114 114
         $this->container->getResponse()->redirect("/admin/category/list/");
115 115
     }
116 116
 
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 
127 127
         $removedCategory = $this->categoryModel->delete($categoryId);
128 128
 
129
-        if($removedCategory)
129
+        if ($removedCategory)
130 130
         {
131 131
             $this->alertBox->setAlert("Category ".$categoryName." deleted");
132 132
         }
@@ -152,12 +152,12 @@  discard block
 block discarded – undo
152 152
 
153 153
         //Error checking
154 154
         $error = false;
155
-        if($categoryName == "")
155
+        if ($categoryName == "")
156 156
         {
157 157
             $error = true;
158 158
             $this->alertBox->setAlert("empty name not allowed", "error");
159 159
         }
160
-        if($categorySlug == "")
160
+        if ($categorySlug == "")
161 161
         {
162 162
             $error = true;
163 163
             $this->alertBox->setAlert("empty slug not allowed", "error");
@@ -175,10 +175,10 @@  discard block
 block discarded – undo
175 175
 
176 176
         //checking result and redirecting
177 177
         if ($categoryNew) {
178
-            $this->alertBox->setAlert("Category " . $categoryName . " created");
178
+            $this->alertBox->setAlert("Category ".$categoryName." created");
179 179
             $this->container->getResponse()->redirect("/admin/category/list/");
180 180
         }
181
-        $this->alertBox->setAlert("Error creating " . $categoryName, "error");
181
+        $this->alertBox->setAlert("Error creating ".$categoryName, "error");
182 182
         $this->container->getResponse()->redirect("/admin/category/list/");
183 183
     }
184 184
 }
185 185
\ No newline at end of file
Please login to merge, or discard this patch.
App/Controllers/Admin/Tag.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 use Core\Constant;
8 8
 use Core\Container;
9 9
 
10
-class Tag extends AdminController{
10
+class Tag extends AdminController {
11 11
 
12 12
     protected $siteConfig;
13 13
     protected $pagination;
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
         $totalCategories = $this->tagModel->countTags();
33 33
         $pagination = $this->pagination->getPagination($page, $totalCategories, $linesPerPage);
34 34
 
35
-        if($linesPerPage !== Constant::LIST_PER_PAGE){
35
+        if ($linesPerPage !== Constant::LIST_PER_PAGE) {
36 36
             $this->data['paginationPostsPerPage'] = $linesPerPage;
37 37
         }
38 38
 
@@ -60,14 +60,14 @@  discard block
 block discarded – undo
60 60
 
61 61
 
62 62
         //Sanity check on ID
63
-        if($tagId == null )
63
+        if ($tagId == null)
64 64
         {
65 65
             throw new \ErrorException("invalid tag ID");
66 66
         }
67 67
 
68 68
         //Error checking
69 69
         $error = false;
70
-        if($tagName == "")
70
+        if ($tagName == "")
71 71
         {
72 72
             $error = true;
73 73
             $this->alertBox->setAlert("empty name not allowed", "error");
@@ -81,10 +81,10 @@  discard block
 block discarded – undo
81 81
 
82 82
         //checking result and redirecting
83 83
         if ($tagUpdate) {
84
-            $this->alertBox->setAlert("Tag " . $tagName . " updated");
84
+            $this->alertBox->setAlert("Tag ".$tagName." updated");
85 85
             $this->response->redirect("/admin/tag/list/");
86 86
         }
87
-        $this->alertBox->setAlert("Error updating " . $tagName, "error");
87
+        $this->alertBox->setAlert("Error updating ".$tagName, "error");
88 88
         $this->response->redirect("/admin/tag/list/");
89 89
     }
90 90
 
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 
101 101
         $removedTag = $this->tagModel->delete($tagId);
102 102
 
103
-        if($removedTag)
103
+        if ($removedTag)
104 104
         {
105 105
             $this->alertBox->setAlert("Tag ".$tagName." deleted");
106 106
         }
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 
126 126
         //Error checking
127 127
         $error = false;
128
-        if($tagName == "")
128
+        if ($tagName == "")
129 129
         {
130 130
             $error = true;
131 131
             $this->alertBox->setAlert("empty name not allowed", "error");
@@ -139,10 +139,10 @@  discard block
 block discarded – undo
139 139
 
140 140
         //checking result and redirecting
141 141
         if ($tagNew) {
142
-            $this->alertBox->setAlert("Tag " . $tagName . " created");
142
+            $this->alertBox->setAlert("Tag ".$tagName." created");
143 143
             $this->response->redirect("/admin/tag/list/");
144 144
         }
145
-        $this->alertBox->setAlert("Error creating " . $tagName, "error");
145
+        $this->alertBox->setAlert("Error creating ".$tagName, "error");
146 146
         $this->response->redirect("/admin/tag/list/");
147 147
     }
148 148
 }
149 149
\ No newline at end of file
Please login to merge, or discard this patch.