Passed
Push — master ( dcfcd7...0a0799 )
by Georgi
03:16
created
src/Dashboard/DashboardView.php 3 patches
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -142,7 +142,9 @@  discard block
 block discarded – undo
142 142
 		
143 143
 	public function addMenu()
144 144
 	{
145
-		if ($this->isLocked()) return;
145
+		if ($this->isLocked()) {
146
+			return;
147
+		}
146 148
 		
147 149
 		$dashboardId = $this->dashboard()->id;
148 150
 		
@@ -165,14 +167,18 @@  discard block
 block discarded – undo
165 167
 		$dashboardMenu->addItem([__('Rename dashboard'), 'icon' => 'i cursor'])->on('click', $modal->show());
166 168
 		
167 169
 		// there is only one admin default dashboard
168
-		if ($this->admin) return;
170
+		if ($this->admin) {
171
+			return;
172
+		}
169 173
 		
170 174
 		// ***** add ***** //		
171 175
 		$modal = $this->add(['Modal', 'title' => __('Add Dashboard')])->set(\Closure::fromCallable([$this, 'addDashboard']));
172 176
 		
173 177
 		$dashboardMenu->addItem([__('Add dashboard'), 'icon' => 'add'])->on('click', $modal->show());
174 178
 		
175
-		if ($this->isSingleDashboard()) return;
179
+		if ($this->isSingleDashboard()) {
180
+			return;
181
+		}
176 182
 		
177 183
 		// ***** reorder ***** //
178 184
 		$modal = $this->add(['Modal', 'title' => __('Reorder Dashboards')])->set(\Closure::fromCallable([$this, 'reorderDashboards']));
Please login to merge, or discard this patch.
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 		$columns = $this->add(['Columns', 'id' => 'dashboard', 'ui' => 'three stackable grid'  . ($this->isLocked()? ' locked': '')]);
49 49
 		
50 50
 		foreach ([1, 2, 3] as $columnId) {
51
-		    $columnApplets = clone $applets;
51
+			$columnApplets = clone $applets;
52 52
 		    
53 53
 			/** @scrutinizer ignore-call */
54 54
 			$col = $columns->addColumn([
@@ -205,9 +205,9 @@  discard block
 block discarded – undo
205 205
 		$existingList = collect($existing->export())->pluck('name', 'id');
206 206
 		
207 207
 		$form->addFields([
208
-		        ['name', __('Name')],
209
-		        ['base', ['DropDown', 'caption' => __('Copy applets from'), 'values' => $existingList]]
210
-        ]);
208
+				['name', __('Name')],
209
+				['base', ['DropDown', 'caption' => __('Copy applets from'), 'values' => $existingList]]
210
+		]);
211 211
 		
212 212
 		$form->layout->addButton(['Button', __('Cancel')])->on('click', $view->owner->hide());
213 213
 		
@@ -219,19 +219,19 @@  discard block
 block discarded – undo
219 219
 			$dashboardId = (int) $dashboard->insert([
220 220
 					'name' => $values['name'],
221 221
 					'user_id' => $this->userId(),
222
-			        'position' => count($existingList)
222
+					'position' => count($existingList)
223 223
 			]);
224 224
 			
225 225
 			if ($values['base']) {
226
-			    foreach ($dashboard->withID($values['base'])->ref('applets') as $baseApplet) {
227
-			        // only save on below does not work for some reason. fails when reloading
228
-			        $baseApplet->duplicate()->saveAndUnload(['dashboard_id' => $dashboardId]);
226
+				foreach ($dashboard->withID($values['base'])->ref('applets') as $baseApplet) {
227
+					// only save on below does not work for some reason. fails when reloading
228
+					$baseApplet->duplicate()->saveAndUnload(['dashboard_id' => $dashboardId]);
229 229
 				}
230 230
 			}
231 231
 
232 232
 			return [
233 233
 					$form->notify(__('Dashboard created, redirecting ...')),
234
-			        new jsExpression('window.setTimeout(function() {window.location.replace([])}, 1200)', [$this->selfLink('body', ['dashboard' => $dashboardId])])
234
+					new jsExpression('window.setTimeout(function() {window.location.replace([])}, 1200)', [$this->selfLink('body', ['dashboard' => $dashboardId])])
235 235
 			];
236 236
 		});
237 237
 	}
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 			
250 250
 			return [
251 251
 					$form->notifySuccess(__('Dashboard renamed, reloading ...')),
252
-			        new jsExpression('window.setTimeout(function() {window.location.replace([])}, 1200)', [$this->selfLink('body', ['dashboard' => $this->dashboard()->id])])
252
+					new jsExpression('window.setTimeout(function() {window.location.replace([])}, 1200)', [$this->selfLink('body', ['dashboard' => $this->dashboard()->id])])
253 253
 			];
254 254
 		});
255 255
 	}
@@ -261,8 +261,8 @@  discard block
 block discarded – undo
261 261
 		$name = $dashboard['name'];
262 262
 
263 263
 		return $dashboard->delete()? [
264
-		        $this->notifySuccess(__('Dashboard ":name" deleted, redirecting ...', compact('name'))),
265
-		        new jsExpression('window.setTimeout(function() {window.location.replace([])}, 1200)', [$this->selfLink()])
264
+				$this->notifySuccess(__('Dashboard ":name" deleted, redirecting ...', compact('name'))),
265
+				new jsExpression('window.setTimeout(function() {window.location.replace([])}, 1200)', [$this->selfLink()])
266 266
 		]: $this->notifyError(__('Error deleting dashboard'));
267 267
 	}
268 268
 	
@@ -273,14 +273,14 @@  discard block
 block discarded – undo
273 273
 		$grid->setModel($this->userDashboards()->setOrder('position'));
274 274
 	
275 275
 		$grid->addDragHandler()->onReorder(function ($order) use ($grid) {
276
-		    foreach ($this->userDashboards() as $dashboard) {
276
+			foreach ($this->userDashboards() as $dashboard) {
277 277
 				$dashboard->save(['position' => array_search($dashboard->id, $order)]);
278 278
 			}
279 279
 			
280
-		    return [
281
-		            new jsReload($grid),
282
-		            $this->notifySuccess(__('Dashboards reordered!'))
283
-		    ];
280
+			return [
281
+					new jsReload($grid),
282
+					$this->notifySuccess(__('Dashboards reordered!'))
283
+			];
284 284
 		});
285 285
 
286 286
 		$view->add(['View', 'ui' => 'buttons'])->add(['Button', __('Done'), 'primary'])->on('click', new jsExpression('location.reload()'));
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
 		$form->model->set($applet['options']);
336 336
 		
337 337
 		$form->validate(function(Form $form) use ($applet) {
338
-		    $applet->save(['options' => $form->model->get()]);
338
+			$applet->save(['options' => $form->model->get()]);
339 339
 
340 340
 			return $form->notifySuccess(__('Settings saved!'));
341 341
 		});
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 	
393 393
 	protected function defaultSystemDashboard()
394 394
 	{
395
-	    return $this->userDashboards(0)->setOrder('position')->tryLoadAny();
395
+		return $this->userDashboards(0)->setOrder('position')->tryLoadAny();
396 396
 	}
397 397
 	
398 398
 	protected function userDashboards($userId = null)
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	
26 26
 	public function body()
27 27
 	{
28
-		if (! $this->isSingleDashboard()) {
28
+		if (!$this->isSingleDashboard()) {
29 29
 			$this->location($this->dashboard()['name']);
30 30
 		}
31 31
 		
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 		
46 46
 		$applets = $dashboard->ref('applets')->setOrder(['column', 'row']);
47 47
 
48
-		$columns = $this->add(['Columns', 'id' => 'dashboard', 'ui' => 'three stackable grid'  . ($this->isLocked()? ' locked': '')]);
48
+		$columns = $this->add(['Columns', 'id' => 'dashboard', 'ui' => 'three stackable grid' . ($this->isLocked() ? ' locked' : '')]);
49 49
 		
50 50
 		foreach ([1, 2, 3] as $columnId) {
51 51
 		    $columnApplets = clone $applets;
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 			}
72 72
 		}
73 73
 		
74
-		if (! $this->isLocked()) {
74
+		if (!$this->isLocked()) {
75 75
 			$columns->js(true)->find('.sortable')->sortable([
76 76
 					'cursor' => 'move',
77 77
 					'handle' => '.panel-sortable-handle',
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 					])
90 90
 			]));
91 91
 			
92
-			$columns->js(true)->find('.applet-close')->click(new jsFunction(['e'], [new jsExpression('if (confirm("' .  __('Delete this applet?') . '")) {$(e.target).closest(".applet").fadeOut(400, function(){var col = $(this).closest(".column.sortable");this.remove();col.trigger("sortupdate");})}')]));
92
+			$columns->js(true)->find('.applet-close')->click(new jsFunction(['e'], [new jsExpression('if (confirm("' . __('Delete this applet?') . '")) {$(e.target).closest(".applet").fadeOut(400, function(){var col = $(this).closest(".column.sortable");this.remove();col.trigger("sortupdate");})}')]));
93 93
 		}
