Passed
Push — Security_and_bug_fixes ( 4b1330...cc57a2 )
by Stone
02:48
created
App/Controllers/Ajax/User.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 use Core\JsonException;
9 9
 use Core\Traits\StringFunctions;
10 10
 
11
-class User  extends AjaxController{
11
+class User  extends AjaxController {
12 12
 
13 13
     use StringFunctions;
14 14
 
@@ -25,12 +25,12 @@  discard block
 block discarded – undo
25 25
         //the router needs a parameter with get functions else throsw a wobbly
26 26
         //we pass a get variable and call the /controller/function/get?bla
27 27
         //for better use and security, we must pass "get" as the parameter
28
-        if(!$this->startsWith(strtolower($get),"get"))
28
+        if (!$this->startsWith(strtolower($get), "get"))
29 29
         {
30 30
             throw new JsonException("invalid call");
31 31
         }
32 32
         $email = $this->request->getData("email");
33
-        if($email === null)
33
+        if ($email === null)
34 34
         {
35 35
             throw new JsonException("Empty email");
36 36
         }
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
     {
52 52
         $this->onlyAdmin();
53 53
         $this->onlyPost();
54
-        $state = (bool)($this->request->getData("state") === 'true');
55
-        $userId = (int)$this->request->getData("userId");
54
+        $state = (bool) ($this->request->getData("state") === 'true');
55
+        $userId = (int) $this->request->getData("userId");
56 56
 
57 57
         $result = array();
58 58
         $result["success"] = false;
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
         $result["userId"] = $userId;
61 61
 
62 62
         // we can not update the Original Admin activation state
63
-        if($userId !== 1)
63
+        if ($userId !== 1)
64 64
         {
65 65
             $result["success"] = $this->userModel->activateUser(!$state, $userId);
66 66
             $result["state"] = !$state;
Please login to merge, or discard this patch.
App/Controllers/Post.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -91,9 +91,11 @@
 block discarded – undo
91 91
         $admin = $this->session->get('user_role_level') >= Constant::ADMIN_LEVEL;
92 92
         $commentId = $this->commentModel->addComment($postId, $userId, $comment, $admin);
93 93
 
94
-        if (!$admin) //if we are not an admin, send an email to alert and add an alertBox
94
+        if (!$admin) {
95
+            //if we are not an admin, send an email to alert and add an alertBox
95 96
         {
96 97
             $siteConfig = $this->siteConfig->getSiteConfig();
98
+        }
97 99
             $post = $this->postModel->getSinglePost($postId);
98 100
             $baseUrl = $this->request->getBaseUrl();
99 101
 
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -42,11 +42,11 @@  discard block
 block discarded – undo
42 42
     public function viewPost(string $slug, string $page = "page-1", int $linesPerPage = Constant::COMMENTS_PER_PAGE)
43 43
     {
44 44
 
45
-        $postId = (int)$this->postModel->getPostIdFromSlug($slug);
45
+        $postId = (int) $this->postModel->getPostIdFromSlug($slug);
46 46
 
47 47
         $posts = $this->postModel->getSinglePost($postId);
48 48
 
49
-        if($posts === false)
49
+        if ($posts === false)
50 50
         {
51 51
             throw new \Exception("Page no longer exists", "404");
52 52
         }
@@ -89,9 +89,9 @@  discard block
 block discarded – undo
89 89
         $this->onlyUser();
90 90
 
91 91
         //get the session userId
92
-        $userId = (int)$this->session->get("userId");
93
-        $comment = (string)$this->request->getData("newComment");
94
-        $postId = (int)$this->request->getData("postId");
92
+        $userId = (int) $this->session->get("userId");
93
+        $comment = (string) $this->request->getData("newComment");
94
+        $postId = (int) $this->request->getData("postId");
95 95
 
96 96
         //check if we are admin, Admins do not need moderation
97 97
         $admin = $this->session->get('user_role_level') >= Constant::ADMIN_LEVEL;
@@ -103,8 +103,8 @@  discard block
 block discarded – undo
103 103
             $post = $this->postModel->getSinglePost($postId);
104 104
             $baseUrl = $this->request->getBaseUrl();
105 105
 
106
-            $emailMessage = "<h1>New comment on post " . $post->title . "</a></h1>";
107
-            $emailMessage .= "<p>Check it out <a href='" . $baseUrl . "admin/comments/moderate-comment/" . $commentId . "'>here</a> </p>";
106
+            $emailMessage = "<h1>New comment on post ".$post->title."</a></h1>";
107
+            $emailMessage .= "<p>Check it out <a href='".$baseUrl."admin/comments/moderate-comment/".$commentId."'>here</a> </p>";
108 108
 
109 109
             $this->sendMail->send($siteConfig["admin_email_address"], "New comment added", $emailMessage);
110 110
 
@@ -113,6 +113,6 @@  discard block
 block discarded – undo
113 113
 
114 114
         $postSlug = $this->postModel->getPostSlugFromId($postId);
115 115
 
116
-        $this->response->redirect("/post/view-post/" . $postSlug);
116
+        $this->response->redirect("/post/view-post/".$postSlug);
117 117
     }
118 118
 }
119 119
\ No newline at end of file
Please login to merge, or discard this patch.
App/Controllers/Admin/Comments.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 use Core\Container;
10 10
 use Core\Traits\StringFunctions;
11 11
 
12
-class Comments extends AdminController{
12
+class Comments extends AdminController {
13 13
 
14 14
     use StringFunctions;
15 15
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
         }
122 122
 
123 123
         $refererUrl = $this->request->getReferer();
124
-        if($refererUrl === "") //referer can return null, set default
124
+        if ($refererUrl === "") //referer can return null, set default
125 125
         {
126 126
             $refererUrl = "admin/comments/view-comments";
127 127
         }
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
         }
153 153
 
154 154
         //update comment
155
-        if($this->commentModel->update($commentId, $comment["commentTextArea"], $comment["commentApproved"]))
155
+        if ($this->commentModel->update($commentId, $comment["commentTextArea"], $comment["commentApproved"]))
156 156
         {
157 157
             $this->alertBox->setAlert("Comment updated");
158 158
         }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -121,10 +121,12 @@
 block discarded – undo
121 121
         }
122 122
 
123 123
         $refererUrl = $this->request->getReferer();
124
-        if($refererUrl === "") //referer can return null, set default
124
+        if($refererUrl === "") {
125
+            //referer can return null, set default
125 126
         {
126 127
             $refererUrl = "admin/comments/view-comments";
127 128
         }
129
+        }
128 130
         $baseUrl = $this->request->getBaseUrl();
129 131
         $redirectUrl = $this->removeFromBeginning($refererUrl, $baseUrl);
130 132
 
Please login to merge, or discard this patch.
Core/Traits/StringFunctions.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 
86 86
         //Searching for the page break tag
87 87
         $breakTagPosition = strpos($text, "<!-- EndOfExcerptBlogOc -->");
88
-        if($breakTagPosition > 0){
88
+        if ($breakTagPosition > 0) {
89 89
             return $this->completeDom(substr($text, 0, $breakTagPosition));
90 90
         }
91 91
 
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
         $string = preg_split('/(<img[^>]+\>)|(<p[^>]+\>)|(<span[^>]+\>)|\s/', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
94 94
 
95 95
         //The preg split can return false, probably will never happen but just in case.
96
-        if(!$string)
96
+        if (!$string)
97 97
         {
98 98
             throw new \Error("excerpt generation failed");
99 99
         }
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
             $trimmed .= $string[$wordCounter];
107 107
             if ($wordCounter < $count - 1) {
108 108
                 $trimmed .= " ";
109
-            } else {
109
+            }else {
110 110
                 $trimmed .= "[...]";
111 111
             }
112 112
         }
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
         $result = true;
147 147
         foreach ($strings as $string)
148 148
         {
149
-            if(!$this->isAlphaNum($string))
149
+            if (!$this->isAlphaNum($string))
150 150
             {
151 151
                 $result = false;
152 152
             }
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
      */
162 162
     public function isHexa(string $string):bool
163 163
     {
164
-        return preg_match("/[\da-f]/",$string) === 1;
164
+        return preg_match("/[\da-f]/", $string) === 1;
165 165
     }
166 166
 
167 167
     /**
Please login to merge, or discard this patch.
App/Controllers/Ajax/Comment.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -24,8 +24,8 @@  discard block
 block discarded – undo
24 24
     {
25 25
         $this->onlyAdmin();
26 26
         $this->onlyPost();
27
-        $state = (bool)($this->request->getData("state") === 'true');
28
-        $commentId = (int)$this->request->getData("commentId");
27
+        $state = (bool) ($this->request->getData("state") === 'true');
28
+        $commentId = (int) $this->request->getData("commentId");
29 29
 
30 30
         $result = array();
31 31
         $result["success"] = $this->commentModel->setApproved(!$state, $commentId);
@@ -36,8 +36,8 @@  discard block
 block discarded – undo
36 36
 
37 37
     public function loadComments()
38 38
     {
39
-        $commentOffset = (int)$this->request->getData("commentOffset");
40
-        $postId = (int)$this->request->getData("postId");
39
+        $commentOffset = (int) $this->request->getData("commentOffset");
40
+        $postId = (int) $this->request->getData("postId");
41 41
 
42 42
         $result = array();
43 43
         $result["success"] = false;
Please login to merge, or discard this patch.
App/Modules/Slug.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@
 block discarded – undo
5 5
 use Cocur\Slugify\Slugify;
6 6
 use Core\Modules\Module;
7 7
 
8
-class Slug extends Module{
8
+class Slug extends Module {
9 9
     public function isSlugValid(string $slug):bool
10 10
     {
11 11
         $slugify = new Slugify();
Please login to merge, or discard this patch.
App/Controllers/Admin/Home.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
         $this->session->remove("registrationErrors");
52 52
 
53 53
         $userId = $this->session->get("userId");
54
-        if($userId === null)
54
+        if ($userId === null)
55 55
         {
56 56
             //this should never happen but scrutinizer thows an alert
57 57
             throw new \Exception("Session error, no ID");
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 
60 60
         $userDetails = $this->userModel->getUserDetailsById($userId);
61 61
 
62
-        if($userDetails === false)
62
+        if ($userDetails === false)
63 63
         {
64 64
             //the user is still logged in his session but deleted from the DB.
65 65
             $this->cookie->deleteCookie("rememberMe");
@@ -114,14 +114,14 @@  discard block
 block discarded – undo
114 114
         $this->onlyUser();
115 115
         $this->onlyPost();
116 116
 
117
-        $user = (object)$this->request->getDataFull();
117
+        $user = (object) $this->request->getDataFull();
118 118
         $redirectUrl = "/admin";
119 119
 
120 120
         if ($user->userId !== $this->session->get("userId") || isset($user->userRoleSelector) || isset($user->locked_out)) {
121 121
             //an admin is trying to update a user or form tampered with
122 122
             $this->onlyAdmin();
123
-            $redirectUrl = "/admin/home/view-user/" . $user->userId;
124
-        } else {
123
+            $redirectUrl = "/admin/home/view-user/".$user->userId;
124
+        }else {
125 125
             //set the role to the original state for update
126 126
             $beforeUser = $this->userModel->getUserDetailsById($user->userId);
127 127
             $user->userRoleSelector = $beforeUser->roles_idroles;
@@ -135,13 +135,13 @@  discard block
 block discarded – undo
135 135
         $error = false;
136 136
         $registerErrors = new \stdClass();
137 137
 
138
-        if($userId == 1 && $user->userLockedOut == 1)
138
+        if ($userId == 1 && $user->userLockedOut == 1)
139 139
         {
140 140
             $error = true;
141 141
             $this->alertBox->setAlert("Original admin may not be deactivated", "error");
142 142
         }
143 143
 
144
-        if($userId == 1 && $user->userRoleSelector != 2)
144
+        if ($userId == 1 && $user->userRoleSelector != 2)
145 145
         {
146 146
             $error = true;
147 147
             $this->alertBox->setAlert("Original admin must stay admin", "error");
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
             throw new \Exception("Error in passed ID");
229 229
         }
230 230
 
231
-        if($userId === 1)
231
+        if ($userId === 1)
232 232
         {
233 233
             $this->alertBox->setAlert('Original Admin can not be deleted', "error");
234 234
             $this->response->redirect("/admin/home/list-users");
Please login to merge, or discard this patch.
Core/Container.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -50,10 +50,10 @@  discard block
 block discarded – undo
50 50
         $twigOptions = [];
51 51
         if (!Config::DEV_ENVIRONMENT) {
52 52
             $twigOptions = [
53
-                'cache' => dirname(__DIR__) . '/Cache'
53
+                'cache' => dirname(__DIR__).'/Cache'
54 54
             ];
55 55
         }
56
-        $loader = new \Twig_Loader_Filesystem(dirname(__DIR__) . '/App/Views');
56
+        $loader = new \Twig_Loader_Filesystem(dirname(__DIR__).'/App/Views');
57 57
         $twig = new \Twig_Environment($loader, $twigOptions);
58 58
 
59 59
         return $twig;
@@ -68,14 +68,14 @@  discard block
 block discarded – undo
68 68
         if ($this->dbh) {
69 69
             return $this->dbh;
70 70
         }
71
-        $dsn = "mysql:host=" . Config::DB_HOST . ";dbname=" . Config::DB_NAME . ";charset=utf8"; //Creating the Data Source name
71
+        $dsn = "mysql:host=".Config::DB_HOST.";dbname=".Config::DB_NAME.";charset=utf8"; //Creating the Data Source name
72 72
         $opt = [
73 73
             PDO::ATTR_PERSISTENT => true,
74 74
             PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
75 75
             PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
76 76
             PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true
77 77
         ];
78
-        $this->dbh = new PDO($dsn, Config::DB_USER, Config::DB_PASSWORD, $opt);;
78
+        $this->dbh = new PDO($dsn, Config::DB_USER, Config::DB_PASSWORD, $opt); ;
79 79
         return $this->dbh;
80 80
     }
81 81
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
      */
122 122
     public function getCookie(): Dependency\Cookie
123 123
     {
124
-        if(!$this->cookie){
124
+        if (!$this->cookie) {
125 125
             $this->cookie = new Cookie();
126 126
         }
127 127
         return $this->cookie;
Please login to merge, or discard this patch.
App/Controllers/Home.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@
 block discarded – undo
33 33
 
34 34
         $this->config = $this->siteConfig->getSiteConfig();
35 35
         $this->userModel = new UserModel($this->container);
36
-        if($this->auth->isuser())
36
+        if ($this->auth->isuser())
37 37
         {
38 38
             $this->data["user"] = $this->userModel->getUserDetailsById($this->session->get("userId"));
39 39
         }
Please login to merge, or discard this patch.