Test Setup Failed
Push — master ( 65feeb...cef6c0 )
by Php Easy Api
04:04
created
src/resta/Support/JsonHandler.php 2 patches
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -18,11 +18,11 @@  discard block
 block discarded – undo
18 18
      */
19 19
     private static function checkFile()
20 20
     {
21
-        $filePortions = explode(DIRECTORY_SEPARATOR,self::$file);
21
+        $filePortions = explode(DIRECTORY_SEPARATOR, self::$file);
22 22
         $pop = array_pop($filePortions);
23 23
 
24
-        if(file_exists(implode(DIRECTORY_SEPARATOR,$filePortions))
25
-            && preg_match('@[a-zA-Z0-9]+\.json@',$pop)){
24
+        if (file_exists(implode(DIRECTORY_SEPARATOR, $filePortions))
25
+            && preg_match('@[a-zA-Z0-9]+\.json@', $pop)) {
26 26
             return self::$file;
27 27
         }
28 28
 
@@ -38,8 +38,8 @@  discard block
 block discarded – undo
38 38
     {
39 39
         $file = self::checkFile();
40 40
 
41
-        if(!file_exists($file)){
42
-            files()->put($file,self::encode([]));
41
+        if (!file_exists($file)) {
42
+            files()->put($file, self::encode([]));
43 43
         }
44 44
     }
45 45
 
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      */
52 52
     public static function decode($data)
53 53
     {
54
-        return json_decode($data,1);
54
+        return json_decode($data, 1);
55 55
     }
56 56
 
57 57
     /**
@@ -63,26 +63,26 @@  discard block
 block discarded – undo
63 63
      *
64 64
      * @throws FileNotFoundException
65 65
      */
66
-    public static function delete($key,$arrayKey=null)
66
+    public static function delete($key, $arrayKey = null)
67 67
     {
68 68
         $data = self::get();
69 69
 
70
-        if(is_null($arrayKey)){
70
+        if (is_null($arrayKey)) {
71 71
 
72
-            if(isset($data[$key])){
72
+            if (isset($data[$key])) {
73 73
                 unset($data[$key]);
74
-                files()->put(self::checkFile(),self::encode($data),true);
74
+                files()->put(self::checkFile(), self::encode($data), true);
75 75
                 return true;
76 76
             }
77 77
         }
78 78
 
79 79
         // if the data to be deleted
80 80
         // in json data contains a nested array data.
81
-        if(!is_null($arrayKey) && is_string($arrayKey)){
81
+        if (!is_null($arrayKey) && is_string($arrayKey)) {
82 82
 
83
-            if(isset($data[$key][$arrayKey])){
83
+            if (isset($data[$key][$arrayKey])) {
84 84
                 unset($data[$key][$arrayKey]);
85
-                files()->put(self::checkFile(),self::encode($data),true);
85
+                files()->put(self::checkFile(), self::encode($data), true);
86 86
                 return true;
87 87
             }
88 88
         }
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
      */
99 99
     public static function encode($data)
100 100
     {
101
-        return json_encode($data,JSON_PRETTY_PRINT);
101
+        return json_encode($data, JSON_PRETTY_PRINT);
102 102
     }
103 103
 
104 104
     /**
@@ -109,13 +109,13 @@  discard block
 block discarded – undo
109 109
      *
110 110
      * @throws FileNotFoundException
111 111
      */
112
-    public static function get($key=null)
112
+    public static function get($key = null)
113 113
     {
114 114
         self::createIfNotFileExist();
115 115
 
116 116
         $data = self::decode(files()->get(self::checkFile()));
117 117
 
118
-        if(is_null($key)){
118
+        if (is_null($key)) {
119 119
             return $data;
120 120
         }
121 121
 
@@ -132,27 +132,27 @@  discard block
 block discarded – undo
132 132
      *
133 133
      * @throws FileNotFoundException
134 134
      */
135
-    public static function set($key,$value)
135
+    public static function set($key, $value)
136 136
     {
137 137
         self::createIfNotFileExist();
138 138
 
139 139
         $file = self::get();
140 140
 
141
-        $dotted = explode('.',$key);
141
+        $dotted = explode('.', $key);
142 142
 
143
-        if(count($dotted)>1){
143
+        if (count($dotted)>1) {
144 144
             $arrayInstance = new ArraySafe(self::get());
145
-            $nestedArray = $arrayInstance->set($key,$value)->toArray();
146
-            files()->put(self::checkFile(),self::encode($nestedArray));
145
+            $nestedArray = $arrayInstance->set($key, $value)->toArray();
146
+            files()->put(self::checkFile(), self::encode($nestedArray));
147 147
         }
148
-        else{
148
+        else {
149 149
 
150
-            if(isset($file[$key]) && is_array($value)){
151
-                $file[$key] = array_merge($file[$key],$value);
152
-                files()->put(self::checkFile(),self::encode($file));
150
+            if (isset($file[$key]) && is_array($value)) {
151
+                $file[$key] = array_merge($file[$key], $value);
152
+                files()->put(self::checkFile(), self::encode($file));
153 153
             }
154
-            else{
155
-                files()->put(self::checkFile(),self::encode(array_merge($file,[$key=>$value])));
154
+            else {
155
+                files()->put(self::checkFile(), self::encode(array_merge($file, [$key=>$value])));
156 156
             }
157 157
         }
158 158
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -144,14 +144,12 @@
 block discarded – undo
144 144
             $arrayInstance = new ArraySafe(self::get());
145 145
             $nestedArray = $arrayInstance->set($key,$value)->toArray();
146 146
             files()->put(self::checkFile(),self::encode($nestedArray));
147
-        }
148
-        else{
147
+        } else{
149 148
 
150 149
             if(isset($file[$key]) && is_array($value)){
151 150
                 $file[$key] = array_merge($file[$key],$value);
152 151
                 files()->put(self::checkFile(),self::encode($file));
153
-            }
154
-            else{
152
+            } else{
155 153
                 files()->put(self::checkFile(),self::encode(array_merge($file,[$key=>$value])));
156 154
             }
157 155
         }
Please login to merge, or discard this patch.