Passed
Branch master (a6e528)
by Henri
02:18 queued 01:03
created
src/JScriptTrait.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -3,14 +3,14 @@  discard block
 block discarded – undo
3 3
 namespace HnrAzevedo\Viewer;
4 4
 
5 5
 
6
-trait JScriptTrait{
6
+trait JScriptTrait {
7 7
 
8 8
     protected function checkInScript(bool $inScript, string $value): bool
9 9
     {
10
-        if((substr(ltrim($value),0,8) === '<script>' && !strpos($value,'src'))){
10
+        if ((substr(ltrim($value), 0, 8)==='<script>' && !strpos($value, 'src'))) {
11 11
             $inScript = true;
12 12
         }
13
-        if((substr(ltrim($value),0,9) === '</script>')){
13
+        if ((substr(ltrim($value), 0, 9)==='</script>')) {
14 14
             $inScript = false;
15 15
         }
16 16
         return $inScript;
@@ -18,17 +18,17 @@  discard block
 block discarded – undo
18 18
 
19 19
     protected function checkCommentInScript(bool $inComment, string $value): bool
20 20
     {
21
-        if(strpos($value,'/*') && !strpos($value,'*/')){
21
+        if (strpos($value, '/*') && !strpos($value, '*/')) {
22 22
             $inComment = true;
23
-        }else{
24
-            $inComment = (strpos($value,'*/')) ? false : $inComment;
23
+        }else {
24
+            $inComment = (strpos($value, '*/')) ? false : $inComment;
25 25
         }
26 26
         return $inComment;
27 27
     }
28 28
 
29 29
     protected function checkScriptNeed(bool $inComment, string $value): bool
30 30
     {
31
-        if(($inComment || strpos($value,'//'))){
31
+        if (($inComment || strpos($value, '//'))) {
32 32
             return false;
33 33
         } 
34 34
         return true;
@@ -36,12 +36,12 @@  discard block
 block discarded – undo
36 36
 
37 37
     protected function treatScript(string $value): string
38 38
     {
39
-        while(  strpos($value,'/*') && strpos($value,'*/')  ){
40
-            $replace = substr($value,strripos ($value,'/*'),strripos ($value,'*/')+2);
41
-            $value = str_replace($replace,'',$value);
39
+        while (strpos($value, '/*') && strpos($value, '*/')) {
40
+            $replace = substr($value, strripos($value, '/*'), strripos($value, '*/')+2);
41
+            $value = str_replace($replace, '', $value);
42 42
         }
43
-        if(strpos($value,'*/')){
44
-            $value = substr($value,strpos($value,'*/')+2);
43
+        if (strpos($value, '*/')) {
44
+            $value = substr($value, strpos($value, '*/')+2);
45 45
         }
46 46
         return $value;
47 47
     }
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
     {
21 21
         if(strpos($value,'/*') && !strpos($value,'*/')){
22 22
             $inComment = true;
23
-        }else{
23
+        } else{
24 24
             $inComment = (strpos($value,'*/')) ? false : $inComment;
25 25
         }
26 26
         return $inComment;
Please login to merge, or discard this patch.
src/HelperTrait.php 2 patches
Spacing   +30 added lines, -30 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
     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);
@@ -36,22 +36,22 @@  discard block
 block discarded – undo
36 36
 
37 37
     private function treatHTML(string $html): string
38 38
     {
39
-        $arrayHtml = explode(PHP_EOL,$html);
39
+        $arrayHtml = explode(PHP_EOL, $html);
40 40
         $html = [];
41 41
 
42 42
         $inScript = false;
43 43
         $inComment = false;
44 44
             
45
-        foreach($arrayHtml as $index => $value){
45
+        foreach ($arrayHtml as $index => $value) {
46 46
             $inScript = $this->checkInScript($inScript, $value);
47 47
             
48 48
 
49
-            if($inScript){
49
+            if ($inScript) {
50 50
                 $inComment = $this->checkCommentInScript($inComment, $value);
51 51
 
52
-                if(!$this->checkScriptNeed($inComment, $value)){
52
+                if (!$this->checkScriptNeed($inComment, $value)) {
53 53
                     continue;
54
-                }else{
54
+                }else {
55 55
                     $value = $this->treatScript($value);
56 56
                 }
57 57
             }
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
             $html[$index] = ltrim($value);
60 60
         }
61 61
         
62
-        return implode('',$html);
62
+        return implode('', $html);
63 63
     }
64 64
 
65 65
     protected function initData()
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
         $_SESSION['data'] = (empty($_SESSION['data'])) ? null : $_SESSION['data'];
68 68
     }
69 69
 
70
-    protected function getVars(string $buffer,string $prefix = null, ?array $values = null): string
70
+    protected function getVars(string $buffer, string $prefix = null, ?array $values = null): string
71 71
     {
72 72
         $this->initData();
73 73
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
     protected function replace_vars($buffer, $vars, $prefix): string
80 80
     {
81 81
         foreach ($vars as $key => $value) {
82
-            switch(gettype($value)){
82
+            switch (gettype($value)) {
83 83
                 case 'array':
84 84
                     $buffer = $this->replace_Array($buffer, $value, $prefix, $key);
85 85
                     break;
@@ -97,9 +97,9 @@  discard block
 block discarded – undo
97 97
 
98 98
     protected function replace_value(string $buffer, $value, ?string $prefix, string $key): string
99 99
     {
100
-        if(gettype($value)!=='array' && gettype($value)!=='object'){
101
-            while(strstr($buffer,'{{ $'.$prefix.$key.' }}')){
102
-                $buffer = str_replace('{{ $'.$prefix.$key.' }}', htmlspecialchars($value) ,$buffer);
100
+        if (gettype($value)!=='array' && gettype($value)!=='object') {
101
+            while (strstr($buffer, '{{ $'.$prefix.$key.' }}')) {
102
+                $buffer = str_replace('{{ $'.$prefix.$key.' }}', htmlspecialchars($value), $buffer);
103 103
             }
104 104
         }
105 105
         return $buffer;
@@ -107,12 +107,12 @@  discard block
 block discarded – undo
107 107
 
108 108
     protected function replace_Object(string $buffer, object $obj, string $prefix, string $key): string
109 109
     {
110
-        foreach($obj->get_object_vars() as $field => $val){
110
+        foreach ($obj->get_object_vars() as $field => $val) {
111 111
             
112
-            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.' , $field);
112
+            $buffer = $this->replace_value($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,11 +120,11 @@  discard block
 block discarded – undo
120 120
 
121 121
     protected function replace_Array(string $buffer, array $array, ?string $prefix = '', ?string $key = ''): string
122 122
     {
123
-        foreach($array as $field => $val){
124
-            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.' , $field);
123
+        foreach ($array as $field => $val) {
124
+            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.', $field);
125 125
 
126
-            while(strstr($buffer,'{{ $'.$prefix.$key.'.'.$field.' }}')){
127
-                $buffer = str_replace('{{ $'.$prefix.$key.'.'.$field.' }}', htmlspecialchars($val) ,$buffer);
126
+            while (strstr($buffer, '{{ $'.$prefix.$key.'.'.$field.' }}')) {
127
+                $buffer = str_replace('{{ $'.$prefix.$key.'.'.$field.' }}', htmlspecialchars($val), $buffer);
128 128
             }
129 129
         }
130 130
         return $buffer;
@@ -132,25 +132,25 @@  discard block
 block discarded – undo
132 132
 
133 133
     protected function removeComments(string $buffer): string
134 134
     {
135
-        while(strstr($buffer,'<!--')){
135
+        while (strstr($buffer, '<!--')) {
136 136
             $comment = substr(
137 137
                 $buffer,
138
-                strpos($buffer,'<!--'),
139
-                strpos(strstr($buffer,'<!--'),'-->')+3
138
+                strpos($buffer, '<!--'),
139
+                strpos(strstr($buffer, '<!--'), '-->')+3
140 140
             );
141
-            $buffer = str_replace($comment,'',$buffer);
141
+            $buffer = str_replace($comment, '', $buffer);
142 142
         }
143 143
         return $buffer;
144 144
     }
145 145
 
146 146
     protected function saveData(): bool
147 147
     {   
148
-        if(session_status() !== PHP_SESSION_ACTIVE){
148
+        if (session_status()!==PHP_SESSION_ACTIVE) {
149 149
             return false;
150 150
         }
151 151
         unset($_SESSION['data']);
152 152
 
153
-        if(!empty($_SESSION['save'])){
153
+        if (!empty($_SESSION['save'])) {
154 154
             foreach ($_SESSION['save'] as $key => $value) {
155 155
                 $_SESSION['data'][$key] = $value;
156 156
             }
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@
 block discarded – undo
51 51
 
52 52
                 if(!$this->checkScriptNeed($inComment, $value)){
53 53
                     continue;
54
-                }else{
54
+                } else{
55 55
                     $value = $this->treatScript($value);
56 56
                 }
57 57
             }
Please login to merge, or discard this patch.