Test Failed
Pull Request — master (#7)
by
unknown
01:39
created
src/Controller/Component/UserPermissionsComponent.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -74,9 +74,9 @@  discard block
 block discarded – undo
74 74
         $this->session = $this->controller->request->session();
75 75
 
76 76
         $this->actions 		 = array();
77
-		$this->allow 		 = true;
77
+		$this->allow = true;
78 78
 		$this->redirect 	 = null;
79
-		$this->params 		 = '';
79
+		$this->params = '';
80 80
 		$this->message 		 = '';
81 81
 		$this->userType 	 = '';
82 82
 		$this->action   	 = null;
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
     * @param array $rules Array of rules for permissions.
91 91
     * @return bool false if user / group doesn't have permission, true if has permission
92 92
     */
93
-    public function allow ($rules) {
93
+    public function allow($rules) {
94 94
     	$this->setUserValues();
95 95
     	$this->bindConfiguration($rules);
96 96
 
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
 
113 113
     private function bindConfiguration(array $rules) 
114 114
     {
115
-    	foreach($rules as $key => $value){
116
-			switch($key){
115
+    	foreach ($rules as $key => $value) {
116
+			switch ($key) {
117 117
 				case "user_type":
118 118
 			        $this->userType = $value;
119 119
 			        break;
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 			        break;
126 126
 			    case "controller":
127 127
 			        $this->controller = $value;
128
-					if(!is_object($value)) {
128
+					if (!is_object($value)) {
129 129
 						Log::write("warning", sprintf("controller is not an object (%s)", gettype($value)));
130 130
 					}
131 131
 			        break;
@@ -135,9 +135,9 @@  discard block
 block discarded – undo
135 135
 			}
136 136
 		}
137 137
 
138
-		foreach($rules['groups']  as $key => $value){
139
-			if($key == $this->userType){
140
-				foreach($value as $v){
138
+		foreach ($rules['groups']  as $key => $value) {
139
+			if ($key == $this->userType) {
140
+				foreach ($value as $v) {
141 141
 					array_push($this->actions, $v);
142 142
 				}
143 143
 			}
@@ -148,8 +148,8 @@  discard block
 block discarded – undo
148 148
     {
149 149
     	$existRulesForGroups = false;
150 150
 
151
-    	if(isset($rules['groups'])){
152
-			foreach($rules['groups'] as $key => $value){
151
+    	if (isset($rules['groups'])) {
152
+			foreach ($rules['groups'] as $key => $value) {
153 153
 				$this->searchForApplyGroupRules($key, $value);
154 154
 			}
155 155
 		}
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 
160 160
     private function searchForApplyGroupRules($key)
161 161
     {
162
-    	if($key == $this->userType){
162
+    	if ($key == $this->userType) {
163 163
     		if ($this->notInArrayAction()) {
164 164
 				$this->redirectIfIsSet();
165 165
 				
@@ -175,8 +175,8 @@  discard block
 block discarded – undo
175 175
 
176 176
     private function applyViewsRules(array $rules)
177 177
     {
178
-    	if(isset($rules['views'])){
179
-			foreach($rules['views'] as $key => $value){
178
+    	if (isset($rules['views'])) {
179
+			foreach ($rules['views'] as $key => $value) {
180 180
 				$this->searchForApplyViewRules($key, $value);
181 181
 			}
182 182
 		}
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
 
185 185
     private function searchForApplyViewRules($key, $value)
186 186
     {
187
-    	if($key == $this->action) {
188
-			if(!$this->checkForHandler($this->controller, $value) || !$this->controller->$value()){
187
+    	if ($key == $this->action) {
188
+			if (!$this->checkForHandler($this->controller, $value) || !$this->controller->$value()) {
189 189
 				$this->redirectIfIsSet();
190 190
 				
191 191
 				$this->allow = false;
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 	
196 196
 	private function checkForHandler($controller, $handler)
197 197
 	{
198
-		if(!method_exists($controller, $handler)) {
198
+		if (!method_exists($controller, $handler)) {
199 199
 			$msg = sprintf(
200 200
 				"Controller %s=%s has no method called '%s'",
201 201
 				is_object($controller) ? "class" : "type",
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 				$handler
204 204
 			);
205 205
 			Log::write("debug", $msg);
206
-			if($this->throwEx) {
206
+			if ($this->throwEx) {
207 207
 				throw new MissingHandlerException($msg);
208 208
 			}
209 209
 			return false;
@@ -214,13 +214,13 @@  discard block
 block discarded – undo
214 214
 	
215 215
     private function redirectIfIsSet()
216 216
     {
217
-    	if($this->redirect && !$this->isRedirecting){
217
+    	if ($this->redirect && !$this->isRedirecting) {
218 218
 			$this->isRedirecting = true;
219
-			if($this->message != ''){
219
+			if ($this->message != '') {
220 220
 				$this->Flash->set($this->message);
221 221
 			}
222 222
 			
223
-			if(method_exists($this->controller, "redirect")) {
223
+			if (method_exists($this->controller, "redirect")) {
224 224
 				$this->controller->redirect($this->redirect);
225 225
 			}
226 226
 			else {
Please login to merge, or discard this patch.