Passed
Branch master (28d65c)
by Henri
01:12
created
src/HelperTrait.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -4,37 +4,37 @@  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 => $_){
12
+        foreach ($data as $variable => $_) {
13 13
             $$variable = $_;
14 14
         }
15 15
         
16
-        $_ = (array_key_exists('_',$data)) ? $data['_'] : null;
16
+        $_ = (array_key_exists('_', $data)) ? $data['_'] : null;
17 17
 
18
-        if(!file_exists($require)){
18
+        if (!file_exists($require)) {
19 19
             $require = basename($require);
20 20
             throw new Exception("Importation file does not exist: {$require} .");
21 21
         }
22 22
         
23 23
         $this->initData();
24 24
 
25
-        $_SESSION['data'] = (!empty($data)) ? array_merge($data,$_SESSION['data']) : $_SESSION['data'];
25
+        $_SESSION['data'] = (!empty($data)) ? array_merge($data, $_SESSION['data']) : $_SESSION['data'];
26 26
 
27 27
         ob_start();
28 28
         require($require);
29 29
         $response = ob_get_contents();
30 30
         ob_end_clean();
31 31
 
32
-        $response = explode(PHP_EOL,$response);
33
-        foreach($response as $index => $value){
32
+        $response = explode(PHP_EOL, $response);
33
+        foreach ($response as $index => $value) {
34 34
             $response[$index] = ltrim($value);
35 35
         }
36 36
         
37
-        return implode('',$response);
37
+        return implode('', $response);
38 38
     }
39 39
 
40 40
     protected function initData()
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
         $_SESSION['data'] = (empty($_SESSION['data'])) ? null : $_SESSION['data'];
43 43
     }
44 44
 
45
-    protected function getVars(string $buffer,string $prefix = null, ?array $values = null): string
45
+    protected function getVars(string $buffer, string $prefix = null, ?array $values = null): string
46 46
     {
47 47
         $this->initData();
48 48
 
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
     protected function replace_vars($buffer, $vars, $prefix): string
55 55
     {
56 56
         foreach ($vars as $key => $value) {
57
-            switch(gettype($value)){
57
+            switch (gettype($value)) {
58 58
                 case 'array':
59 59
                     $buffer = $this->replace_Array($buffer, $value, $prefix, $key);
60 60
                     break;
@@ -72,9 +72,9 @@  discard block
 block discarded – undo
72 72
 
73 73
     protected function replace_value(string $buffer, $value, ?string $prefix, string $key): string
74 74
     {
75
-        if(gettype($value)!=='array' && gettype($value)!=='object'){
76
-            while(strstr($buffer,'{{ $'.$prefix.$key.' }}')){
77
-                $buffer = str_replace('{{ $'.$prefix.$key.' }}', htmlspecialchars($value) ,$buffer);
75
+        if (gettype($value)!=='array' && gettype($value)!=='object') {
76
+            while (strstr($buffer, '{{ $'.$prefix.$key.' }}')) {
77
+                $buffer = str_replace('{{ $'.$prefix.$key.' }}', htmlspecialchars($value), $buffer);
78 78
             }
79 79
         }
80 80
         return $buffer;
@@ -82,12 +82,12 @@  discard block
 block discarded – undo
82 82
 
83 83
     protected function replace_Object(string $buffer, object $obj, string $prefix, string $key): string
84 84
     {
85
-        foreach($obj->get_object_vars() as $field => $val){
85
+        foreach ($obj->get_object_vars() as $field => $val) {
86 86
             
87
-            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.' , $field);
87
+            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.', $field);
88 88
 
89
-            while(strstr($buffer,'{{ $'.$prefix.$key.'.'.$field.' }}')){
90
-                $buffer = str_replace('{{ $'.$prefix.$key.'.'.$field.' }}', htmlspecialchars($val) ,$buffer);
89
+            while (strstr($buffer, '{{ $'.$prefix.$key.'.'.$field.' }}')) {
90
+                $buffer = str_replace('{{ $'.$prefix.$key.'.'.$field.' }}', htmlspecialchars($val), $buffer);
91 91
             }
92 92
         }
93 93
         return $buffer;
@@ -95,11 +95,11 @@  discard block
 block discarded – undo
95 95
 
96 96
     protected function replace_Array(string $buffer, array $array, ?string $prefix = '', ?string $key = ''): string
97 97
     {
98
-        foreach($array as $field => $val){
99
-            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.' , $field);
98
+        foreach ($array as $field => $val) {
99
+            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.', $field);
100 100
 
101
-            while(strstr($buffer,'{{ $'.$prefix.$key.'.'.$field.' }}')){
102
-                $buffer = str_replace('{{ $'.$prefix.$key.'.'.$field.' }}', htmlspecialchars($val) ,$buffer);
101
+            while (strstr($buffer, '{{ $'.$prefix.$key.'.'.$field.' }}')) {
102
+                $buffer = str_replace('{{ $'.$prefix.$key.'.'.$field.' }}', htmlspecialchars($val), $buffer);
103 103
             }
104 104
         }
105 105
         return $buffer;
@@ -107,25 +107,25 @@  discard block
 block discarded – undo
107 107
 
108 108
     protected function removeComments(string $buffer): string
109 109
     {
110
-        while(strstr($buffer,'<!--')){
110
+        while (strstr($buffer, '<!--')) {
111 111
             $comment = substr(
112 112
                 $buffer,
113
-                strpos($buffer,'<!--'),
114
-                strpos(strstr($buffer,'<!--'),'-->')+3
113
+                strpos($buffer, '<!--'),
114
+                strpos(strstr($buffer, '<!--'), '-->')+3
115 115
             );
116
-            $buffer = str_replace($comment,'',$buffer);
116
+            $buffer = str_replace($comment, '', $buffer);
117 117
         }
118 118
         return $buffer;
119 119
     }
120 120
 
121 121
     protected function saveData(): bool
122 122
     {   
123
-        if(session_status() !== PHP_SESSION_ACTIVE){
123
+        if (session_status()!==PHP_SESSION_ACTIVE) {
124 124
             return false;
125 125
         }
126 126
         unset($_SESSION['data']);
127 127
 
128
-        if(!empty($_SESSION['save'])){
128
+        if (!empty($_SESSION['save'])) {
129 129
             foreach ($_SESSION['save'] as $key => $value) {
130 130
                 $_SESSION['data'][$key] = $value;
131 131
             }
Please login to merge, or discard this patch.