Passed
Push — master ( 1ad2f5...2d8719 )
by Henri
01:12
created
src/HelperTrait.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -4,25 +4,25 @@  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
-        foreach($data as $variable => $_){
14
+        foreach ($data as $variable => $_) {
15 15
             $$variable = $_;
16 16
         }
17 17
         
18
-        $_ = (array_key_exists('_',$data)) ? $data['_'] : null;
18
+        $_ = (array_key_exists('_', $data)) ? $data['_'] : null;
19 19
 
20
-        if(!file_exists($require)){
20
+        if (!file_exists($require)) {
21 21
             $require = basename($require);
22 22
             throw new Exception("Importation file does not exist: {$require} .");
23 23
         }
24 24
 
25
-        $this->data = array_merge($this->data,$data);
25
+        $this->data = array_merge($this->data, $data);
26 26
 
27 27
         ob_start();
28 28
         require($require);
@@ -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,12 +95,12 @@  discard block
 block discarded – undo
95 95
 
96 96
     protected function replaceObject(string $buffer, object $obj, string $prefix, string $key): string
97 97
     {
98
-        foreach(get_object_vars($obj) as $field => $val){
98
+        foreach (get_object_vars($obj) as $field => $val) {
99 99
             
100
-            $buffer = $this->replaceValue($buffer, $val, $key.'.'.$field.'.' , $field);
100
+            $buffer = $this->replaceValue($buffer, $val, $key.'.'.$field.'.', $field);
101 101
 
102
-            while(strstr($buffer,'{{ $'.$prefix.$key.'.'.$field.' }}')){
103
-                $buffer = str_replace('{{ $'.$prefix.$key.'.'.$field.' }}', htmlspecialchars($obj->$field) ,$buffer);
102
+            while (strstr($buffer, '{{ $'.$prefix.$key.'.'.$field.' }}')) {
103
+                $buffer = str_replace('{{ $'.$prefix.$key.'.'.$field.' }}', htmlspecialchars($obj->$field), $buffer);
104 104
             }
105 105
         }
106 106
         return $buffer;
@@ -108,11 +108,11 @@  discard block
 block discarded – undo
108 108
 
109 109
     protected function replaceArray(string $buffer, array $array, ?string $prefix = '', ?string $key = ''): string
110 110
     {
111
-        foreach($array as $field => $val){
112
-            $buffer = $this->replaceValue($buffer, $val, $key.'.'.$field.'.' , $field);
111
+        foreach ($array as $field => $val) {
112
+            $buffer = $this->replaceValue($buffer, $val, $key.'.'.$field.'.', $field);
113 113
 
114
-            while(strstr($buffer,'{{ $'.$prefix.$key.'.'.$field.' }}')){
115
-                $buffer = str_replace('{{ $'.$prefix.$key.'.'.$field.' }}', htmlspecialchars($val) ,$buffer);
114
+            while (strstr($buffer, '{{ $'.$prefix.$key.'.'.$field.' }}')) {
115
+                $buffer = str_replace('{{ $'.$prefix.$key.'.'.$field.' }}', htmlspecialchars($val), $buffer);
116 116
             }
117 117
         }
118 118
         return $buffer;
@@ -120,13 +120,13 @@  discard block
 block discarded – undo
120 120
 
121 121
     protected function removeComments(string $buffer): string
122 122
     {
123
-        while(strstr($buffer,'<!--')){
123
+        while (strstr($buffer, '<!--')) {
124 124
             $comment = substr(
125 125
                 $buffer,
126
-                strpos($buffer,'<!--'),
127
-                strpos(strstr($buffer,'<!--'),'-->')+3
126
+                strpos($buffer, '<!--'),
127
+                strpos(strstr($buffer, '<!--'), '-->')+3
128 128
             );
129
-            $buffer = str_replace($comment,'',$buffer);
129
+            $buffer = str_replace($comment, '', $buffer);
130 130
         }
131 131
         return $buffer;
132 132
     }
Please login to merge, or discard this patch.
src/EspecialHelperTrait.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 namespace HnrAzevedo\Viewer;
4 4
 
5
-trait EspecialHelperTrait{
5
+trait EspecialHelperTrait {
6 6
     use HelperTrait;
7 7
 
8 8
     protected function getEspecialVars(string $buffer): string
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
     protected function replaceEspecialVars(string $buffer, array $vars, ?string $prefix = ''): string
14 14
     {
15 15
         foreach ($vars as $key => $value) {
16
-            switch(gettype($value)){
16
+            switch (gettype($value)) {
17 17
                 case 'array':
18 18
                     $buffer = $this->replaceEspecialArray($buffer, $value, $prefix, $key);
19 19
                     break;
@@ -31,9 +31,9 @@  discard block
 block discarded – undo
31 31
 
32 32
     protected function replaceEspecialValue(string $buffer, $value, ?string $prefix, string $key): string
33 33
     {
34
-        if(gettype($value)!=='array' && gettype($value)!=='object'){
35
-            while(strstr($buffer,'{{!! $'.$prefix.$key.' !!}}')){
36
-                $buffer = str_replace('{{!! $'.$prefix.$key.' !!}}', $value ,$buffer);
34
+        if (gettype($value)!=='array' && gettype($value)!=='object') {
35
+            while (strstr($buffer, '{{!! $'.$prefix.$key.' !!}}')) {
36
+                $buffer = str_replace('{{!! $'.$prefix.$key.' !!}}', $value, $buffer);
37 37
             }
38 38
         }
39 39
         return $buffer;
@@ -41,12 +41,12 @@  discard block
 block discarded – undo
41 41
 
42 42
     protected function replaceEspecialObject(string $buffer, object $obj, string $prefix, string $key): string
43 43
     {
44
-        foreach(get_object_vars($obj) as $field => $val){
44
+        foreach (get_object_vars($obj) as $field => $val) {
45 45
             
46
-            $buffer = $this->replaceEspecialValue($buffer, $val, $key.'.'.$field.'.' , $field);
46
+            $buffer = $this->replaceEspecialValue($buffer, $val, $key.'.'.$field.'.', $field);
47 47
 
48
-            while(strstr($buffer,'{{!! $'.$prefix.$key.'.'.$field.' !!}}')){
49
-                $buffer = str_replace('{{!! $'.$prefix.$key.'.'.$field.' !!}}', $obj->$field ,$buffer);
48
+            while (strstr($buffer, '{{!! $'.$prefix.$key.'.'.$field.' !!}}')) {
49
+                $buffer = str_replace('{{!! $'.$prefix.$key.'.'.$field.' !!}}', $obj->$field, $buffer);
50 50
             }
51 51
         }
52 52
         return $buffer;
@@ -54,11 +54,11 @@  discard block
 block discarded – undo
54 54
 
55 55
     protected function replaceEspecialArray(string $buffer, array $array, ?string $prefix = '', ?string $key = ''): string
56 56
     {
57
-        foreach($array as $field => $val){
58
-            $buffer = $this->replaceEspecialValue($buffer, $val, $key.'.'.$field.'.' , $field);
57
+        foreach ($array as $field => $val) {
58
+            $buffer = $this->replaceEspecialValue($buffer, $val, $key.'.'.$field.'.', $field);
59 59
 
60
-            while(strstr($buffer,'{{!! $'.$prefix.$key.'.'.$field.' !!}}')){
61
-                $buffer = str_replace('{{!! $'.$prefix.$key.'.'.$field.' !!}}', $val ,$buffer);
60
+            while (strstr($buffer, '{{!! $'.$prefix.$key.'.'.$field.' !!}}')) {
61
+                $buffer = str_replace('{{!! $'.$prefix.$key.'.'.$field.' !!}}', $val, $buffer);
62 62
             }
63 63
         }
64 64
         return $buffer;
Please login to merge, or discard this patch.