Passed
Branch master (3f13ae)
by Henri
06:27 queued 05:06
created
src/HelperTrait.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -4,35 +4,35 @@  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
 
16
-        if(!file_exists($require)){
16
+        if (!file_exists($require)) {
17 17
             $require = basename($require);
18 18
             throw new Exception("Importation file does not exist: {$require} .");
19 19
         }
20 20
         
21 21
         $this->initData();
22 22
 
23
-        $_SESSION['data'] = (!empty($data)) ? array_merge($data,$_SESSION['data']) : $_SESSION['data'];
23
+        $_SESSION['data'] = (!empty($data)) ? array_merge($data, $_SESSION['data']) : $_SESSION['data'];
24 24
 
25 25
         ob_start();
26 26
         require($require);
27 27
         $response = ob_get_contents();
28 28
         ob_end_clean();
29 29
 
30
-        $response = explode(PHP_EOL,$response);
31
-        foreach($response as $index => $value){
30
+        $response = explode(PHP_EOL, $response);
31
+        foreach ($response as $index => $value) {
32 32
             $response[$index] = ltrim($value);
33 33
         }
34 34
         
35
-        return implode('',$response);
35
+        return implode('', $response);
36 36
     }
37 37
 
38 38
     protected function initData()
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
         $_SESSION['data'] = (empty($_SESSION['data'])) ? null : $_SESSION['data'];
41 41
     }
42 42
 
