Passed
Branch master (af8266)
by Henri
02:51 queued 01:38
created
src/HelperTrait.php 2 patches
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -4,12 +4,12 @@  discard block
 block discarded – undo
4 4
 
5 5
 use Exception;
6 6
 
7
-trait HelperTrait{
7
+trait HelperTrait {
8 8
     use CheckTrait;
9 9
 
10 10
     protected function getOB(string $require, array $data = []): string
11 11
     {
12
-        foreach($data as $variable => $value){
12
+        foreach ($data as $variable => $value) {
13 13
             $$variable = $value;
14 14
         }
15 15
 
@@ -18,15 +18,15 @@  discard block
 block discarded – undo
18 18
         $response = ob_get_contents();
19 19
         ob_end_clean();
20 20
 
21
-        $response = explode(PHP_EOL,$response);
22
-        foreach($response as $index => $value){
21
+        $response = explode(PHP_EOL, $response);
22
+        foreach ($response as $index => $value) {
23 23
             $response[$index] = ltrim($value);
24 24
         }
25 25
         
26
-        return implode('',$response);
26
+        return implode('', $response);
27 27
     }
28 28
 
29
-    protected function getVars(string $buffer,string $prefix = null, ?array $values = null): string
29
+    protected function getVars(string $buffer, string $prefix = null, ?array $values = null): string
30 30
     {
31 31
         $_SESSION['data'] = (empty($_SESSION['data'])) ? null : $_SESSION['data'];
32 32
 
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
     protected function replace_vars($buffer, $vars, $prefix): string
39 39
     {
40 40
         foreach ($vars as $key => $value) {
41
-            switch(gettype($value)){
41
+            switch (gettype($value)) {
42 42
                 case 'array':
43 43
                     $buffer = $this->replace_Array($buffer, $value, $prefix, $key);
44 44
                     break;
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
 
57 57
     protected function replace_value(string $buffer, $value, string $prefix, string $key): string
58 58
     {
59
-        if(gettype($value)!=='array' && gettype($value)!=='object'){
60
-            while(strstr($buffer,'{{ '.$prefix.$key.' }}')){
61
-                $buffer = str_replace('{{ '.$prefix.$key.' }}', $value ,$buffer);
59
+        if (gettype($value)!=='array' && gettype($value)!=='object') {
60
+            while (strstr($buffer, '{{ '.$prefix.$key.' }}')) {
61
+                $buffer = str_replace('{{ '.$prefix.$key.' }}', $value, $buffer);
62 62
             }
63 63
         }
64 64
         return $buffer;
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 
67 67
     protected function replace_Object(string $buffer, object $obj, string $prefix, string $key): string
68 68
     {
69
-        foreach($obj->get_object_vars() as $field => $val){
69
+        foreach ($obj->get_object_vars() as $field => $val) {
70 70
             
71
-            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.' , $field);
71
+            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.', $field);
72 72
 
73
-            while(strstr($buffer,'{{ '.$prefix.$key.'.'.$field.' }}')){
74
-                $buffer = str_replace('{{ '.$prefix.$key.'.'.$field.' }}',$val ,$buffer);
73
+            while (strstr($buffer, '{{ '.$prefix.$key.'.'.$field.' }}')) {
74
+                $buffer = str_replace('{{ '.$prefix.$key.'.'.$field.' }}', $val, $buffer);
75 75
             }
76 76
         }
77 77
         return $buffer;
@@ -79,11 +79,11 @@  discard block
 block discarded – undo
79 79
 
80 80
     protected function replace_Array(string $buffer, array $array, string $prefix, string $key): string
81 81
     {
82
-        foreach($array as $field => $val){
83
-            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.' , $field);
82
+        foreach ($array as $field => $val) {
83
+            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.', $field);
84 84
 
85
-            while(strstr($buffer,'{{ '.$prefix.$key.'.'.$field.' }}')){
86
-                $buffer = str_replace('{{ '.$prefix.$key.'.'.$field.' }}',$val,$buffer);
85
+            while (strstr($buffer, '{{ '.$prefix.$key.'.'.$field.' }}')) {
86
+                $buffer = str_replace('{{ '.$prefix.$key.'.'.$field.' }}', $val, $buffer);
87 87
             }
88 88
         }
89 89
         return $buffer;
@@ -91,38 +91,38 @@  discard block
 block discarded – undo
91 91
 
92 92
     protected function removeComments(string $buffer): string
93 93
     {
94
-        while(strstr($buffer,'<!--')){
94
+        while (strstr($buffer, '<!--')) {
95 95
             $comment = substr(
96 96
                 $buffer,
97
-                strpos($buffer,'<!--'),
98
-                strpos(strstr($buffer,'<!--'),'-->')+3
97
+                strpos($buffer, '<!--'),
98
+                strpos(strstr($buffer, '<!--'), '-->')+3
99 99
             );
100
-            $buffer = str_replace($comment,'',$buffer);
100
+            $buffer = str_replace($comment, '', $buffer);
101 101
         }
102 102
         return $buffer;
103 103
     }
104 104
 
105 105
     protected function getImport(string $buffer, array $data = []): string
106 106
     {
107
-        while(strstr($buffer,'@import')){
107
+        while (strstr($buffer, '@import')) {
108 108
             $buffer = $this->getVars($buffer);
109 109
 
110 110
             $import = substr(
111 111
                 $buffer,
112
-                strpos($buffer,'@import(\''),
113
-                strpos(strstr($buffer,'@import'),'\')')+2
112
+                strpos($buffer, '@import(\''),
113
+                strpos(strstr($buffer, '@import'), '\')')+2
114 114
             );
115 115
 
116 116
             $tpl = $this->check_importExist($import);
117 117
 
118
-            try{
119
-                $buffer_tpl = $this->getOB($this->path . DIRECTORY_SEPARATOR . $tpl . '.tpl.php', $data);
120
-            }catch(Exception $er){
118
+            try {
119
+                $buffer_tpl = $this->getOB($this->path.DIRECTORY_SEPARATOR.$tpl.'.tpl.php', $data);
120
+            }catch (Exception $er) {
121 121
                 throw $er;
122 122
             }
123 123
             
124 124
             $buffer_tpl = $this->getVars($buffer_tpl);
125
-            $buffer = str_replace($import,$buffer_tpl,$buffer);
125
+            $buffer = str_replace($import, $buffer_tpl, $buffer);
126 126
         }
127 127
 
128 128
         return $buffer;
@@ -130,12 +130,12 @@  discard block
 block discarded – undo
130 130
 
131 131
     protected function saveData(): bool
132 132
     {   
133
-        if(session_status() !== PHP_SESSION_ACTIVE){
133
+        if (session_status()!==PHP_SESSION_ACTIVE) {
134 134
             return false;
135 135
         }
136 136
         unset($_SESSION['data']);
137 137
 
138
-        if(!empty($_SESSION['save'])){
138
+        if (!empty($_SESSION['save'])) {
139 139
             foreach ($_SESSION['save'] as $key => $value) {
140 140
                 $_SESSION['data'][$key] = $value;
141 141
             }
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -117,7 +117,7 @@
 block discarded – undo
117 117
 
118 118
             try{
119 119
                 $buffer_tpl = $this->getOB($this->path . DIRECTORY_SEPARATOR . $tpl . '.tpl.php', $data);
120
-            }catch(Exception $er){
120
+            } catch(Exception $er){
121 121
                 throw $er;
122 122
             }
123 123
             
Please login to merge, or discard this patch.