Passed
Branch master (a48404)
by Henri
01:21
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   +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 1 patch
Spacing   +24 added lines, -24 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
 
@@ -20,15 +20,15 @@  discard block
 block discarded – undo
20 20
         $response = ob_get_contents();
21 21
         ob_end_clean();
22 22
 
23
-        $response = explode(PHP_EOL,$response);
24
-        foreach($response as $index => $value){
23
+        $response = explode(PHP_EOL, $response);
24
+        foreach ($response as $index => $value) {
25 25
             $response[$index] = ltrim($value);
26 26
         }
27 27
         
28
-        return implode('',$response);
28
+        return implode('', $response);
29 29
     }
30 30
 
31
-    protected function getVars(string $buffer,string $prefix = null, ?array $values = null): string
31
+    protected function getVars(string $buffer, string $prefix = null, ?array $values = null): string
32 32
     {
33 33
         $_SESSION['data'] = (empty($_SESSION['data'])) ? null : $_SESSION['data'];
34 34
 
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
     protected function replace_vars($buffer, $vars, $prefix): string
41 41
     {
42 42
         foreach ($vars as $key => $value) {
43
-            switch(gettype($value)){
43
+            switch (gettype($value)) {
44 44
                 case 'array':
45 45
                     $buffer = $this->replace_Array($buffer, $value, $prefix, $key);
46 46
                     break;
@@ -58,9 +58,9 @@  discard block
 block discarded – undo
58 58
 
59 59
     protected function replace_value(string $buffer, $value, string $prefix, string $key): string
60 60
     {
61
-        if(gettype($value)!=='array' && gettype($value)!=='object'){
62
-            while(strstr($buffer,'{{'.$prefix.$key.'}}')){
63
-                $buffer = str_replace('{{'.$prefix.$key.'}}', $value ,$buffer);
61
+        if (gettype($value)!=='array' && gettype($value)!=='object') {
62
+            while (strstr($buffer, '{{'.$prefix.$key.'}}')) {
63
+                $buffer = str_replace('{{'.$prefix.$key.'}}', $value, $buffer);
64 64
             }
65 65
         }
66 66
         return $buffer;
@@ -68,12 +68,12 @@  discard block
 block discarded – undo
68 68
 
69 69
     protected function replace_Object(string $buffer, object $obj, string $prefix, string $key): string
70 70
     {
71
-        foreach($obj->get_object_vars() as $field => $val){
71
+        foreach ($obj->get_object_vars() as $field => $val) {
72 72
             
73
-            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.' , $field);
73
+            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.', $field);
74 74
 
75
-            while(strstr($buffer,'{{'.$prefix.$key.'.'.$field.'}}')){
76
-                $buffer = str_replace('{{'.$prefix.$key.'.'.$field.'}}',$val ,$buffer);
75
+            while (strstr($buffer, '{{'.$prefix.$key.'.'.$field.'}}')) {
76
+                $buffer = str_replace('{{'.$prefix.$key.'.'.$field.'}}', $val, $buffer);
77 77
             }
78 78
         }
79 79
         return $buffer;
@@ -81,11 +81,11 @@  discard block
 block discarded – undo
81 81
 
82 82
     protected function replace_Array(string $buffer, array $array, ?string $prefix = '', ?string $key = ''): string
83 83
     {
84
-        foreach($array as $field => $val){
85
-            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.' , $field);
84
+        foreach ($array as $field => $val) {
85
+            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.', $field);
86 86
 
87
-            while(strstr($buffer,'{{'.$prefix.$key.'.'.$field.'}}')){
88
-                $buffer = str_replace('{{'.$prefix.$key.'.'.$field.'}}',$val,$buffer);
87
+            while (strstr($buffer, '{{'.$prefix.$key.'.'.$field.'}}')) {
88
+                $buffer = str_replace('{{'.$prefix.$key.'.'.$field.'}}', $val, $buffer);
89 89
             }
90 90
         }
91 91
         return $buffer;
@@ -93,25 +93,25 @@  discard block
 block discarded – undo
93 93
 
94 94
     protected function removeComments(string $buffer): string
95 95
     {
96
-        while(strstr($buffer,'<!--')){
96
+        while (strstr($buffer, '<!--')) {
97 97
             $comment = substr(
98 98
                 $buffer,
99
-                strpos($buffer,'<!--'),
100
-                strpos(strstr($buffer,'<!--'),'-->')+3
99
+                strpos($buffer, '<!--'),
100
+                strpos(strstr($buffer, '<!--'), '-->')+3
101 101
             );
102
-            $buffer = str_replace($comment,'',$buffer);
102
+            $buffer = str_replace($comment, '', $buffer);
103 103
         }
104 104
         return $buffer;
105 105
     }
106 106
 
107 107
     protected function saveData(): bool
108 108
     {   
109
-        if(session_status() !== PHP_SESSION_ACTIVE){
109
+        if (session_status()!==PHP_SESSION_ACTIVE) {
110 110
             return false;
111 111
         }
112 112
         unset($_SESSION['data']);
113 113
 
114
-        if(!empty($_SESSION['save'])){
114
+        if (!empty($_SESSION['save'])) {
115 115
             foreach ($_SESSION['save'] as $key => $value) {
116 116
                 $_SESSION['data'][$key] = $value;
117 117
             }
Please login to merge, or discard this patch.
src/Viewer.php 1 patch
Spacing   +4 added lines, -4 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 HelperTrait, CheckTrait;
7 7
 
8 8
     private static $instance = null;
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 
17 17
     public static function getInstance(string $path): Viewer
18 18
     {
19
-        if(is_null(self::$instance)){
19
+        if (is_null(self::$instance)) {
20 20
             self::$instance = new self($path);
21 21
         }
22 22
         return self::$instance;
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
         
34 34
         $this->check_viewExist($file);
35 35
 
36
-        $buffer = $this->getOB($this->path . DIRECTORY_SEPARATOR . $file . '.view.php', $data);
36
+        $buffer = $this->getOB($this->path.DIRECTORY_SEPARATOR.$file.'.view.php', $data);
37 37
         
38 38
         $buffer = $this->getVars($buffer);
39 39
         
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 
42 42
         $this->saveData();
43 43
 
44
-        if(!$return){
44
+        if (!$return) {
45 45
             echo $buffer;
46 46
             return '';
47 47
         }
Please login to merge, or discard this patch.