Passed
Push — master ( 39b2c2...164285 )
by Henri
01:18
created
src/HelperTrait.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -4,22 +4,22 @@  discard block
 block discarded – undo
4 4
 
5 5
 use Exception;
6 6
 
7
-trait HelperTrait{
7
+trait HelperTrait {
8 8
     use CheckTrait, JScriptTrait;
9 9
 
10 10
     public array $data = [];
11 11
 
12 12
     protected function getOB(string $require, array $data = []): string
13 13
     {
14
-        $this->data = array_merge($this->data,$data);
14
+        $this->data = array_merge($this->data, $data);
15 15
 
16
-        foreach($this->data as $variable => $_){
16
+        foreach ($this->data as $variable => $_) {
17 17
             $$variable = $_;
18 18
         }
19 19
         
20
-        $_ = (array_key_exists('_',$data)) ? $data['_'] : null;
20
+        $_ = (array_key_exists('_', $data)) ? $data['_'] : null;
21 21
 
22
-        if(!file_exists($require)){
22
+        if (!file_exists($require)) {
23 23
             $require = basename($require);
24 24
             throw new Exception("Importation file does not exist: {$require} .");
25 25
         }
@@ -34,21 +34,21 @@  discard block
 block discarded – undo
34 34
 
35 35
     private function treatHTML(string $html): string
36 36
     {
37
-        $arrayHtml = explode(PHP_EOL,$html);
37
+        $arrayHtml = explode(PHP_EOL, $html);
38 38
         $html = [];
39 39
 
40 40
         $inScript = false;
41 41
         $inComment = false;
42 42
             
43
-        foreach($arrayHtml as $index => $value){
43
+        foreach ($arrayHtml as $index => $value) {
44 44
             $inScript = $this->checkInScript($inScript, $value);
45 45
             
46
-            if($inScript){
46
+            if ($inScript) {
47 47
                 $inComment = $this->checkCommentInScript($inComment, $value);
48 48
 
49
-                if(!$this->checkScriptNeed($inComment, $value)){
49
+                if (!$this->checkScriptNeed($inComment, $value)) {
50 50
                     continue;
51
-                }else{
51
+                }else {
52 52
                     $value = $this->treatScript($value);
53 53
                 }
54 54
             }
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
             $html[$index] = ltrim($value);
57 57
         }
58 58
         
59
-        return implode('',$html);
59
+        return implode('', $html);
60 60
     }
61 61
 
62 62
     protected function getVars(string $buffer): string
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
     protected function replaceVars(string $buffer, array $vars, ?string $prefix = ''): string
68 68
     {
69 69
         foreach ($vars as $key => $value) {
70
-            switch(gettype($value)){
70
+            switch (gettype($value)) {
71 71
                 case 'array':
72 72
                     $buffer = $this->replaceArray($buffer, $value, $prefix, $key);
73 73
                     break;
@@ -85,9 +85,9 @@  discard block
 block discarded – undo
85 85
 
86 86
     protected function replaceValue(string $buffer, $value, ?string $prefix, string $key): string
87 87
     {
88
-        if(gettype($value)!=='array' && gettype($value)!=='object'){
89
-            while(strstr($buffer,'{{ $'.$prefix.$key.' }}')){
90
-                $buffer = str_replace('{{ $'.$prefix.$key.' }}', htmlspecialchars($value) ,$buffer);
88
+        if (gettype($value)!=='array' && gettype($value)!=='object') {
89
+            while (strstr($buffer, '{{ $'.$prefix.$key.' }}')) {
90
+                $buffer = str_replace('{{ $'.$prefix.$key.' }}', htmlspecialchars($value), $buffer);
91 91
             }
92 92
         }
93 93
         return $buffer;
@@ -95,14 +95,14 @@  discard block
 block discarded – undo
95 95
 
96 96
     protected function replaceObject(string $buffer, object $obj, ?string $prefix, string $key): string
97 97
     {
98
-        $vars = method_exists($obj,'getVars') ? $obj->getVars() : [];
98
+        $vars = method_exists($obj, 'getVars') ? $obj->getVars() : [];
99 99
         $vars = array_merge($vars, get_object_vars($obj));
100
-        foreach($vars as $field => $val){
100
+        foreach ($vars as $field => $val) {
101 101
             
102
-            $buffer = $this->replaceValue($buffer, $val, $key.'.'.$field.'.' , $field);
102
+            $buffer = $this->replaceValue($buffer, $val, $key.'.'.$field.'.', $field);
103 103
 
104
-            while(strstr($buffer,'{{ $'.$prefix.$key.'.'.$field.' }}')){
105
-                $buffer = str_replace('{{ $'.$prefix.$key.'.'.$field.' }}', htmlspecialchars($obj->$field) ,$buffer);
104
+            while (strstr($buffer, '{{ $'.$prefix.$key.'.'.$field.' }}')) {
105
+                $buffer = str_replace('{{ $'.$prefix.$key.'.'.$field.' }}', htmlspecialchars($obj->$field), $buffer);
106 106
             }
107 107
         }
108 108
         return $buffer;
@@ -110,11 +110,11 @@  discard block
 block discarded – undo
110 110
 
111 111
     protected function replaceArray(string $buffer, array $array, ?string $prefix = '', ?string $key = ''): string
112 112
     {
113
-        foreach($array as $field => $val){
114
-            $buffer = $this->replaceValue($buffer, $val, $key.'.'.$field.'.' , $field);
113
+        foreach ($array as $field => $val) {
114
+            $buffer = $this->replaceValue($buffer, $val, $key.'.'.$field.'.', $field);
115 115
 
116
-            while(strstr($buffer,'{{ $'.$prefix.$key.'.'.$field.' }}')){
117
-                $buffer = str_replace('{{ $'.$prefix.$key.'.'.$field.' }}', htmlspecialchars($val) ,$buffer);
116
+            while (strstr($buffer, '{{ $'.$prefix.$key.'.'.$field.' }}')) {
117
+                $buffer = str_replace('{{ $'.$prefix.$key.'.'.$field.' }}', htmlspecialchars($val), $buffer);
118 118
             }
119 119
         }
120 120
         return $buffer;
@@ -122,13 +122,13 @@  discard block
 block discarded – undo
122 122
 
123 123
     protected function removeComments(string $buffer): string
124 124
     {
125
-        while(strstr($buffer,'<!--')){
125
+        while (strstr($buffer, '<!--')) {
126 126
             $comment = substr(
127 127
                 $buffer,
128
-                strpos($buffer,'<!--'),
129
-                strpos(strstr($buffer,'<!--'),'-->')+3
128
+                strpos($buffer, '<!--'),
129
+                strpos(strstr($buffer, '<!--'), '-->')+3
130 130
             );
131
-            $buffer = str_replace($comment,'',$buffer);
131
+            $buffer = str_replace($comment, '', $buffer);
132 132
         }
133 133
         return $buffer;
134 134
     }
Please login to merge, or discard this patch.