Passed
Branch master (af8266)
by Henri
02:51 queued 01:38
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.
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
         ['param1' => 1],
@@ -18,7 +18,7 @@  discard block
 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.
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.
src/Viewer.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -2,25 +2,25 @@  discard block
 block discarded – undo
2 2
 
3 3
 namespace HnrAzevedo\Viewer;
4 4
 
5
-class Viewer{
5
+class Viewer {
6 6
     use HelperTrait, CheckTrait;
7 7
 
8 8
     private static $instance = null;
9 9
     private string $path = '';
10 10
 
11
-    public function __construct(string $path){
11
+    public function __construct(string $path) {
12 12
         $this->path = $path;
13 13
         return $this;
14 14
     }
15 15
 
16
-    public static function getInstance(string $path){
17
-        if(is_null(self::$instance)){
16
+    public static function getInstance(string $path) {
17
+        if (is_null(self::$instance)) {
18 18
             self::$instance = new self($path);
19 19
         }
20 20
         return self::$instance;
21 21
     }
22 22
 
23
-    public static function create(string $path){
23
+    public static function create(string $path) {
24 24
         return self::getInstance($path);
25 25
     }
26 26
 
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
         
31 31
         $this->check_viewExist($file);
32 32
 
33
-        $buffer = $this->getOB($this->path . DIRECTORY_SEPARATOR . $file . '.view.php', $data);
33
+        $buffer = $this->getOB($this->path.DIRECTORY_SEPARATOR.$file.'.view.php', $data);
34 34
         
35 35
         $buffer = $this->getVars($buffer);
36 36
         
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 
41 41
         $this->saveData();
42 42
 
43
-        if(!$return){
43
+        if (!$return) {
44 44
             echo $buffer;
45 45
             return '';
46 46
         }
Please login to merge, or discard this patch.
src/CheckTrait.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -4,27 +4,27 @@
 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
     }
15 15
 
16 16
     protected function check_importExist($import): string
17 17
     {
18
-        $tpl = str_replace('.',DIRECTORY_SEPARATOR,
18
+        $tpl = str_replace('.', DIRECTORY_SEPARATOR,
19 19
                 substr(
20 20
                     $import,
21
-                    strpos($import,'\'')+1,
21
+                    strpos($import, '\'')+1,
22 22
                     strlen($import)-11
23 23
                 )
24 24
             );
25 25
 
26
-        if(!file_exists($this->path . DIRECTORY_SEPARATOR . $tpl . '.tpl.php')){
27
-            throw new Exception('Import \''.str_replace(['@import(\'','\')'],'',$import).'\' não encontrado.');
26
+        if (!file_exists($this->path.DIRECTORY_SEPARATOR.$tpl.'.tpl.php')) {
27
+            throw new Exception('Import \''.str_replace(['@import(\'', '\')'], '', $import).'\' não encontrado.');
28 28
         }
29 29
         return $tpl;
30 30
     }
Please login to merge, or discard this patch.
src/HelperTrait.php 2 patches
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -4,12 +4,12 @@  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 => $value){
12
+        foreach ($data as $variable => $value) {
13 13
             $$variable = $value;
14 14
         }
15 15
 
@@ -18,15 +18,15 @@  discard block
 block discarded – undo
18 18
         $response = ob_get_contents();
19 19
         ob_end_clean();
20 20
 
21
-        $response = explode(PHP_EOL,$response);
22
-        foreach($response as $index => $value){
21
+        $response = explode(PHP_EOL, $response);
22
+        foreach ($response as $index => $value) {
23 23
             $response[$index] = ltrim($value);
24 24
         }
25 25
         
26
-        return implode('',$response);
26
+        return implode('', $response);
27 27
     }
28 28
 
29
-    protected function getVars(string $buffer,string $prefix = null, ?array $values = null): string
29
+    protected function getVars(string $buffer, string $prefix = null, ?array $values = null): string
30 30
     {
31 31
         $_SESSION['data'] = (empty($_SESSION['data'])) ? null : $_SESSION['data'];
32 32
 
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
     protected function replace_vars($buffer, $vars, $prefix): string
39 39
     {
40 40
         foreach ($vars as $key => $value) {
41
-            switch(gettype($value)){
41
+            switch (gettype($value)) {
42 42
                 case 'array':
43 43
                     $buffer = $this->replace_Array($buffer, $value, $prefix, $key);
44 44
                     break;
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
 
57 57
     protected function replace_value(string $buffer, $value, string $prefix, string $key): string
58 58
     {
59
-        if(gettype($value)!=='array' && gettype($value)!=='object'){
60
-            while(strstr($buffer,'{{ '.$prefix.$key.' }}')){
61
-                $buffer = str_replace('{{ '.$prefix.$key.' }}', $value ,$buffer);
59
+        if (gettype($value)!=='array' && gettype($value)!=='object') {
60
+            while (strstr($buffer, '{{ '.$prefix.$key.' }}')) {
61
+                $buffer = str_replace('{{ '.$prefix.$key.' }}', $value, $buffer);
62 62
             }
63 63
         }
64 64
         return $buffer;
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 
67 67
     protected function replace_Object(string $buffer, object $obj, string $prefix, string $key): string
68 68
     {
69
-        foreach($obj->get_object_vars() as $field => $val){
69
+        foreach ($obj->get_object_vars() as $field => $val) {
70 70
             
71
-            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.' , $field);
71
+            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.', $field);
72 72
 
73
-            while(strstr($buffer,'{{ '.$prefix.$key.'.'.$field.' }}')){
74
-                $buffer = str_replace('{{ '.$prefix.$key.'.'.$field.' }}',$val ,$buffer);
73
+            while (strstr($buffer, '{{ '.$prefix.$key.'.'.$field.' }}')) {
74
+                $buffer = str_replace('{{ '.$prefix.$key.'.'.$field.' }}', $val, $buffer);
75 75
             }
76 76
         }
77 77
         return $buffer;
@@ -79,11 +79,11 @@  discard block
 block discarded – undo
79 79
 
80 80
     protected function replace_Array(string $buffer, array $array, string $prefix, string $key): string
81 81
     {
82
-        foreach($array as $field => $val){
83
-            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.' , $field);
82
+        foreach ($array as $field => $val) {
83
+            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.', $field);
84 84
 
85
-            while(strstr($buffer,'{{ '.$prefix.$key.'.'.$field.' }}')){
86
-                $buffer = str_replace('{{ '.$prefix.$key.'.'.$field.' }}',$val,$buffer);
85
+            while (strstr($buffer, '{{ '.$prefix.$key.'.'.$field.' }}')) {
86
+                $buffer = str_replace('{{ '.$prefix.$key.'.'.$field.' }}', $val, $buffer);
87 87
             }
88 88
         }
89 89
         return $buffer;
@@ -91,38 +91,38 @@  discard block
 block discarded – undo
91 91
 
92 92
     protected function removeComments(string $buffer): string
93 93
     {
94
-        while(strstr($buffer,'<!--')){
94
+        while (strstr($buffer, '<!--')) {
95 95
             $comment = substr(
96 96
                 $buffer,
97
-                strpos($buffer,'<!--'),
98
-                strpos(strstr($buffer,'<!--'),'-->')+3
97
+                strpos($buffer, '<!--'),
98
+                strpos(strstr($buffer, '<!--'), '-->')+3
99 99
             );
100
-            $buffer = str_replace($comment,'',$buffer);
100
+            $buffer = str_replace($comment, '', $buffer);
101 101
         }
102 102
         return $buffer;
103 103
     }
104 104
 
105 105
     protected function getImport(string $buffer, array $data = []): string
106 106
     {
107
-        while(strstr($buffer,'@import')){
107
+        while (strstr($buffer, '@import')) {
108 108
             $buffer = $this->getVars($buffer);
109 109
 
110 110
             $import = substr(
111 111
                 $buffer,
112
-                strpos($buffer,'@import(\''),
113
-                strpos(strstr($buffer,'@import'),'\')')+2
112
+                strpos($buffer, '@import(\''),
113
+                strpos(strstr($buffer, '@import'), '\')')+2
114 114
             );
115 115
 
116 116
             $tpl = $this->check_importExist($import);
117 117
 
118
-            try{
119
-                $buffer_tpl = $this->getOB($this->path . DIRECTORY_SEPARATOR . $tpl . '.tpl.php', $data);
120
-            }catch(Exception $er){
118
+            try {
119
+                $buffer_tpl = $this->getOB($this->path.DIRECTORY_SEPARATOR.$tpl.'.tpl.php', $data);
120
+            }catch (Exception $er) {
121 121
                 throw $er;
122 122
             }
123 123
             
124 124
             $buffer_tpl = $this->getVars($buffer_tpl);
125
-            $buffer = str_replace($import,$buffer_tpl,$buffer);
125
+            $buffer = str_replace($import, $buffer_tpl, $buffer);
126 126
         }
127 127
 
128 128
         return $buffer;
@@ -130,12 +130,12 @@  discard block
 block discarded – undo
130 130
 
131 131
     protected function saveData(): bool
132 132
     {   
133
-        if(session_status() !== PHP_SESSION_ACTIVE){
133
+        if (session_status()!==PHP_SESSION_ACTIVE) {
134 134
             return false;
135 135
         }
136 136
         unset($_SESSION['data']);
137 137
 
138
-        if(!empty($_SESSION['save'])){
138
+        if (!empty($_SESSION['save'])) {
139 139
             foreach ($_SESSION['save'] as $key => $value) {
140 140
                 $_SESSION['data'][$key] = $value;
141 141
             }
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -117,7 +117,7 @@
 block discarded – undo
117 117
 
118 118
             try{
119 119
                 $buffer_tpl = $this->getOB($this->path . DIRECTORY_SEPARATOR . $tpl . '.tpl.php', $data);
120
-            }catch(Exception $er){
120
+            } catch(Exception $er){
121 121
                 throw $er;
122 122
             }
123 123
             
Please login to merge, or discard this patch.