Passed
Push — master ( 0cd5ac...9d2f0c )
by Henri
07:06
created
examples/index.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
     ];
17 17
 
18 18
     Viewer::create(__DIR__.'/Views/')
19
-          ->render('default', $data);
19
+            ->render('default', $data);
20 20
 
21 21
 }catch(Exception $er){
22 22
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
     Viewer::create(__DIR__.'/Views/')
19 19
           ->render('default', $data);
20 20
 
21
-}catch(Exception $er){
21
+} catch(Exception $er){
22 22
 
23 23
     die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}.");
24 24
 
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 
9 9
 /* NOTE: in case of error an exception is thrown */
10 10
 
11
-try{
11
+try {
12 12
     
13 13
     $data = ['parameter'=>
14 14
         [
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
     Viewer::create(__DIR__.'/Views/')
21 21
           ->render('default', $data);
22 22
 
23
-}catch(Exception $er){
23
+}catch (Exception $er) {
24 24
 
25 25
     die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}.");
26 26
 
Please login to merge, or discard this patch.
src/CheckTrait.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -4,11 +4,11 @@
 block discarded – undo
4 4
 
5 5
 use Exception;
6 6
 
7
-trait CheckTrait{
7
+trait CheckTrait {
8 8
 
9
-    protected function check_viewExist(string $viewfile){
10
-        if(!file_exists($this->path . $viewfile . '.view.php')){
11
-            $v = $this->path . $viewfile;
9
+    protected function check_viewExist(string $viewfile) {
10
+        if (!file_exists($this->path.$viewfile.'.view.php')) {
11
+            $v = $this->path.$viewfile;
12 12
             throw new Exception("Preview file {$v} not found");
13 13
         }
14 14
     }
Please login to merge, or discard this patch.
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
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.
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.
src/Viewer.php 2 patches
Spacing   +7 added lines, -7 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
-class Viewer{
5
+class Viewer {
6 6
     use EspecialHelperTrait, CheckTrait;
7 7
 
8 8
     private static $instance = null;
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
     public static function getInstance(string $path): Viewer
17 17
     {
18
-        if(is_null(self::$instance)){
18
+        if (is_null(self::$instance)) {
19 19
             self::$instance = new self();
20 20
         }
21 21
         self::$instance->path = $path;
@@ -29,20 +29,20 @@  discard block
 block discarded – undo
29 29
 
30 30
     public function render(string $file, array $data = [], bool $return = false): string
31 31
     {
32
-        if(!headers_sent()){
32
+        if (!headers_sent()) {
33 33
             header('Content-Type: text/html; charset=utf-8');
34 34
         }
35 35
         
36 36
         $this->check_viewExist($file);
37 37
 
38
-        $buffer = $this->getOB($this->path . DIRECTORY_SEPARATOR . $file . '.view.php', $data);
38
+        $buffer = $this->getOB($this->path.DIRECTORY_SEPARATOR.$file.'.view.php', $data);
39 39
         
40 40
         $buffer = $this->getVars($buffer);
41 41
         $buffer = $this->getEspecialVars($buffer);
42 42
         
43 43
         $buffer = $this->removeComments($buffer);
44 44
 
45
-        if(!$return){
45
+        if (!$return) {
46 46
             echo $buffer;
47 47
             return '';
48 48
         }
@@ -52,12 +52,12 @@  discard block
 block discarded – undo
52 52
 
53 53
     public function include(string $file): void
54 54
     {
55
-        try{
55
+        try {
56 56
             $buffer = $this->getOB($this->path.$file.'.inc.php');
57 57
             $buffer = $this->getVars($buffer);
58 58
             $buffer = $this->getEspecialVars($buffer);
59 59
             echo $buffer;
60
-        }catch(\Exception $er){
60
+        }catch (\Exception $er) {
61 61
             echo "<div class='view error'>Component error: {$er->getMessage()}</div>";
62 62
         }
63 63
     }
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@
 block discarded – undo
57 57
             $buffer = $this->getVars($buffer);
58 58
             $buffer = $this->getEspecialVars($buffer);
59 59
             echo $buffer;
60
-        }catch(\Exception $er){
60
+        } catch(\Exception $er){
61 61
             echo "<div class='view error'>Component error: {$er->getMessage()}</div>";
62 62
         }
63 63
     }
Please login to merge, or discard this patch.
src/EspecialHelperTrait.php 1 patch
Spacing   +14 added lines, -14 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,14 +41,14 @@  discard block
 block discarded – undo
41 41
 
42 42
     protected function replaceEspecialObject(string $buffer, object $obj, ?string $prefix, string $key): string
43 43
     {
44
-        $vars = method_exists($obj,'getVars') ? $obj->getVars() : [];
44
+        $vars = method_exists($obj, 'getVars') ? $obj->getVars() : [];
45 45
         $vars = array_merge($vars, get_object_vars($obj));
46
-        foreach($vars as $field => $val){
46
+        foreach ($vars as $field => $val) {
47 47
             
48
-            $buffer = $this->replaceEspecialValue($buffer, $val, $key.'.'.$field.'.' , $field);
48
+            $buffer = $this->replaceEspecialValue($buffer, $val, $key.'.'.$field.'.', $field);
49 49
 
50
-            while(strstr($buffer,'{{!! $'.$prefix.$key.'.'.$field.' !!}}')){
51
-                $buffer = str_replace('{{!! $'.$prefix.$key.'.'.$field.' !!}}', $obj->$field ,$buffer);
50
+            while (strstr($buffer, '{{!! $'.$prefix.$key.'.'.$field.' !!}}')) {
51
+                $buffer = str_replace('{{!! $'.$prefix.$key.'.'.$field.' !!}}', $obj->$field, $buffer);
52 52
             }
53 53
         }
54 54
         return $buffer;
@@ -56,11 +56,11 @@  discard block
 block discarded – undo
56 56
 
57 57
     protected function replaceEspecialArray(string $buffer, array $array, ?string $prefix = '', ?string $key = ''): string
58 58
     {
59
-        foreach($array as $field => $val){
60
-            $buffer = $this->replaceEspecialValue($buffer, $val, $key.'.'.$field.'.' , $field);
59
+        foreach ($array as $field => $val) {
60
+            $buffer = $this->replaceEspecialValue($buffer, $val, $key.'.'.$field.'.', $field);
61 61
 
62
-            while(strstr($buffer,'{{!! $'.$prefix.$key.'.'.$field.' !!}}')){
63
-                $buffer = str_replace('{{!! $'.$prefix.$key.'.'.$field.' !!}}', $val ,$buffer);
62
+            while (strstr($buffer, '{{!! $'.$prefix.$key.'.'.$field.' !!}}')) {
63
+                $buffer = str_replace('{{!! $'.$prefix.$key.'.'.$field.' !!}}', $val, $buffer);
64 64
             }
65 65
         }
66 66
         return $buffer;
Please login to merge, or discard this patch.