Passed
Push — master ( a7f4c5...36cdac )
by Henri
01:18
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/HelperTrait.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -2,12 +2,12 @@  discard block
 block discarded – undo
2 2
 
3 3
 namespace HnrAzevedo\Viewer;
4 4
 
5
-trait HelperTrait{
5
+trait HelperTrait {
6 6
     use CheckTrait;
7 7
 
8 8
     protected function getOB(string $require, array $data = []): string
9 9
     {
10
-        foreach($data as $variable => $value){
10
+        foreach ($data as $variable => $value) {
11 11
             $$variable = $value;
12 12
         }
13 13
 
@@ -16,15 +16,15 @@  discard block
 block discarded – undo
16 16
         $response = ob_get_contents();
17 17
         ob_end_clean();
18 18
 
19
-        $response = explode(PHP_EOL,$response);
20
-        foreach($response as $index => $value){
19
+        $response = explode(PHP_EOL, $response);
20
+        foreach ($response as $index => $value) {
21 21
             $response[$index] = ltrim($value);
22 22
         }
23 23
         
24
-        return implode('',$response);
24
+        return implode('', $response);
25 25
     }
26 26
 
27
-    protected function getVars(string $buffer,string $prefix = null, ?array $values = null): string
27
+    protected function getVars(string $buffer, string $prefix = null, ?array $values = null): string
28 28
     {
29 29
         $_SESSION['data'] = (empty($_SESSION['data'])) ? null : $_SESSION['data'];
30 30
 
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
     protected function replace_vars($buffer, $vars, $prefix): string
37 37
     {
38 38
         foreach ($vars as $key => $value) {
39
-            switch(gettype($value)){
39
+            switch (gettype($value)) {
40 40
                 case 'array':
41 41
                     $buffer = $this->replace_Array($buffer, $value, $prefix, $key);
42 42
                     break;
@@ -54,9 +54,9 @@  discard block
 block discarded – undo
54 54
 
55 55
     protected function replace_value(string $buffer, $value, string $prefix, string $key): string
56 56
     {
57
-        if(gettype($value)!=='array' && gettype($value)!=='object'){
58
-            while(strstr($buffer,'{{ '.$prefix.$key.' }}')){
59
-                $buffer = str_replace('{{ '.$prefix.$key.' }}', $value ,$buffer);
57
+        if (gettype($value)!=='array' && gettype($value)!=='object') {
58
+            while (strstr($buffer, '{{ '.$prefix.$key.' }}')) {
59
+                $buffer = str_replace('{{ '.$prefix.$key.' }}', $value, $buffer);
60 60
             }
61 61
         }
62 62
         return $buffer;
@@ -64,12 +64,12 @@  discard block
 block discarded – undo
64 64
 
65 65
     protected function replace_Object(string $buffer, object $obj, string $prefix, string $key): string
66 66
     {
67
-        foreach($obj->get_object_vars() as $field => $val){
67
+        foreach ($obj->get_object_vars() as $field => $val) {
68 68
             
69
-            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.' , $field);
69
+            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.', $field);
70 70
 
71
-            while(strstr($buffer,'{{ '.$prefix.$key.'.'.$field.' }}')){
72
-                $buffer = str_replace('{{ '.$prefix.$key.'.'.$field.' }}',$val ,$buffer);
71
+            while (strstr($buffer, '{{ '.$prefix.$key.'.'.$field.' }}')) {
72
+                $buffer = str_replace('{{ '.$prefix.$key.'.'.$field.' }}', $val, $buffer);
73 73
             }
74 74
         }
75 75
         return $buffer;
@@ -77,11 +77,11 @@  discard block
 block discarded – undo
77 77
 
78 78
     protected function replace_Array(string $buffer, array $array, string $prefix, string $key): string
79 79
     {
80
-        foreach($array as $field => $val){
81
-            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.' , $field);
80
+        foreach ($array as $field => $val) {
81
+            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.', $field);
82 82
 
83
-            while(strstr($buffer,'{{ '.$prefix.$key.'.'.$field.' }}')){
84
-                $buffer = str_replace('{{ '.$prefix.$key.'.'.$field.' }}',$val,$buffer);
83
+            while (strstr($buffer, '{{ '.$prefix.$key.'.'.$field.' }}')) {
84
+                $buffer = str_replace('{{ '.$prefix.$key.'.'.$field.' }}', $val, $buffer);
85 85
             }
86 86
         }
87 87
         return $buffer;
@@ -89,39 +89,39 @@  discard block
 block discarded – undo
89 89
 
90 90
     protected function removeComments(string $buffer): string
91 91
     {
92
-        while(strstr($buffer,'<!--')){
92
+        while (strstr($buffer, '<!--')) {
93 93
             $comment = substr(
94 94
                 $buffer,
95
-                strpos($buffer,'<!--'),
96
-                strpos(strstr($buffer,'<!--'),'-->')+3
95
+                strpos($buffer, '<!--'),
96
+                strpos(strstr($buffer, '<!--'), '-->')+3
97 97
             );
98
-            $buffer = str_replace($comment,'',$buffer);
98
+            $buffer = str_replace($comment, '', $buffer);
99 99
         }
100 100
         return $buffer;
101 101
     }
102 102
 
103 103
     protected function getImport(string $buffer): string
104 104
     {
105
-        while(strstr($buffer,'@import')){
105
+        while (strstr($buffer, '@import')) {
106 106
             $buffer = $this->getVars($buffer);
107 107
 
108 108
             $import = substr(
109 109
                 $buffer,
110
-                strpos($buffer,'@import(\''),
111
-                strpos(strstr($buffer,'@import'),'\')')+2
110
+                strpos($buffer, '@import(\''),
111
+                strpos(strstr($buffer, '@import'), '\')')+2
112 112
             );
113 113
 
114 114
             $tpl = $this->check_importExist($import);
115 115
 
116
-            try{
117
-                $buffer_tpl = $this->getOB($this->path . DIRECTORY_SEPARATOR . $tpl . '.tpl.php');
118
-            }catch(\Exception $er){
116
+            try {
117
+                $buffer_tpl = $this->getOB($this->path.DIRECTORY_SEPARATOR.$tpl.'.tpl.php');
118
+            }catch (\Exception $er) {
119 119
                 var_dump($er);
120 120
                 die();
121 121
             }
122 122
             
123 123
             $buffer_tpl = $this->getVars($buffer_tpl);
124
-            $buffer = str_replace($import,$buffer_tpl,$buffer);
124
+            $buffer = str_replace($import, $buffer_tpl, $buffer);
125 125
         }
126 126
 
127 127
         return $buffer;
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
 
130 130
     protected function saveData(): bool
131 131
     {   
132
-        if(session_status() !== PHP_SESSION_ACTIVE){
132
+        if (session_status()!==PHP_SESSION_ACTIVE) {
133 133
             return false;
134 134
         }
135 135
         unset($_SESSION['data']);
136 136
 
137
-        if(!empty($_SESSION['save'])){
137
+        if (!empty($_SESSION['save'])) {
138 138
             foreach ($_SESSION['save'] as $key => $value) {
139 139
                 $_SESSION['data'][$key] = $value;
140 140
             }
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.