43
-    protected function getVars(string $buffer,string $prefix = null, ?array $values = null): string
43
+    protected function getVars(string $buffer, string $prefix = null, ?array $values = null): string
44 44
     {
45 45
         $this->initData();
46 46
 
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
     protected function replace_vars($buffer, $vars, $prefix): string
53 53
     {
54 54
         foreach ($vars as $key => $value) {
55
-            switch(gettype($value)){
55
+            switch (gettype($value)) {
56 56
                 case 'array':
57 57
                     $buffer = $this->replace_Array($buffer, $value, $prefix, $key);
58 58
                     break;
@@ -70,9 +70,9 @@  discard block
 block discarded – undo
70 70
 
71 71
     protected function replace_value(string $buffer, $value, ?string $prefix, string $key): string
72 72
     {
73
-        if(gettype($value)!=='array' && gettype($value)!=='object'){
74
-            while(strstr($buffer,'{{ $'.$prefix.$key.' }}')){
75
-                $buffer = str_replace('{{ $'.$prefix.$key.' }}', htmlspecialchars($value) ,$buffer);
73
+        if (gettype($value)!=='array' && gettype($value)!=='object') {
74
+            while (strstr($buffer, '{{ $'.$prefix.$key.' }}')) {
75
+                $buffer = str_replace('{{ $'.$prefix.$key.' }}', htmlspecialchars($value), $buffer);
76 76
             }
77 77
         }
78 78
         return $buffer;
@@ -80,12 +80,12 @@  discard block
 block discarded – undo
80 80
 
81 81
     protected function replace_Object(string $buffer, object $obj, string $prefix, string $key): string
82 82
     {
83
-        foreach($obj->get_object_vars() as $field => $val){
83
+        foreach ($obj->get_object_vars() as $field => $val) {
84 84
             
85
-            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.' , $field);
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.' }}', htmlspecialchars($val) ,$buffer);
87
+            while (strstr($buffer, '{{ $'.$prefix.$key.'.'.$field.' }}')) {
88
+                $buffer = str_replace('{{ $'.$prefix.$key.'.'.$field.' }}', htmlspecialchars($val), $buffer);
89 89
             }
90 90
         }
91 91
         return $buffer;
@@ -93,11 +93,11 @@  discard block
 block discarded – undo
93 93
 
94 94
     protected function replace_Array(string $buffer, array $array, ?string $prefix = '', ?string $key = ''): string
95 95
     {
96
-        foreach($array as $field => $val){
97
-            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.' , $field);
96
+        foreach ($array as $field => $val) {
97
+            $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.', $field);
98 98
 
99
-            while(strstr($buffer,'{{ $'.$prefix.$key.'.'.$field.' }}')){
100
-                $buffer = str_replace('{{ $'.$prefix.$key.'.'.$field.' }}', htmlspecialchars($val) ,$buffer);
99
+            while (strstr($buffer, '{{ $'.$prefix.$key.'.'.$field.' }}')) {
100
+                $buffer = str_replace('{{ $'.$prefix.$key.'.'.$field.' }}', htmlspecialchars($val), $buffer);
101 101
             }
102 102
         }
103 103
         return $buffer;
@@ -105,25 +105,25 @@  discard block
 block discarded – undo
105 105
 
106 106
     protected function removeComments(string $buffer): string
107 107
     {
108
-        while(strstr($buffer,'<!--')){
108
+        while (strstr($buffer, '<!--')) {
109 109
             $comment = substr(
110 110
                 $buffer,
111
-                strpos($buffer,'<!--'),
112
-                strpos(strstr($buffer,'<!--'),'-->')+3
111
+                strpos($buffer, '<!--'),
112
+                strpos(strstr($buffer, '<!--'), '-->')+3
113 113
             );
114
-            $buffer = str_replace($comment,'',$buffer);
114
+            $buffer = str_replace($comment, '', $buffer);
115 115
         }
116 116
         return $buffer;
117 117
     }
118 118
 
119 119
     protected function saveData(): bool
120 120
     {   
121
-        if(session_status() !== PHP_SESSION_ACTIVE){
121
+        if (session_status()!==PHP_SESSION_ACTIVE) {
122 122
             return false;
123 123
         }
124 124
         unset($_SESSION['data']);
125 125
 
126
-        if(!empty($_SESSION['save'])){
126
+        if (!empty($_SESSION['save'])) {
127 127
             foreach ($_SESSION['save'] as $key => $value) {
128 128
                 $_SESSION['data'][$key] = $value;
129 129
             }
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/EspecialHelperTrait.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -4,10 +4,10 @@  discard block
 block discarded – undo
4 4
 
5 5
 use Exception;
6 6
 
7
-trait EspecialHelperTrait{
7
+trait EspecialHelperTrait {
8 8
     use HelperTrait;
9 9
 
10
-    protected function getEspecialVars(string $buffer,string $prefix = null, ?array $values = null): string
10
+    protected function getEspecialVars(string $buffer, string $prefix = null, ?array $values = null): string
11 11
     {
12 12
         $this->initData();
13 13
 
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
     protected function replaceEspecialVars($buffer, $vars, $prefix): string
20 20
     {
21 21
         foreach ($vars as $key => $value) {
22
-            switch(gettype($value)){
22
+            switch (gettype($value)) {
23 23
                 case 'array':
24 24
                     $buffer = $this->replaceEspecialArray($buffer, $value, $prefix, $key);
25 25
                     break;
@@ -37,9 +37,9 @@  discard block
 block discarded – undo
37 37
 
38 38
     protected function replaceEspecialValue(string $buffer, $value, ?string $prefix, string $key): string
39 39
     {
40
-        if(gettype($value)!=='array' && gettype($value)!=='object'){
41
-            while(strstr($buffer,'{{!! $'.$prefix.$key.' !!}}')){
42
-                $buffer = str_replace('{{!! $'.$prefix.$key.' !!}}', $value ,$buffer);
40
+        if (gettype($value)!=='array' && gettype($value)!=='object') {
41
+            while (strstr($buffer, '{{!! $'.$prefix.$key.' !!}}')) {
42
+                $buffer = str_replace('{{!! $'.$prefix.$key.' !!}}', $value, $buffer);
43 43
             }
44 44
         }
45 45
         return $buffer;
@@ -47,12 +47,12 @@  discard block
 block discarded – undo
47 47
 
48 48
     protected function replaceEspecialObject(string $buffer, object $obj, string $prefix, string $key): string
49 49
     {
50
-        foreach($obj->get_object_vars() as $field => $val){
50
+        foreach ($obj->get_object_vars() as $field => $val) {
51 51
             
52
-            $buffer = $this->replaceEspecialValue($buffer, $val, $key.'.'.$field.'.' , $field);
52
+            $buffer = $this->replaceEspecialValue($buffer, $val, $key.'.'.$field.'.', $field);
53 53
 
54
-            while(strstr($buffer,'{{!! $'.$prefix.$key.'.'.$field.' !!}}')){
55
-                $buffer = str_replace('{{!! $'.$prefix.$key.'.'.$field.' !!}}', $val ,$buffer);
54
+            while (strstr($buffer, '{{!! $'.$prefix.$key.'.'.$field.' !!}}')) {
55
+                $buffer = str_replace('{{!! $'.$prefix.$key.'.'.$field.' !!}}', $val, $buffer);
56 56
             }
57 57
         }
58 58
         return $buffer;
@@ -60,11 +60,11 @@  discard block
 block discarded – undo
60 60
 
61 61
     protected function replaceEspecialArray(string $buffer, array $array, ?string $prefix = '', ?string $key = ''): string
62 62
     {
63
-        foreach($array as $field => $val){
64
-            $buffer = $this->replaceEspecialValue($buffer, $val, $key.'.'.$field.'.' , $field);
63
+        foreach ($array as $field => $val) {
64
+            $buffer = $this->replaceEspecialValue($buffer, $val, $key.'.'.$field.'.', $field);
65 65
 
66
-            while(strstr($buffer,'{{!! $'.$prefix.$key.'.'.$field.' !!}}')){
67
-                $buffer = str_replace('{{!! $'.$prefix.$key.'.'.$field.' !!}}', $val ,$buffer);
66
+            while (strstr($buffer, '{{!! $'.$prefix.$key.'.'.$field.' !!}}')) {
67
+                $buffer = str_replace('{{!! $'.$prefix.$key.'.'.$field.' !!}}', $val, $buffer);
68 68
             }
69 69
         }
70 70
         return $buffer;
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,13 +29,13 @@  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);
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 
45 45
         $this->saveData();
46 46
 
47
-        if(!$return){
47
+        if (!$return) {
48 48
             echo $buffer;
49 49
             return '';
50 50
         }
@@ -55,11 +55,11 @@  discard block
 block discarded – undo
55 55
     public function include(string $file): void
56 56
     {
57 57
         $buffer = '';
58
-        try{
58
+        try {
59 59
             $buffer = $this->getOB($this->path.$file.'.tpl.php');
60 60
             $buffer = $this->getVars($buffer);
61 61
             $buffer = $this->getEspecialVars($buffer);
62
-        }catch(\Exception $er){
62
+        }catch (\Exception $er) {
63 63
             $buffer = "<div class='view error'>Component error: {$er->getMessage()}</div>";
64 64
         }
65 65
         echo $buffer;
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@
 block discarded – undo
59 59
             $buffer = $this->getOB($this->path.$file.'.tpl.php');
60 60
             $buffer = $this->getVars($buffer);
61 61
             $buffer = $this->getEspecialVars($buffer);
62
-        }catch(\Exception $er){
62
+        } catch(\Exception $er){
63 63
             $buffer = "<div class='view error'>Component error: {$er->getMessage()}</div>";
64 64
         }
65 65
         echo $buffer;
Please login to merge, or discard this patch.