94 94
 		
95 95
 		$this->columns = $columns;
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 				]
137 137
 		]);
138 138
 
139
-		foreach ( AppletJoint::collect() as $applet ) {
139
+		foreach (AppletJoint::collect() as $applet) {
140 140
 			$col->add([
141 141
 					new Applet(),
142 142
 					'appletId' => 'new_' . str_ireplace('\\', '-', get_class($applet)),
@@ -260,10 +260,10 @@  discard block
 block discarded – undo
260 260
 		
261 261
 		$name = $dashboard['name'];
262 262
 
263
-		return $dashboard->delete()? [
263
+		return $dashboard->delete() ? [
264 264
 		        $this->notifySuccess(__('Dashboard ":name" deleted, redirecting ...', compact('name'))),
265 265
 		        new jsExpression('window.setTimeout(function() {window.location.replace([])}, 1200)', [$this->selfLink()])
266
-		]: $this->notifyError(__('Error deleting dashboard'));
266
+		] : $this->notifyError(__('Error deleting dashboard'));
267 267
 	}
268 268
 	
269 269
 	public function reorderDashboards($view)
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 		
273 273
 		$grid->setModel($this->userDashboards()->setOrder('position'));
274 274
 	
275
-		$grid->addDragHandler()->onReorder(function ($order) use ($grid) {
275
+		$grid->addDragHandler()->onReorder(function($order) use ($grid) {
276 276
 		    foreach ($this->userDashboards() as $dashboard) {
277 277
 				$dashboard->save(['position' => array_search($dashboard->id, $order)]);
278 278
 			}
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
 	
355 355
 	public function isLocked()
356 356
 	{
357
-		return $this->locked || ! Auth::user()->can('edit dashboard');
357
+		return $this->locked || !Auth::user()->can('edit dashboard');
358 358
 	}
359 359
 	
360 360
 	protected function isSingleDashboard()
@@ -370,18 +370,18 @@  discard block
 block discarded – undo
370 370
 	 */
371 371
 	protected function dashboard()
372 372
 	{
373
-		if (! is_object($this->dashboard)) {
374
-			$this->dashboard = $this->dashboard? Dashboard::create()->tryLoad($this->dashboard): $this->defaultUserDashboard();
373
+		if (!is_object($this->dashboard)) {
374
+			$this->dashboard = $this->dashboard ? Dashboard::create()->tryLoad($this->dashboard) : $this->defaultUserDashboard();
375 375
 		}
376 376
 
377
-		return $this->dashboard?: abort(404);
377
+		return $this->dashboard ?: abort(404);
378 378
 	}
379 379
 	
380 380
 	protected function defaultUserDashboard()
381 381
 	{
382 382
 		$userDashboard = $this->userDashboards()->setOrder('position')->tryLoadAny();
383 383
 		
384
-		if (! $userDashboard->loaded()) {
384
+		if (!$userDashboard->loaded()) {
385 385
 			$this->lock();
386 386
 			
387 387
 			$userDashboard = $this->defaultSystemDashboard();
@@ -405,6 +405,6 @@  discard block
 block discarded – undo
405 405
 	 */
406 406
 	protected function userId()
407 407
 	{
408
-		return $this->admin? 0: Auth::id();
408
+		return $this->admin ? 0 : Auth::id();
409 409
 	}
410 410
 }
Please login to merge, or discard this patch.
src/Dashboard/Seeds/Applet.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@
 block discarded – undo
28 28
 			$this->set($joint->info())->setAttr('searchkey', strtolower($joint->caption() . ';' . $joint->info()));
29 29
 		}
30 30
 		else {
31
-			if (! $this->locked) {
31
+			if (!$this->locked) {
32 32
 				$this->addControl('close', 'applet-close')->setAttr('title', __('Close applet'));
33 33
 			}
34 34
 			
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,8 +26,7 @@
 block discarded – undo
26 26
 		
27 27
 		if ($this->admin) {
28 28
 			$this->set($joint->info())->setAttr('searchkey', strtolower($joint->caption() . ';' . $joint->info()));
29
-		}
30
-		else {
29
+		} else {
31 30
 			if (! $this->locked) {
32 31
 				$this->addControl('close', 'applet-close')->setAttr('title', __('Close applet'));
33 32
 			}
Please login to merge, or discard this patch.
src/CommonData/CommonDataSettings.php 3 patches
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 
11 11
 class CommonDataSettings extends ModuleView
12 12
 {
13
-    use SessionTrait;
13
+	use SessionTrait;
14 14
     
15 15
 	protected $label = 'Common Data';
16 16
 	
@@ -36,23 +36,23 @@  discard block
 block discarded – undo
36 36
 	
37 37
 	public function setAncestors()
38 38
 	{
39
-	    $parent = $this->stickyGet('parent');
39
+		$parent = $this->stickyGet('parent');
40 40
 	    
41
-	    if (isset($parent)) {
42
-	        $this->memorize('parent', $parent?: null);
43
-	    }
41
+		if (isset($parent)) {
42
+			$this->memorize('parent', $parent?: null);
43
+		}
44 44
 
45
-	    $this->ancestors = Models\CommonData::ancestorsAndSelf($this->recall('parent'));
45
+		$this->ancestors = Models\CommonData::ancestorsAndSelf($this->recall('parent'));
46 46
 	}
47 47
 	
48 48
 	public function setLocation()
49 49
 	{
50
-	    $location = [['label' => $this->label, 'link' => '?parent=0']];	    
50
+		$location = [['label' => $this->label, 'link' => '?parent=0']];	    
51 51
 		foreach (Models\CommonData::create()->withID($this->ancestors) as $node) {
52
-		    $location[] = [
53
-		            'label' => $node['value'] ?: $node['key'], 
54
-		            'link' => '?parent=' . $node['id']
55
-		    ];
52
+			$location[] = [
53
+					'label' => $node['value'] ?: $node['key'], 
54
+					'link' => '?parent=' . $node['id']
55
+			];
56 56
 		}
57 57
 
58 58
 		$this->label = null;
@@ -69,17 +69,17 @@  discard block
 block discarded – undo
69 69
 				'editFields' => ['key', 'value'],
70 70
 				'addFields' => ['key', 'value'],
71 71
 				'displayFields' => ['key', 'value', 'readonly'],
72
-		        'notifyDefault' => ['jsToast', 'settings' => ['message' => __('Data is saved!'), 'class' => 'success']],
72
+				'notifyDefault' => ['jsToast', 'settings' => ['message' => __('Data is saved!'), 'class' => 'success']],
73 73
 				'paginator' => false,
74
-		        'menu' => ActionBar::instance(),
75
-		        'quickSearch' => ['key', 'value']
74
+				'menu' => ActionBar::instance(),
75
+				'quickSearch' => ['key', 'value']
76 76
 		]);
77 77
 
78 78
 		$this->grid->setModel($this->nodes()->setOrder('position'));
79 79
 		
80 80
 		$this->grid->addActionButton(['icon' => 'level down', 'attr' => ['title' => __('Drilldown')]], new jsExpression(
81
-		        'document.location=\'?parent=\'+[]',
82
-		        [$this->grid->jsRow()->data('id')]
81
+				'document.location=\'?parent=\'+[]',
82
+				[$this->grid->jsRow()->data('id')]
83 83
 		));
84 84
 
85 85
 		$this->grid->addDragHandler()->onReorder(function ($order) {
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 		});
95 95
 
96 96
 		if ($this->ancestors && $this->grid->menu) {
97
-		    $this->grid->menu->addItem([__('Level Up'), 'icon' => 'level up'], '?parent=' . $this->parent(1));
97
+			$this->grid->menu->addItem([__('Level Up'), 'icon' => 'level up'], '?parent=' . $this->parent(1));
98 98
 		}
99 99
 		
100 100
 		return $this;
@@ -102,29 +102,29 @@  discard block
 block discarded – undo
102 102
 	
103 103
 	public function parent($level = 0)
104 104
 	{
105
-	    return $this->ancestors[$level] ?? 0;
105
+		return $this->ancestors[$level] ?? 0;
106 106
 	}
107 107
 	
108 108
 	public function nodes()
109 109
 	{
110
-	    $nodes = Models\CommonData::create();
110
+		$nodes = Models\CommonData::create();
111 111
 	    
112
-	    //@TODO: remove below when adding null condition fixed
113
-	    if ($parent = $this->parent()) {
114
-	        $nodes->addCondition('parent', $parent);
115
-	    }
116
-	    else {
117
-	        $nodes->addCondition($nodes->expr('parent is NULL'));
118
-	    }
112
+		//@TODO: remove below when adding null condition fixed
113
+		if ($parent = $this->parent()) {
114
+			$nodes->addCondition('parent', $parent);
115
+		}
116
+		else {
117
+			$nodes->addCondition($nodes->expr('parent is NULL'));
118
+		}
119 119
 
120
-	    $nodes->addHook('beforeInsert', function($node, & $data) {
121
-	        $data['parent'] = $this->recall('parent');
122
-	    });
120
+		$nodes->addHook('beforeInsert', function($node, & $data) {
121
+			$data['parent'] = $this->recall('parent');
122
+		});
123 123
 	        
124
-	    $nodes->getAction('edit')->enabled = function($row = null) {
125
-	        return $row ? !$row['readonly'] : true;
126
-	    };
124
+		$nodes->getAction('edit')->enabled = function($row = null) {
125
+			return $row ? !$row['readonly'] : true;
126
+		};
127 127
 	    
128
-	    return $nodes;
128
+		return $nodes;
129 129
 	}
130 130
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 	    $parent = $this->stickyGet('parent');
40 40
 	    
41 41
 	    if (isset($parent)) {
42
-	        $this->memorize('parent', $parent?: null);
42
+	        $this->memorize('parent', $parent ?: null);
43 43
 	    }
44 44
 
45 45
 	    $this->ancestors = Models\CommonData::ancestorsAndSelf($this->recall('parent'));
@@ -82,13 +82,13 @@  discard block
 block discarded – undo
82 82
 		        [$this->grid->jsRow()->data('id')]
83 83
 		));
84 84
 
85
-		$this->grid->addDragHandler()->onReorder(function ($order) {
85
+		$this->grid->addDragHandler()->onReorder(function($order) {
86 86
 			$result = true;
87 87
 			foreach ($this->nodes() as $node) {
88 88
 				$result &= $node->save(['position' => array_search($node->id, $order)]);
89 89
 			}
90 90
 			
91
-			$notifier = $result? $this->notifySuccess(__('Items reordered!')): $this->notifyError(__('Error saving order!'));
91
+			$notifier = $result ? $this->notifySuccess(__('Items reordered!')) : $this->notifyError(__('Error saving order!'));
92 92
 			
93 93
 			return $this->grid->jsSave($notifier);
94 94
 		});
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -112,8 +112,7 @@
 block discarded – undo
112 112
 	    //@TODO: remove below when adding null condition fixed
113 113
 	    if ($parent = $this->parent()) {
114 114
 	        $nodes->addCondition('parent', $parent);
115
-	    }
116
-	    else {
115
+	    } else {
117 116
 	        $nodes->addCondition($nodes->expr('parent is NULL'));
118 117
 	    }
119 118
 
Please login to merge, or discard this patch.
src/CommonData/CommonDataCore.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@
 block discarded – undo
26 26
 	
27 27
 	public function install()
28 28
 	{
29
-	    Models\CommonData::migrate();
29
+		Models\CommonData::migrate();
30 30
 	}
31 31
 	
32 32
 	public function uninstall()
Please login to merge, or discard this patch.
src/CommonData/Models/CommonData.php 3 patches
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -9,259 +9,259 @@
 block discarded – undo
9 9
 class CommonDataNotFound extends \Exception {}
10 10
 
11 11
 class CommonData extends Model {
12
-    use HasEpesiConnection;
12
+	use HasEpesiConnection;
13 13
     
14
-    public $table = 'commondata';
14
+	public $table = 'commondata';
15 15
     
16
-    public $caption = 'Common Data';
16
+	public $caption = 'Common Data';
17 17
     
18
-    public $title_field = 'value';
18
+	public $title_field = 'value';
19 19
     
20
-    protected static $cache = [
21
-    		'id' => [],
22
-    		'value' => [],
23
-    		'array' => []
24
-    ];
20
+	protected static $cache = [
21
+			'id' => [],
22
+			'value' => [],
23
+			'array' => []
24
+	];
25 25
     
26
-    function init() {
27
-        parent::init();
26
+	function init() {
27
+		parent::init();
28 28
         
29
-        $this->addFields([
30
-                'key' => ['caption' => __('Key')],
31
-                'value' => ['caption' => __('Value')],
32
-                'position' => ['type' => 'integer', 'caption' => __('Position')],
33
-                'readonly' => ['type' => 'boolean']
34
-        ]);
29
+		$this->addFields([
30
+				'key' => ['caption' => __('Key')],
31
+				'value' => ['caption' => __('Value')],
32
+				'position' => ['type' => 'integer', 'caption' => __('Position')],
33
+				'readonly' => ['type' => 'boolean']
34
+		]);
35 35
         
36
-        $this->hasOne('parent', [self::class, 'our_field' => 'parent']);
36
+		$this->hasOne('parent', [self::class, 'our_field' => 'parent']);
37 37
         
38
-        $this->getAction('edit')->ui['execButton'] = ['Button', __('Save'), 'class' => ['primary']];
38
+		$this->getAction('edit')->ui['execButton'] = ['Button', __('Save'), 'class' => ['primary']];
39 39
         
40
-        $this->addHook('beforeInsert', function($node, & $data) {
41
-            $data['position'] = $node->action('fx', ['max', 'position'])->getOne() + 1;
40
+		$this->addHook('beforeInsert', function($node, & $data) {
41
+			$data['position'] = $node->action('fx', ['max', 'position'])->getOne() + 1;
42 42
             
43
-            $data['readonly'] = $data['readonly'] ?? 0;
44
-        });
45
-    }
43
+			$data['readonly'] = $data['readonly'] ?? 0;
44
+		});
45
+	}
46 46
     
47
-    public static function getId($path, $clearCache = false)
48
-    {
49
-    	$id = null;
50
-    	foreach(explode('/', trim($path,'/')) as $nodeKey) {
51
-    	    $parentId = $id;
47
+	public static function getId($path, $clearCache = false)
48
+	{
49
+		$id = null;
50
+		foreach(explode('/', trim($path,'/')) as $nodeKey) {
51
+			$parentId = $id;
52 52
     	    
53
-    		if ($nodeKey === '') continue; //ignore empty paths
53
+			if ($nodeKey === '') continue; //ignore empty paths
54 54
     		
55
-    		if ($clearCache || empty(self::$cache['id'][$parentId][$nodeKey])) {
56
-    		    $node = self::siblings($parentId)->addCondition('key', $nodeKey)->tryLoadAny();
55
+			if ($clearCache || empty(self::$cache['id'][$parentId][$nodeKey])) {
56
+				$node = self::siblings($parentId)->addCondition('key', $nodeKey)->tryLoadAny();
57 57
     		    
58
-    			if (! $node->loaded()) return false;
58
+				if (! $node->loaded()) return false;
59 59
 
60
-    			self::$cache['id'][$parentId][$nodeKey] = $node->id;
61
-    		}
60
+				self::$cache['id'][$parentId][$nodeKey] = $node->id;
61
+			}
62 62
     		
63
-    		$id = self::$cache['id'][$parentId][$nodeKey];
64
-    	}
63
+			$id = self::$cache['id'][$parentId][$nodeKey];
64
+		}
65 65
     	
66
-    	return $id;
67
-    }
66
+		return $id;
67
+	}
68 68
    
69
-    public static function newId($path, $readonly = false)
70
-    {
71
-    	if (! $path = trim($path,'/')) return false;
69
+	public static function newId($path, $readonly = false)
70
+	{
71
+		if (! $path = trim($path,'/')) return false;
72 72
 
73
-    	$id = null;
74
-    	foreach(explode('/', $path) as $nodeKey) {
75
-    		if ($nodeKey === '') continue;
73
+		$id = null;
74
+		foreach(explode('/', $path) as $nodeKey) {
75
+			if ($nodeKey === '') continue;
76 76
     		
77
-    		$parentId = $id;
77
+			$parentId = $id;
78 78
     		
79
-    		$node = self::siblings($parentId)->addCondition('key', $nodeKey)->tryLoadAny();
79
+			$node = self::siblings($parentId)->addCondition('key', $nodeKey)->tryLoadAny();
80 80
 
81
-    		if ($node->loaded()) {
82
-    		    $id = $node->id;
83
-    		}
84
-    		else {
85
-    		    $id = $node->insert([
86
-    		            'parent' => $parentId,
87
-    		            'key' => $nodeKey,
88
-    		            'readonly' => $readonly
89
-    		    ]);
90
-    		}
91
-    	}
81
+			if ($node->loaded()) {
82
+				$id = $node->id;
83
+			}
84
+			else {
85
+				$id = $node->insert([
86
+						'parent' => $parentId,
87
+						'key' => $nodeKey,
88
+						'readonly' => $readonly
89
+				]);
90
+			}
91
+		}
92 92
     	
93
-    	return $id;
94
-    }
93
+		return $id;
94
+	}
95 95
     
96
-    public static function setValue($path, $value, $overwrite = true, $readonly = false)
97
-    {
98
-    	if (! $id = self::getId($path)) {
99
-    		if (! $id = self::newId($path, $readonly)) return false;
100
-    	} else {
101
-    		if (! $overwrite) return false;
102
-    	}
96
+	public static function setValue($path, $value, $overwrite = true, $readonly = false)
97
+	{
98
+		if (! $id = self::getId($path)) {
99
+			if (! $id = self::newId($path, $readonly)) return false;
100
+		} else {
101
+			if (! $overwrite) return false;
102
+		}
103 103
 
104
-    	self::create()->tryLoad($id)->save(compact('value', 'readonly'));
104
+		self::create()->tryLoad($id)->save(compact('value', 'readonly'));
105 105
     	
106
-    	self::clearCache();
106
+		self::clearCache();
107 107
     	
108
-    	return true;
109
-    }
108
+		return true;
109
+	}
110 110
     
111
-    public static function clearCache()
112
-    {
113
-    	self::$cache = array_fill_keys(array_keys(self::$cache), []);
114
-    }
111
+	public static function clearCache()
112
+	{
113
+		self::$cache = array_fill_keys(array_keys(self::$cache), []);
114
+	}
115 115
     
116
-    public static function getValue($path, $translate = false)
117
-    {
118
-    	$key = md5(serialize($path));
116
+	public static function getValue($path, $translate = false)
117
+	{
118
+		$key = md5(serialize($path));
119 119
     	
120
-    	if (! isset(self::$cache['value'][$key])) {
121
-    		if(! $id = self::getId($path)) return false;
120
+		if (! isset(self::$cache['value'][$key])) {
121
+			if(! $id = self::getId($path)) return false;
122 122
 
123
-    		self::$cache['value'][$key] = self::create()->tryLoad($id)->get('value');
124
-	    }
123
+			self::$cache['value'][$key] = self::create()->tryLoad($id)->get('value');
124
+		}
125 125
 	    
126
-	    return $translate? __(self::$cache['value'][$key]): self::$cache['value'][$key];
127
-    }
126
+		return $translate? __(self::$cache['value'][$key]): self::$cache['value'][$key];
127
+	}
128 128
         
129
-    /**
130
-     * Creates new array for common use.
131
-     *
132
-     * @param $path string
133
-     * @param $array array initialization value
134
-     * @param $overwrite bool whether method should overwrite if array already exists, otherwise the data will be appended
135
-     * @param $readonly bool do not allow user to change this array from GUI
136
-     */
137
-    public static function newArray($path, $array, $overwrite = false, $readonly = false)
138
-    {
139
-    	self::validateArrayKeys($array);
129
+	/**
130
+	 * Creates new array for common use.
131
+	 *
132
+	 * @param $path string
133
+	 * @param $array array initialization value
134
+	 * @param $overwrite bool whether method should overwrite if array already exists, otherwise the data will be appended
135
+	 * @param $readonly bool do not allow user to change this array from GUI
136
+	 */
137
+	public static function newArray($path, $array, $overwrite = false, $readonly = false)
138
+	{
139
+		self::validateArrayKeys($array);
140 140
     		
141
-    	$path = trim($path, '/');
141
+		$path = trim($path, '/');
142 142
     	
143 143
 		if ($id = self::getId($path)) {
144
-    		if (! $overwrite) {
145
-    			self::extendArray($path, $array);
146
-    			return true;
147
-    		}
144
+			if (! $overwrite) {
145
+				self::extendArray($path, $array);
146
+				return true;
147
+			}
148 148
     				
149
-    		self::create()->delete($id);
150
-    	}
149
+			self::create()->delete($id);
150
+		}
151 151
     			
152
-    	if(! $id = self::newId($path, $readonly)) return false;
152
+		if(! $id = self::newId($path, $readonly)) return false;
153 153
     			
154
-    	if ($overwrite) {
155
-    	    self::create()->tryLoad($id)->save(compact('readonly'));
156
-    	}
154
+		if ($overwrite) {
155
+			self::create()->tryLoad($id)->save(compact('readonly'));
156
+		}
157 157
     			
158
-    	foreach ($array as $key => $value) {
159
-    		self::setValue($path . '/' . $key, $value, true, $readonly);
160
-    	}
158
+		foreach ($array as $key => $value) {
159
+			self::setValue($path . '/' . $key, $value, true, $readonly);
160
+		}
161 161
     			
162
-    	return true;
163
-    }
162
+		return true;
163
+	}
164 164
 
165
-    /**
166
-     * Extends common data array.
167
-     *
168
-     * @param $path string
169
-     * @param $array array values to insert
170
-     * @param $overwrite bool whether method should overwrite data if array key already exists, otherwise the data will be preserved
171
-     */
172
-    public static function extendArray($path, $array, $overwrite=false, $readonly=false)
173
-    {
174
-    	self::validateArrayKeys($array);
165
+	/**
166
+	 * Extends common data array.
167
+	 *
168
+	 * @param $path string
169
+	 * @param $array array values to insert
170
+	 * @param $overwrite bool whether method should overwrite data if array key already exists, otherwise the data will be preserved
171
+	 */
172
+	public static function extendArray($path, $array, $overwrite=false, $readonly=false)
173
+	{
174
+		self::validateArrayKeys($array);
175 175
     	
176
-    	$path = trim($path, '/');
176
+		$path = trim($path, '/');
177 177
     			
178
-    	if (! self::getId($path)){
179
-    		return self::newArray($path, $array, $overwrite, $readonly);
180
-    	}
178
+		if (! self::getId($path)){
179
+			return self::newArray($path, $array, $overwrite, $readonly);
180
+		}
181 181
 
182
-    	foreach ($array as $key => $value) {
183
-    		self::setValue($path . '/' . $key, $value, $overwrite, $readonly);
184
-    	}
185
-    }
182
+		foreach ($array as $key => $value) {
183
+			self::setValue($path . '/' . $key, $value, $overwrite, $readonly);
184
+		}
185
+	}
186 186
         
187
-    /**
188
-     * Returns common data array.
189
-     *
190
-     * @param string array name
191
-     * @return mixed returns an array if such array exists, false otherwise
192
-     */
193
-    public static function getArray($path, $sortColumn = 'position', $silent = false)
194
-    {
195
-    	return self::getCollection($path, $silent)->sortBy($sortColumn)->pluck('value', 'key')->all();
196
-    }
187
+	/**
188
+	 * Returns common data array.
189
+	 *
190
+	 * @param string array name
191
+	 * @return mixed returns an array if such array exists, false otherwise
192
+	 */
193
+	public static function getArray($path, $sortColumn = 'position', $silent = false)
194
+	{
195
+		return self::getCollection($path, $silent)->sortBy($sortColumn)->pluck('value', 'key')->all();
196
+	}
197 197
 
198
-    /**
199
-     * Removes common data array or entry.
200
-     *
201
-     * @param $path string
202
-     * @return true on success, false otherwise
203
-     */
204
-    public static function deleteArray($path){
205
-    	if (! $id = self::getId($path, true)) return false;
198
+	/**
199
+	 * Removes common data array or entry.
200
+	 *
201
+	 * @param $path string
202
+	 * @return true on success, false otherwise
203
+	 */
204
+	public static function deleteArray($path){
205
+		if (! $id = self::getId($path, true)) return false;
206 206
     	
207
-    	self::create()->delete($id);
207
+		self::create()->delete($id);
208 208
     	
209
-    	self::clearCache();
210
-    }
209
+		self::clearCache();
210
+	}
211 211
     
212
-    public static function siblings($parent = null)
213
-    {
214
-        $parentId = is_numeric($parent)? $parent: self::getId($parent);
212
+	public static function siblings($parent = null)
213
+	{
214
+		$parentId = is_numeric($parent)? $parent: self::getId($parent);
215 215
 
216
-        $model = self::create();
216
+		$model = self::create();
217 217
         
218
-        //@TODO: remove below when adding null condition fixed
219
-        return $parentId? $model->addCondition('parent', $parentId): $model->addCondition($model->expr('parent is NULL'));
220
-    }
218
+		//@TODO: remove below when adding null condition fixed
219
+		return $parentId? $model->addCondition('parent', $parentId): $model->addCondition($model->expr('parent is NULL'));
220
+	}
221 221
         
222
-    public static function ancestors($node)
223
-    {
224
-        $node = is_numeric($node)? self::create()->tryLoad($node): $node;
222
+	public static function ancestors($node)
223
+	{
224
+		$node = is_numeric($node)? self::create()->tryLoad($node): $node;
225 225
 
226
-        if (! $node['parent']) return [];
226
+		if (! $node['parent']) return [];
227 227
         
228
-        return array_filter(array_merge([$node['parent']], self::ancestors($node['parent'])));
229
-    }
228
+		return array_filter(array_merge([$node['parent']], self::ancestors($node['parent'])));
229
+	}
230 230
     
231
-    public static function ancestorsAndSelf($node)
232
-    {
233
-        $node = is_numeric($node)? self::create()->tryLoad($node): $node;
231
+	public static function ancestorsAndSelf($node)
232
+	{
233
+		$node = is_numeric($node)? self::create()->tryLoad($node): $node;
234 234
         
235
-        return array_filter(array_merge([$node['id']], self::ancestors($node)));
236
-    }
235
+		return array_filter(array_merge([$node['id']], self::ancestors($node)));
236
+	}
237 237
     
238
-    /**
239
-     * Returns common data collection.
240
-     *
241
-     * @param $path string
242
-     * @return Collection
243
-     */
244
-    public static function getCollection($path, $silent = false)
245
-    {
246
-    	if(isset(self::$cache['array'][$path])) {
247
-    		return self::$cache['array'][$path];
248
-    	}
238
+	/**
239
+	 * Returns common data collection.
240
+	 *
241
+	 * @param $path string
242
+	 * @return Collection
243
+	 */
244
+	public static function getCollection($path, $silent = false)
245
+	{
246
+		if(isset(self::$cache['array'][$path])) {
247
+			return self::$cache['array'][$path];
248
+		}
249 249
     	
250
-    	if (! $id = self::getId($path)) {
251
-    		if ($silent) return collect();
250
+		if (! $id = self::getId($path)) {
251
+			if ($silent) return collect();
252 252
     		
253
-    		throw new CommonDataNotFound('Invalid CommonData::getArray() request: ' . $path);
254
-    	}
253
+			throw new CommonDataNotFound('Invalid CommonData::getArray() request: ' . $path);
254
+		}
255 255
     	
256
-    	return self::$cache['array'][$path] = collect(self::siblings($id)->export());
257
-    }
256
+		return self::$cache['array'][$path] = collect(self::siblings($id)->export());
257
+	}
258 258
     
259
-    protected static function validateArrayKeys($array)
260
-    {
261
-    	foreach($array as $key => $value) {
262
-    		if (strpos($key, '/') === false) continue;
259
+	protected static function validateArrayKeys($array)
260
+	{
261
+		foreach($array as $key => $value) {
262
+			if (strpos($key, '/') === false) continue;
263 263
     		
264
-    		\Exception('Invalid common data key: '. $key);
265
-    	}
266
-    }
264
+			\Exception('Invalid common data key: '. $key);
265
+		}
266
+	}
267 267
 }
268 268
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
     public static function getId($path, $clearCache = false)
48 48
     {
49 49
     	$id = null;
50
-    	foreach(explode('/', trim($path,'/')) as $nodeKey) {
50
+    	foreach (explode('/', trim($path, '/')) as $nodeKey) {
51 51
     	    $parentId = $id;
52 52
     	    
53 53
     		if ($nodeKey === '') continue; //ignore empty paths
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
     		if ($clearCache || empty(self::$cache['id'][$parentId][$nodeKey])) {
56 56
     		    $node = self::siblings($parentId)->addCondition('key', $nodeKey)->tryLoadAny();
57 57
     		    
58
-    			if (! $node->loaded()) return false;
58
+    			if (!$node->loaded()) return false;
59 59
 
60 60
     			self::$cache['id'][$parentId][$nodeKey] = $node->id;
61 61
     		}
@@ -68,10 +68,10 @@  discard block
 block discarded – undo
68 68
    
69 69
     public static function newId($path, $readonly = false)
70 70
     {
71
-    	if (! $path = trim($path,'/')) return false;
71
+    	if (!$path = trim($path, '/')) return false;
72 72
 
73 73
     	$id = null;
74
-    	foreach(explode('/', $path) as $nodeKey) {
74
+    	foreach (explode('/', $path) as $nodeKey) {
75 75
     		if ($nodeKey === '') continue;
76 76
     		
77 77
     		$parentId = $id;
@@ -95,10 +95,10 @@  discard block
 block discarded – undo
95 95
     
96 96
     public static function setValue($path, $value, $overwrite = true, $readonly = false)
97 97
     {
98
-    	if (! $id = self::getId($path)) {
99
-    		if (! $id = self::newId($path, $readonly)) return false;
98
+    	if (!$id = self::getId($path)) {
99
+    		if (!$id = self::newId($path, $readonly)) return false;
100 100
     	} else {
101
-    		if (! $overwrite) return false;
101
+    		if (!$overwrite) return false;
102 102
     	}
103 103
 
104 104
     	self::create()->tryLoad($id)->save(compact('value', 'readonly'));
@@ -117,13 +117,13 @@  discard block
 block discarded – undo
117 117
     {
118 118
     	$key = md5(serialize($path));
119 119
     	
120
-    	if (! isset(self::$cache['value'][$key])) {
121
-    		if(! $id = self::getId($path)) return false;
120
+    	if (!isset(self::$cache['value'][$key])) {
121
+    		if (!$id = self::getId($path)) return false;
122 122
 
123 123
     		self::$cache['value'][$key] = self::create()->tryLoad($id)->get('value');
124 124
 	    }
125 125
 	    
126
-	    return $translate? __(self::$cache['value'][$key]): self::$cache['value'][$key];
126
+	    return $translate ? __(self::$cache['value'][$key]) : self::$cache['value'][$key];
127 127
     }
128 128
         
129 129
     /**
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
     	$path = trim($path, '/');
142 142
     	
143 143
 		if ($id = self::getId($path)) {
144
-    		if (! $overwrite) {
144
+    		if (!$overwrite) {
145 145
     			self::extendArray($path, $array);
146 146
     			return true;
147 147
     		}
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
     		self::create()->delete($id);
150 150
     	}
151 151
     			
152
-    	if(! $id = self::newId($path, $readonly)) return false;
152
+    	if (!$id = self::newId($path, $readonly)) return false;
153 153
     			
154 154
     	if ($overwrite) {
155 155
     	    self::create()->tryLoad($id)->save(compact('readonly'));
@@ -169,13 +169,13 @@  discard block
 block discarded – undo
169 169
      * @param $array array values to insert
170 170
      * @param $overwrite bool whether method should overwrite data if array key already exists, otherwise the data will be preserved
171 171
      */
172
-    public static function extendArray($path, $array, $overwrite=false, $readonly=false)
172
+    public static function extendArray($path, $array, $overwrite = false, $readonly = false)
173 173
     {
174 174
     	self::validateArrayKeys($array);
175 175
     	
176 176
     	$path = trim($path, '/');
177 177
     			
178
-    	if (! self::getId($path)){
178
+    	if (!self::getId($path)) {
179 179
     		return self::newArray($path, $array, $overwrite, $readonly);
180 180
     	}
181 181
 
@@ -201,8 +201,8 @@  discard block
 block discarded – undo
201 201
      * @param $path string
202 202
      * @return true on success, false otherwise
203 203
      */
204
-    public static function deleteArray($path){
205
-    	if (! $id = self::getId($path, true)) return false;
204
+    public static function deleteArray($path) {
205
+    	if (!$id = self::getId($path, true)) return false;
206 206
     	
207 207
     	self::create()->delete($id);
208 208
     	
@@ -211,26 +211,26 @@  discard block
 block discarded – undo
211 211
     
212 212
     public static function siblings($parent = null)
213 213
     {
214
-        $parentId = is_numeric($parent)? $parent: self::getId($parent);
214
+        $parentId = is_numeric($parent) ? $parent : self::getId($parent);
215 215
 
216 216
         $model = self::create();
217 217
         
218 218
         //@TODO: remove below when adding null condition fixed
219
-        return $parentId? $model->addCondition('parent', $parentId): $model->addCondition($model->expr('parent is NULL'));
219
+        return $parentId ? $model->addCondition('parent', $parentId) : $model->addCondition($model->expr('parent is NULL'));
220 220
     }
221 221
         
222 222
     public static function ancestors($node)
223 223
     {
224
-        $node = is_numeric($node)? self::create()->tryLoad($node): $node;
224
+        $node = is_numeric($node) ? self::create()->tryLoad($node) : $node;
225 225
 
226
-        if (! $node['parent']) return [];
226
+        if (!$node['parent']) return [];
227 227
         
228 228
         return array_filter(array_merge([$node['parent']], self::ancestors($node['parent'])));
229 229
     }
230 230
     
231 231
     public static function ancestorsAndSelf($node)
232 232
     {
233
-        $node = is_numeric($node)? self::create()->tryLoad($node): $node;
233
+        $node = is_numeric($node) ? self::create()->tryLoad($node) : $node;
234 234
         
235 235
         return array_filter(array_merge([$node['id']], self::ancestors($node)));
236 236
     }
@@ -243,11 +243,11 @@  discard block
 block discarded – undo
243 243
      */
244 244
     public static function getCollection($path, $silent = false)
245 245
     {
246
-    	if(isset(self::$cache['array'][$path])) {
246
+    	if (isset(self::$cache['array'][$path])) {
247 247
     		return self::$cache['array'][$path];
248 248
     	}
249 249
     	
250
-    	if (! $id = self::getId($path)) {
250
+    	if (!$id = self::getId($path)) {
251 251
     		if ($silent) return collect();
252 252
     		
253 253
     		throw new CommonDataNotFound('Invalid CommonData::getArray() request: ' . $path);
@@ -258,10 +258,10 @@  discard block
 block discarded – undo
258 258
     
259 259
     protected static function validateArrayKeys($array)
260 260
     {
261
-    	foreach($array as $key => $value) {
261
+    	foreach ($array as $key => $value) {
262 262
     		if (strpos($key, '/') === false) continue;
263 263
     		
264
-    		\Exception('Invalid common data key: '. $key);
264
+    		\Exception('Invalid common data key: ' . $key);
265 265
     	}
266 266
     }
267 267
 }
268 268
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +38 added lines, -14 removed lines patch added patch discarded remove patch
@@ -50,12 +50,17 @@  discard block
 block discarded – undo
50 50
     	foreach(explode('/', trim($path,'/')) as $nodeKey) {
51 51
     	    $parentId = $id;
52 52
     	    
53
-    		if ($nodeKey === '') continue; //ignore empty paths
53
+    		if ($nodeKey === '') {
54
+    			continue;
55
+    		}
56
+    		//ignore empty paths
54 57
     		
55 58
     		if ($clearCache || empty(self::$cache['id'][$parentId][$nodeKey])) {
56 59
     		    $node = self::siblings($parentId)->addCondition('key', $nodeKey)->tryLoadAny();
57 60
     		    
58
-    			if (! $node->loaded()) return false;
61
+    			if (! $node->loaded()) {
62
+    				return false;
63
+    			}
59 64
 
60 65
     			self::$cache['id'][$parentId][$nodeKey] = $node->id;
61 66
     		}
@@ -68,11 +73,15 @@  discard block
 block discarded – undo
68 73
    
69 74
     public static function newId($path, $readonly = false)
70 75
     {
71
-    	if (! $path = trim($path,'/')) return false;
76
+    	if (! $path = trim($path,'/')) {
77
+    		return false;
78
+    	}
72 79
 
73 80
     	$id = null;
74 81
     	foreach(explode('/', $path) as $nodeKey) {
75
-    		if ($nodeKey === '') continue;
82
+    		if ($nodeKey === '') {
83
+    			continue;
84
+    		}
76 85
     		
77 86
     		$parentId = $id;
78 87
     		
@@ -80,8 +89,7 @@  discard block
 block discarded – undo
80 89
 
81 90
     		if ($node->loaded()) {
82 91
     		    $id = $node->id;
83
-    		}
84
-    		else {
92
+    		} else {
85 93
     		    $id = $node->insert([
86 94
     		            'parent' => $parentId,
87 95
     		            'key' => $nodeKey,
@@ -96,9 +104,13 @@  discard block
 block discarded – undo
96 104
     public static function setValue($path, $value, $overwrite = true, $readonly = false)
97 105
     {
98 106
     	if (! $id = self::getId($path)) {
99
-    		if (! $id = self::newId($path, $readonly)) return false;
107
+    		if (! $id = self::newId($path, $readonly)) {
108
+    			return false;
109
+    		}
100 110
     	} else {
101
-    		if (! $overwrite) return false;
111
+    		if (! $overwrite) {
112
+    			return false;
113
+    		}
102 114
     	}
103 115
 
104 116
     	self::create()->tryLoad($id)->save(compact('value', 'readonly'));
@@ -118,7 +130,9 @@  discard block
 block discarded – undo
118 130
     	$key = md5(serialize($path));
119 131
     	
120 132
     	if (! isset(self::$cache['value'][$key])) {
121
-    		if(! $id = self::getId($path)) return false;
133
+    		if(! $id = self::getId($path)) {
134
+    			return false;
135
+    		}
122 136
 
123 137
     		self::$cache['value'][$key] = self::create()->tryLoad($id)->get('value');
124 138
 	    }
@@ -149,7 +163,9 @@  discard block
 block discarded – undo
149 163
     		self::create()->delete($id);
150 164
     	}
151 165
     			
152
-    	if(! $id = self::newId($path, $readonly)) return false;
166
+    	if(! $id = self::newId($path, $readonly)) {
167
+    		return false;
168
+    	}
153 169
     			
154 170
     	if ($overwrite) {
155 171
     	    self::create()->tryLoad($id)->save(compact('readonly'));
@@ -202,7 +218,9 @@  discard block
 block discarded – undo
202 218
      * @return true on success, false otherwise
203 219
      */
204 220
     public static function deleteArray($path){
205
-    	if (! $id = self::getId($path, true)) return false;
221
+    	if (! $id = self::getId($path, true)) {
222
+    		return false;
223
+    	}
206 224
     	
207 225
     	self::create()->delete($id);
208 226
     	
@@ -223,7 +241,9 @@  discard block
 block discarded – undo
223 241
     {
224 242
         $node = is_numeric($node)? self::create()->tryLoad($node): $node;
225 243
 
226
-        if (! $node['parent']) return [];
244
+        if (! $node['parent']) {
245
+        	return [];
246
+        }
227 247
         
228 248
         return array_filter(array_merge([$node['parent']], self::ancestors($node['parent'])));
229 249
     }
@@ -248,7 +268,9 @@  discard block
 block discarded – undo
248 268
     	}
249 269
     	
250 270
     	if (! $id = self::getId($path)) {
251
-    		if ($silent) return collect();
271
+    		if ($silent) {
272
+    			return collect();
273
+    		}
252 274
     		
253 275
     		throw new CommonDataNotFound('Invalid CommonData::getArray() request: ' . $path);
254 276
     	}
@@ -259,7 +281,9 @@  discard block
 block discarded – undo
259 281
     protected static function validateArrayKeys($array)
260 282
     {
261 283
     	foreach($array as $key => $value) {
262
-    		if (strpos($key, '/') === false) continue;
284
+    		if (strpos($key, '/') === false) {
285
+    			continue;
286
+    		}
263 287
     		
264 288
     		\Exception('Invalid common data key: '. $key);
265 289
     	}
Please login to merge, or discard this patch.
src/CommonData/Fields/CommonData.php 3 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
 	public $path = '';
18 18
 
19 19
 	public $serialize = [
20
-	        [__CLASS__, 'serialize'],
21
-	        [__CLASS__, 'unserialize'],
20
+			[__CLASS__, 'serialize'],
21
+			[__CLASS__, 'unserialize'],
22 22
 	];
23 23
 	
24 24
 	public $multiple = false;
@@ -33,75 +33,75 @@  discard block
 block discarded – undo
33 33
 		$this->_init();
34 34
 		
35 35
 		if ($this->getDependency()) {
36
-		    $this->ui['form'] = [
37
-		            'AutoComplete', 
38
-		            'model' => CommonDataModel::create(),
39
-		            'dependency' => function($model, $data) {
40
-		                $model->addCondition('parent', CommonDataModel::getId($this->getDependencyPath($data)));
41
-        		    },
42
-        		    'renderRowFunction' => function($field, $row) {
43
-        		        return [
44
-        		          'value' => $row['key'],
45
-        		          'title' => $row['value'] ?: $row['key'],
46
-        		        ];
47
-        		     },
48
-        		     'multiple' => $this->multiple
49
-		    ];
36
+			$this->ui['form'] = [
37
+					'AutoComplete', 
38
+					'model' => CommonDataModel::create(),
39
+					'dependency' => function($model, $data) {
40
+						$model->addCondition('parent', CommonDataModel::getId($this->getDependencyPath($data)));
41
+					},
42
+					'renderRowFunction' => function($field, $row) {
43
+						return [
44
+						  'value' => $row['key'],
45
+						  'title' => $row['value'] ?: $row['key'],
46
+						];
47
+					 },
48
+					 'multiple' => $this->multiple
49
+			];
50 50
 		} else {
51
-		    $this->values = CommonDataModel::getArray($this->path);
51
+			$this->values = CommonDataModel::getArray($this->path);
52 52
 		}
53 53
 
54 54
 		$this->ui = array_merge([
55
-		        'table' => ['Multiformat', [$this, 'format']],
56
-		        'form' => ['isMultiple' => $this->multiple]
55
+				'table' => ['Multiformat', [$this, 'format']],
56
+				'form' => ['isMultiple' => $this->multiple]
57 57
 		], $this->ui);
58 58
 	}
59 59
 	
60 60
 	public function getDependency()
61 61
 	{
62
-	    $fields = (array) $this->path;
62
+		$fields = (array) $this->path;
63 63
 	    
64
-	    $path = array_shift($fields);
64
+		$path = array_shift($fields);
65 65
 	    
66
-	    return $fields? compact('path', 'fields'): false;
66
+		return $fields? compact('path', 'fields'): false;
67 67
 	}
68 68
 	
69 69
 	public function getDependencyPath($data)
70 70
 	{
71
-	    if (! $dependency = $this->getDependency()) return false;
71
+		if (! $dependency = $this->getDependency()) return false;
72 72
 	    
73
-	    return implode('/', array_merge([$dependency['path']], array_intersect_key($data, array_flip($dependency['fields']))));
73
+		return implode('/', array_merge([$dependency['path']], array_intersect_key($data, array_flip($dependency['fields']))));
74 74
 	}
75 75
 	
76 76
 	public function getValues($data)
77 77
 	{
78
-	    $path = $this->getDependencyPath($data) ?: $this->path;
78
+		$path = $this->getDependencyPath($data) ?: $this->path;
79 79
 	    
80
-	    return CommonDataModel::getArray($path);
80
+		return CommonDataModel::getArray($path);
81 81
 	}
82 82
 	
83 83
 	public static function serialize($field, $value, $persistence)
84 84
 	{
85
-	    return $field->multiple? implode(',', (array) $value): $value;
85
+		return $field->multiple? implode(',', (array) $value): $value;
86 86
 	}
87 87
 	
88 88
 	public static function unserialize($field, $value, $persistence)
89 89
 	{
90
-	    return $field->multiple? explode(',', $value): $value;
90
+		return $field->multiple? explode(',', $value): $value;
91 91
 	}
92 92
 
93 93
 	public function format($row, $field)
94 94
 	{	
95
-	    $values = array_intersect_key($this->getValues($row->get()), array_flip((array) $row[$field]));
95
+		$values = array_intersect_key($this->getValues($row->get()), array_flip((array) $row[$field]));
96 96
 	    
97
-	    return [[
98
-	            'Template',
99
-	            implode('<br>', $values),
100
-	    ]];
97
+		return [[
98
+				'Template',
99
+				implode('<br>', $values),
100
+		]];
101 101
 	}
102 102
 	
103 103
 	public function normalize($value)
104 104
 	{
105
-	    return $this->multiple? parent::normalize($value): $value;
105
+		return $this->multiple? parent::normalize($value): $value;
106 106
 	}
107 107
 }
108 108
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -63,12 +63,12 @@  discard block
 block discarded – undo
63 63
 	    
64 64
 	    $path = array_shift($fields);
65 65
 	    
66
-	    return $fields? compact('path', 'fields'): false;
66
+	    return $fields ? compact('path', 'fields') : false;
67 67
 	}
68 68
 	
69 69
 	public function getDependencyPath($data)
70 70
 	{
71
-	    if (! $dependency = $this->getDependency()) return false;
71
+	    if (!$dependency = $this->getDependency()) return false;
72 72
 	    
73 73
 	    return implode('/', array_merge([$dependency['path']], array_intersect_key($data, array_flip($dependency['fields']))));
74 74
 	}
@@ -82,12 +82,12 @@  discard block
 block discarded – undo
82 82
 	
83 83
 	public static function serialize($field, $value, $persistence)
84 84
 	{
85
-	    return $field->multiple? implode(',', (array) $value): $value;
85
+	    return $field->multiple ? implode(',', (array) $value) : $value;
86 86
 	}
87 87
 	
88 88
 	public static function unserialize($field, $value, $persistence)
89 89
 	{
90
-	    return $field->multiple? explode(',', $value): $value;
90
+	    return $field->multiple ? explode(',', $value) : $value;
91 91
 	}
92 92
 
93 93
 	public function format($row, $field)
@@ -102,6 +102,6 @@  discard block
 block discarded – undo
102 102
 	
103 103
 	public function normalize($value)
104 104
 	{
105
-	    return $this->multiple? parent::normalize($value): $value;
105
+	    return $this->multiple ? parent::normalize($value) : $value;
106 106
 	}
107 107
 }
108 108
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -68,7 +68,9 @@
 block discarded – undo
68 68
 	
69 69
 	public function getDependencyPath($data)
70 70
 	{
71
-	    if (! $dependency = $this->getDependency()) return false;
71
+	    if (! $dependency = $this->getDependency()) {
72
+	    	return false;
73
+	    }
72 74
 	    
73 75
 	    return implode('/', array_merge([$dependency['path']], array_intersect_key($data, array_flip($dependency['fields']))));
74 76
 	}
Please login to merge, or discard this patch.
src/Dashboard/Models/DashboardApplet.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -7,21 +7,21 @@
 block discarded – undo
7 7
 
8 8
 class DashboardApplet extends Model
9 9
 {
10
-    use HasEpesiConnection;
10
+	use HasEpesiConnection;
11 11
     
12
-    public $table = 'dashboard_applets';
12
+	public $table = 'dashboard_applets';
13 13
     
14
-    public function init()
15
-    {
16
-        parent::init();
14
+	public function init()
15
+	{
16
+		parent::init();
17 17
         
18
-        $this->addFields([
19
-                'class' => ['type' => 'string'],
20
-                'column' => ['type' => 'integer', 'default' => 1],
21
-                'row' => ['type' => 'integer', 'default' => 0],
22
-                'options' => ['type' => 'array', 'default' => []]
23
-        ]);
18
+		$this->addFields([
19
+				'class' => ['type' => 'string'],
20
+				'column' => ['type' => 'integer', 'default' => 1],
21
+				'row' => ['type' => 'integer', 'default' => 0],
22
+				'options' => ['type' => 'array', 'default' => []]
23
+		]);
24 24
         
25
-        $this->hasOne('dashboard', [Dashboard::class, 'our_field' => 'dashboard_id']);
26
-    }
25
+		$this->hasOne('dashboard', [Dashboard::class, 'our_field' => 'dashboard_id']);
26
+	}
27 27
 }
Please login to merge, or discard this patch.
src/Dashboard/Models/Dashboard.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -8,25 +8,25 @@
 block discarded – undo
8 8
 
9 9
 class Dashboard extends Model
10 10
 {
11
-    use HasEpesiConnection;
11
+	use HasEpesiConnection;
12 12
     
13
-    public $table = 'dashboards';
13
+	public $table = 'dashboards';
14 14
     
15
-    public function init()
16
-    {
17
-        parent::init();
15
+	public function init()
16
+	{
17
+		parent::init();
18 18
         
19
-        $this->addFields([
20
-                'name' => ['type' => 'string'],
21
-                'position' => ['type' => 'integer', 'default' => 0]
22
-        ]);
19
+		$this->addFields([
20
+				'name' => ['type' => 'string'],
21
+				'position' => ['type' => 'integer', 'default' => 0]
22
+		]);
23 23
         
24
-        $this->hasOne('user', [User::class, 'our_field' => 'user_id']);
24
+		$this->hasOne('user', [User::class, 'our_field' => 'user_id']);
25 25
         
26
-        $this->hasMany('applets', [DashboardApplet::class, 'their_field' => 'dashboard_id']);
26
+		$this->hasMany('applets', [DashboardApplet::class, 'their_field' => 'dashboard_id']);
27 27
         
28
-        $this->addHook('beforeDelete', function($id) {
29
-            $this->withID($id)->ref('applets')->action('delete')->execute();
30
-        });
31
-    }
28
+		$this->addHook('beforeDelete', function($id) {
29
+			$this->withID($id)->ref('applets')->action('delete')->execute();
30
+		});
31
+	}
32 32
 }
Please login to merge, or discard this patch.
src/Dashboard/DashboardCore.php 3 patches
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -18,23 +18,23 @@  discard block
 block discarded – undo
18 18
 	
19 19
 	public function install()
20 20
 	{
21
-	    Models\Dashboard::migrate();
22
-	    Models\DashboardApplet::migrate();
21
+		Models\Dashboard::migrate();
22
+		Models\DashboardApplet::migrate();
23 23
 		
24 24
 		// setup default dashboard
25
-	    $dashboardId = (int) Models\Dashboard::create()->insert([
25
+		$dashboardId = (int) Models\Dashboard::create()->insert([
26 26
 				'user_id' => 0,
27 27
 				'name' => __('Admin Default')
28 28
 		]);
29 29
 		
30
-	    Models\DashboardApplet::create()->insert([
31
-	            [
32
-	                    'dashboard_id' => $dashboardId,
33
-	                    'class' => 'Epesi\\Applets\\Clock\\ClockApplet',
34
-	                    'row' => 0,
35
-	                    'column' => 3,
36
-	            ]
37
-	    ]);
30
+		Models\DashboardApplet::create()->insert([
31
+				[
32
+						'dashboard_id' => $dashboardId,
33
+						'class' => 'Epesi\\Applets\\Clock\\ClockApplet',
34
+						'row' => 0,
35
+						'column' => 3,
36
+				]
37
+		]);
38 38
 	}
39 39
 	
40 40
 	public static function info()
@@ -51,14 +51,14 @@  discard block
 block discarded – undo
51 51
 	{
52 52
 		// create user default dashboard as copy of the system default
53 53
 		User::created(function(User $user) {
54
-		    if (! $defaultDashboard = Models\Dashboard::create()->addCondition('user_id', 0)->tryLoadAny()) return;
54
+			if (! $defaultDashboard = Models\Dashboard::create()->addCondition('user_id', 0)->tryLoadAny()) return;
55 55
 			$userDefaultDashboard = (clone $defaultDashboard)->duplicate()->save([
56
-			        'name' => __('Default'),
57
-			        'user_id' => $user->id
56
+					'name' => __('Default'),
57
+					'user_id' => $user->id
58 58
 			]);
59 59
 
60 60
 			foreach ($defaultDashboard->ref('applets') as $defaultApplet) {
61
-			    $defaultApplet->duplicate()->saveAndUnload(['dashboard_id' => $userDefaultDashboard->id]);
61
+				$defaultApplet->duplicate()->saveAndUnload(['dashboard_id' => $userDefaultDashboard->id]);
62 62
 			}
63 63
 		});
64 64
 	}
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@
 block discarded – undo
51 51
 	{
52 52
 		// create user default dashboard as copy of the system default
53 53
 		User::created(function(User $user) {
54
-		    if (! $defaultDashboard = Models\Dashboard::create()->addCondition('user_id', 0)->tryLoadAny()) return;
54
+		    if (!$defaultDashboard = Models\Dashboard::create()->addCondition('user_id', 0)->tryLoadAny()) return;
55 55
 			$userDefaultDashboard = (clone $defaultDashboard)->duplicate()->save([
56 56
 			        'name' => __('Default'),
57 57
 			        'user_id' => $user->id
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -51,7 +51,9 @@
 block discarded – undo
51 51
 	{
52 52
 		// create user default dashboard as copy of the system default
53 53
 		User::created(function(User $user) {
54
-		    if (! $defaultDashboard = Models\Dashboard::create()->addCondition('user_id', 0)->tryLoadAny()) return;
54
+		    if (! $defaultDashboard = Models\Dashboard::create()->addCondition('user_id', 0)->tryLoadAny()) {
55
+		    	return;
56
+		    }
55 57
 			$userDefaultDashboard = (clone $defaultDashboard)->duplicate()->save([
56 58
 			        'name' => __('Default'),
57 59
 			        'user_id' => $user->id
Please login to merge, or discard this patch.