@@ -25,7 +25,10 @@ discard block |
||
| 25 | 25 | { |
| 26 | 26 | $parentId = null; |
| 27 | 27 | foreach(explode('/', trim($path,'/')) as $nodeKey) { |
| 28 | - if ($nodeKey === '') continue; //ignore empty paths |
|
| 28 | + if ($nodeKey === '') { |
|
| 29 | + continue; |
|
| 30 | + } |
|
| 31 | + //ignore empty paths |
|
| 29 | 32 | |
| 30 | 33 | if ($clearCache || empty(self::$cache['id'][$parentId][$nodeKey])) { |
| 31 | 34 | if (! $node = self::where('parent_id', $parentId)->where('key', $nodeKey)->first()) { |
@@ -43,11 +46,15 @@ discard block |
||
| 43 | 46 | |
| 44 | 47 | public static function newId($path, $readonly = false) |
| 45 | 48 | { |
| 46 | - if (! $path = trim($path,'/')) return false; |
|
| 49 | + if (! $path = trim($path,'/')) { |
|
| 50 | + return false; |
|
| 51 | + } |
|
| 47 | 52 | |
| 48 | 53 | $id = $parentId = null; |
| 49 | 54 | foreach(explode('/', $path) as $nodeKey) { |
| 50 | - if ($nodeKey === '') continue; |
|
| 55 | + if ($nodeKey === '') { |
|
| 56 | + continue; |
|
| 57 | + } |
|
| 51 | 58 | |
| 52 | 59 | if (! $node = self::where('parent_id', $parentId)->where('key', $nodeKey)->first()) { |
| 53 | 60 | $node = self::create([ |
@@ -67,9 +74,13 @@ discard block |
||
| 67 | 74 | public static function setValue($path, $value, $overwrite = true, $readonly = false) |
| 68 | 75 | { |
| 69 | 76 | if (! $id = self::getId($path)) { |
| 70 | - if (! $id = self::newId($path, $readonly)) return false; |
|
| 77 | + if (! $id = self::newId($path, $readonly)) { |
|
| 78 | + return false; |
|
| 79 | + } |
|
| 71 | 80 | } else { |
| 72 | - if (! $overwrite) return false; |
|
| 81 | + if (! $overwrite) { |
|
| 82 | + return false; |
|
| 83 | + } |
|
| 73 | 84 | } |
| 74 | 85 | |
| 75 | 86 | self::findOrFail($id)->update(compact('value', 'readonly')); |
@@ -89,7 +100,9 @@ discard block |
||
| 89 | 100 | $key = md5(serialize($path)); |
| 90 | 101 | |
| 91 | 102 | if (! isset(self::$cache['value'][$key])) { |
| 92 | - if(! $id = self::getId($path)) return false; |
|
| 103 | + if(! $id = self::getId($path)) { |
|
| 104 | + return false; |
|
| 105 | + } |
|
| 93 | 106 | |
| 94 | 107 | self::$cache['value'][$key] = self::find($id)->value; |
| 95 | 108 | } |
@@ -120,7 +133,9 @@ discard block |
||
| 120 | 133 | self::find($id)->delete(); |
| 121 | 134 | } |
| 122 | 135 | |
| 123 | - if(! $id = self::newId($path, $readonly)) return false; |
|
| 136 | + if(! $id = self::newId($path, $readonly)) { |
|
| 137 | + return false; |
|
| 138 | + } |
|
| 124 | 139 | |
| 125 | 140 | if ($overwrite) { |
| 126 | 141 | self::find($id)->update(compact('readonly')); |
@@ -173,7 +188,9 @@ discard block |
||
| 173 | 188 | * @return true on success, false otherwise |
| 174 | 189 | */ |
| 175 | 190 | public static function deleteArray($path){ |
| 176 | - if (! $id = self::getId($path, true)) return false; |
|
| 191 | + if (! $id = self::getId($path, true)) { |
|
| 192 | + return false; |
|
| 193 | + } |
|
| 177 | 194 | |
| 178 | 195 | self::find($id)->delete(); |
| 179 | 196 | |
@@ -193,7 +210,9 @@ discard block |
||
| 193 | 210 | } |
| 194 | 211 | |
| 195 | 212 | if (! $id = self::getId($path)) { |
| 196 | - if ($silent) return collect(); |
|
| 213 | + if ($silent) { |
|
| 214 | + return collect(); |
|
| 215 | + } |
|
| 197 | 216 | |
| 198 | 217 | throw new CommonDataNotFound('Invalid CommonData::getArray() request: ' . $path); |
| 199 | 218 | } |
@@ -204,7 +223,9 @@ discard block |
||
| 204 | 223 | protected static function validateArrayKeys($array) |
| 205 | 224 | { |
| 206 | 225 | foreach($array as $key => $value) { |
| 207 | - if (strpos($key, '/') === false) continue; |
|
| 226 | + if (strpos($key, '/') === false) { |
|
| 227 | + continue; |
|
| 228 | + } |
|
| 208 | 229 | |
| 209 | 230 | \Exception('Invalid common data key: '. $key); |
| 210 | 231 | } |