Test Setup Failed
Push — master ( 44d278...ec418a )
by Php Easy Api
03:52
created
src/resta/Support/JsonHandler.php 2 patches
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -23,13 +23,13 @@  discard block
 block discarded – undo
23 23
      */
24 24
     private static function checkFile()
25 25
     {
26
-        if(!is_null(self::$singleton)) return self::$singleton;
26
+        if (!is_null(self::$singleton)) return self::$singleton;
27 27
 
28
-        $filePortions = explode(DIRECTORY_SEPARATOR,self::$file);
28
+        $filePortions = explode(DIRECTORY_SEPARATOR, self::$file);
29 29
         $pop = array_pop($filePortions);
30 30
 
31
-        if(file_exists(implode(DIRECTORY_SEPARATOR,$filePortions))
32
-            && preg_match('@[a-zA-Z0-9]+\.json@',$pop)){
31
+        if (file_exists(implode(DIRECTORY_SEPARATOR, $filePortions))
32
+            && preg_match('@[a-zA-Z0-9]+\.json@', $pop)) {
33 33
             self::$singleton = self::$file;
34 34
             return self::$singleton;
35 35
         }
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
     {
47 47
         $file = self::checkFile();
48 48
 
49
-        if(!file_exists($file)){
50
-            files()->put($file,self::encode([]));
49
+        if (!file_exists($file)) {
50
+            files()->put($file, self::encode([]));
51 51
         }
52 52
     }
53 53
 
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
      */
60 60
     public static function decode($data)
61 61
     {
62
-        return json_decode($data,1);
62
+        return json_decode($data, 1);
63 63
     }
64 64
 
65 65
     /**
@@ -71,26 +71,26 @@  discard block
 block discarded – undo
71 71
      *
72 72
      * @throws FileNotFoundException
73 73
      */
74
-    public static function delete($key,$arrayKey=null)
74
+    public static function delete($key, $arrayKey = null)
75 75
     {
76 76
         $data = self::get();
77 77
 
78
-        if(is_null($arrayKey)){
78
+        if (is_null($arrayKey)) {
79 79
 
80
-            if(isset($data[$key])){
80
+            if (isset($data[$key])) {
81 81
                 unset($data[$key]);
82
-                files()->put(self::checkFile(),self::encode($data),true);
82
+                files()->put(self::checkFile(), self::encode($data), true);
83 83
                 return true;
84 84
             }
85 85
         }
86 86
 
87 87
         // if the data to be deleted
88 88
         // in json data contains a nested array data.
89
-        if(!is_null($arrayKey) && is_string($arrayKey)){
89
+        if (!is_null($arrayKey) && is_string($arrayKey)) {
90 90
 
91
-            if(isset($data[$key][$arrayKey])){
91
+            if (isset($data[$key][$arrayKey])) {
92 92
                 unset($data[$key][$arrayKey]);
93
-                files()->put(self::checkFile(),self::encode($data),true);
93
+                files()->put(self::checkFile(), self::encode($data), true);
94 94
                 return true;
95 95
             }
96 96
         }
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
      */
107 107
     public static function encode($data)
108 108
     {
109
-        return json_encode($data,JSON_PRETTY_PRINT);
109
+        return json_encode($data, JSON_PRETTY_PRINT);
110 110
     }
111 111
 
112 112
     /**
@@ -132,18 +132,18 @@  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
-        if(isset($file[$key]) && is_array($value)){
142
-            $file[$key] = array_merge($file[$key],$value);
143
-            files()->put(self::checkFile(),self::encode($file));
141
+        if (isset($file[$key]) && is_array($value)) {
142
+            $file[$key] = array_merge($file[$key], $value);
143
+            files()->put(self::checkFile(), self::encode($file));
144 144
         }
145
-        else{
146
-            files()->put(self::checkFile(),self::encode(array_merge($file,[$key=>$value])));
145
+        else {
146
+            files()->put(self::checkFile(), self::encode(array_merge($file, [$key=>$value])));
147 147
         }
148 148
 
149 149
         return self::get();
Please login to merge, or discard this patch.
Braces   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -23,7 +23,9 @@  discard block
 block discarded – undo
23 23
      */
24 24
     private static function checkFile()
25 25
     {
26
-        if(!is_null(self::$singleton)) return self::$singleton;
26
+        if(!is_null(self::$singleton)) {
27
+            return self::$singleton;
28
+        }
27 29
 
28 30
         $filePortions = explode(DIRECTORY_SEPARATOR,self::$file);
29 31
         $pop = array_pop($filePortions);
@@ -141,8 +143,7 @@  discard block
 block discarded – undo
141 143
         if(isset($file[$key]) && is_array($value)){
142 144
             $file[$key] = array_merge($file[$key],$value);
143 145
             files()->put(self::checkFile(),self::encode($file));
144
-        }
145
-        else{
146
+        } else{
146 147
             files()->put(self::checkFile(),self::encode(array_merge($file,[$key=>$value])));
147 148
         }
148 149
 
Please login to merge, or discard this patch.