Passed
Push — master ( 9d2f0c...c82b8d )
by Henri
01:28
created
src/Helper.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -14,13 +14,13 @@  discard block
 block discarded – undo
14 14
     {
15 15
         $this->data = array_merge($this->data, $data);
16 16
 
17
-        foreach($this->data as $variable => $_){
17
+        foreach ($this->data as $variable => $_) {
18 18
             $$variable = $_;
19 19
         }
20 20
         
21 21
         $_ = (isset($data['_'])) ?? $data['_'];
22 22
 
23
-        if(!file_exists($require)){
23
+        if (!file_exists($require)) {
24 24
             $require = basename($require);
25 25
             throw new \RuntimeException("Importation file does not exist: {$require}");
26 26
         }
@@ -41,13 +41,13 @@  discard block
 block discarded – undo
41 41
         $inScript = false;
42 42
         $inComment = false;
43 43
             
44
-        foreach($arrayHtml as $index => $value){
44
+        foreach ($arrayHtml as $index => $value) {
45 45
             $inScript = $this->checkInScript($inScript, $value);
46 46
             
47
-            if($inScript){
47
+            if ($inScript) {
48 48
                 $inComment = $this->checkCommentInScript($inComment, $value);
49 49
 
50
-                if(!$this->checkScriptNeed($inComment, $value)){
50
+                if (!$this->checkScriptNeed($inComment, $value)) {
51 51
                     continue;
52 52
                 }
53 53
                 
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
             $html[$index] = ltrim($value);
58 58
         }
59 59
         
60
-        return implode('',$html);
60
+        return implode('', $html);
61 61
     }
62 62
 
63 63
     protected function getVars(string $buffer, ?bool $treat = true): string
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
     protected function replaceVars(string $buffer, array $vars, ?string $prefix = ''): string
71 71
     {
72 72
         foreach ($vars as $key => $value) {
73
-            switch(gettype($value)){
73
+            switch (gettype($value)) {
74 74
                 case 'array':
75 75
                     $buffer = $this->replaceArray($buffer, $value, $prefix, $key);
76 76
                     break;
@@ -88,9 +88,9 @@  discard block
 block discarded – undo
88 88
 
89 89
     protected function replaceValue(string $buffer, $value, ?string $prefix, string $key): string
90 90
     {
91
-        if(is_scalar($value)){
92
-            while(strstr($buffer, "{{{$this->treat} \${$prefix}{$key} {$this->treat}}}")){
93
-                $buffer = str_replace("{{{$this->treat} \${$prefix}{$key} {$this->treat}}}", (($this->especial) ? htmlspecialchars($value) : $value) ,$buffer);
91
+        if (is_scalar($value)) {
92
+            while (strstr($buffer, "{{{$this->treat} \${$prefix}{$key} {$this->treat}}}")) {
93
+                $buffer = str_replace("{{{$this->treat} \${$prefix}{$key} {$this->treat}}}", (($this->especial) ? htmlspecialchars($value) : $value), $buffer);
94 94
             }
95 95
         }
96 96
 
@@ -99,22 +99,22 @@  discard block
 block discarded – undo
99 99
 
100 100
     protected function replaceObject(string $buffer, object $obj, ?string $prefix, string $key): string
101 101
     {
102
-        $vars = method_exists($obj,'getVars') ? $obj->getVars() : [];
102
+        $vars = method_exists($obj, 'getVars') ? $obj->getVars() : [];
103 103
         $vars = array_merge($vars, get_object_vars($obj));
104 104
 
105
-        foreach($vars as $field => $val){
106
-            $buffer = $this->replaceValue($buffer, $val, $key.'.' , $field);
105
+        foreach ($vars as $field => $val) {
106
+            $buffer = $this->replaceValue($buffer, $val, $key.'.', $field);
107 107
 
108
-            if(is_array($obj->$field)){
108
+            if (is_array($obj->$field)) {
109 109
                 $buffer = $this->replaceVars($buffer, $obj->$field, $key.'.'.$field.'.');
110 110
             }
111 111
         
112
-            if(is_object($obj->$field)){
112
+            if (is_object($obj->$field)) {
113 113
                 $buffer = $this->replaceObject($buffer, $obj->$field, $key.'.', $key.'.'.$field);
114 114
             }
115 115
 
116
-            while(strstr($buffer, "{{{$this->treat} \${$prefix}{$key}.{$field} {$this->treat}}}")){
117
-                $buffer = str_replace("{{{$this->treat} \${$prefix}{$key}.{$field} {$this->treat}}}", (($this->especial) ? htmlspecialchars($obj->$field) : $obj->$field) ,$buffer);
116
+            while (strstr($buffer, "{{{$this->treat} \${$prefix}{$key}.{$field} {$this->treat}}}")) {
117
+                $buffer = str_replace("{{{$this->treat} \${$prefix}{$key}.{$field} {$this->treat}}}", (($this->especial) ? htmlspecialchars($obj->$field) : $obj->$field), $buffer);
118 118
             }
119 119
             
120 120
         }
@@ -123,11 +123,11 @@  discard block
 block discarded – undo
123 123
 
124 124
     protected function replaceArray(string $buffer, array $array, ?string $prefix = '', ?string $key = ''): string
125 125
     {
126
-        foreach($array as $field => $val){
126
+        foreach ($array as $field => $val) {
127 127
             $buffer = $this->replaceValue($buffer, $val, $key.'.', $field);
128 128
 
129
-            while(strstr($buffer, "{{{$this->treat} \${$prefix}{$key}.{$field} {$this->treat}}}")){
130
-                $buffer = str_replace("{{{$this->treat} \${$prefix}{$key}.{$field} {$this->treat}}}", (($this->especial) ? htmlspecialchars($val) : $val) ,$buffer);
129
+            while (strstr($buffer, "{{{$this->treat} \${$prefix}{$key}.{$field} {$this->treat}}}")) {
130
+                $buffer = str_replace("{{{$this->treat} \${$prefix}{$key}.{$field} {$this->treat}}}", (($this->especial) ? htmlspecialchars($val) : $val), $buffer);
131 131
             }
132 132
         }
133 133
         return $buffer;
@@ -135,13 +135,13 @@  discard block
 block discarded – undo
135 135
 
136 136
     protected function removeComments(string $buffer): string
137 137
     {
138
-        while(strstr($buffer,'<!--')){
138
+        while (strstr($buffer, '<!--')) {
139 139
             $comment = substr(
140 140
                 $buffer,
141
-                strpos($buffer,'<!--'),
142
-                strpos(strstr($buffer,'<!--'),'-->')+3
141
+                strpos($buffer, '<!--'),
142
+                strpos(strstr($buffer, '<!--'), '-->')+3
143 143
             );
144
-            $buffer = str_replace($comment,'',$buffer);
144
+            $buffer = str_replace($comment, '', $buffer);
145 145
         }
146 146
         return $buffer;
147 147
     }
Please login to merge, or discard this patch.
src/ViewerInterface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@
 block discarded – undo
4 4
 
5 5
 use Psr\Http\Server\MiddlewareInterface;
6 6
 
7
-interface ViewerInterface extends MiddlewareInterface{
7
+interface ViewerInterface extends MiddlewareInterface {
8 8
     
9 9
     public static function import(string $file): void;
10 10
 
Please login to merge, or discard this patch.
src/Viewer.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -26,14 +26,14 @@  discard block
 block discarded – undo
26 26
 
27 27
     public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
28 28
     {
29
-        if(null === $request->getAttribute('viewer')){
29
+        if (null===$request->getAttribute('viewer')) {
30 30
             throw new \RuntimeException('The path and file parameters for viewing were not defined in the request');
31 31
         }
32 32
 
33 33
         self::$path = $request->getAttribute('viewer')['path'];
34 34
 
35 35
         $buffer = $this->getInstance()->render($request->getAttribute('viewer')['file'],
36
-            (isset($request->getAttribute('viewer')['data'])) ? $request->getAttribute('viewer')['data'] : [] );
36
+            (isset($request->getAttribute('viewer')['data'])) ? $request->getAttribute('viewer')['data'] : []);
37 37
 
38 38
         $request = $request->withBody((new Factory())->createStream($buffer));
39 39
 
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
     {
45 45
         self::getInstance()->data = $data;
46 46
         
47
-        if(!isset(self::$middleware)){
47
+        if (!isset(self::$middleware)) {
48 48
             self::getInstance()->handle($file);
49 49
             return '';
50 50
         }
@@ -61,14 +61,14 @@  discard block
 block discarded – undo
61 61
             new Uri($_SERVER['REQUEST_URI'])
62 62
         );
63 63
     
64
-        $serverRequest = $serverRequest->withAttribute('viewer',[
64
+        $serverRequest = $serverRequest->withAttribute('viewer', [
65 65
             'path' => self::$path,
66 66
             'file' => $file,
67 67
             'data' => self::getInstance()->data
68 68
         ]);
69 69
 
70 70
 
71
-        self::getInstance()->process($serverRequest, new class implements RequestHandlerInterface{
71
+        self::getInstance()->process($serverRequest, new class implements RequestHandlerInterface {
72 72
             public function handle(ServerRequestInterface $request): ResponseInterface
73 73
             {
74 74
                 echo $request->getBody()->getContents();
@@ -86,16 +86,16 @@  discard block
 block discarded – undo
86 86
 
87 87
     public static function import(string $file): void
88 88
     {
89
-        try{
89
+        try {
90 90
             echo self::getInstance()->getBody($file.'.inc.php');
91
-        }catch(\Exception $er){
91
+        }catch (\Exception $er) {
92 92
             echo "<div class='view error'>Component error: {$er->getMessage()}</div>";
93 93
         }
94 94
     }
95 95
 
96 96
     private function getBody(string $file)
97 97
     {
98
-        $buffer = $this->getInstance()->getOB(self::$path . DIRECTORY_SEPARATOR . $file);
98
+        $buffer = $this->getInstance()->getOB(self::$path.DIRECTORY_SEPARATOR.$file);
99 99
         $buffer = $this->getInstance()->getVars($buffer);
100 100
         $buffer = $this->getInstance()->getVars($buffer, false);
101 101
         $buffer = $this->getInstance()->removeComments($buffer);
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@
 block discarded – undo
88 88
     {
89 89
         try{
90 90
             echo self::getInstance()->getBody($file.'.inc.php');
91
-        }catch(\Exception $er){
91
+        } catch(\Exception $er){
92 92
             echo "<div class='view error'>Component error: {$er->getMessage()}</div>";
93 93
         }
94 94
     }
Please login to merge, or discard this patch.
src/JScriptTrait.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -7,10 +7,10 @@  discard block
 block discarded – undo
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,16 +18,16 @@  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
             return true;
23 23
         }
24 24
         
25
-        return (strpos($value,'*/')) ? false : $inComment;
25
+        return (strpos($value, '*/')) ? false : $inComment;
26 26
     }
27 27
 
28 28
     protected function checkScriptNeed(bool $inComment, string $value): bool
29 29
     {
30
-        if(($inComment || strpos($value,'//'))){
30
+        if (($inComment || strpos($value, '//'))) {
31 31
             return false;
32 32
         } 
33 33
         return true;
@@ -35,13 +35,13 @@  discard block
 block discarded – undo
35 35
 
36 36
     protected function treatScript(string $value): string
37 37
     {
38
-        while(  strpos($value,'/*') && strpos($value,'*/')  ){
39
-            $replace = substr($value,strripos ($value,'/*'),strripos ($value,'*/')+2);
40
-            $value = str_replace($replace,'',$value);
38
+        while (strpos($value, '/*') && strpos($value, '*/')) {
39
+            $replace = substr($value, strripos($value, '/*'), strripos($value, '*/')+2);
40
+            $value = str_replace($replace, '', $value);
41 41
         }
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
         
47 47
         return $value;
Please login to merge, or discard this patch.
examples/Class/Address.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-class Address{
3
+class Address {
4 4
     public string $nation;
5 5
     
6 6
     public function __construct()
Please login to merge, or discard this patch.
examples/Class/User.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 require 'Address.php';
4 4
 
5
-class User{
5
+class User {
6 6
     public string $name = 'Henri Azevedo';
7 7
     public array $values = [1 => 'param1'];
8 8
     public Address $address;
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
     public function getVars(): array
20 20
     {
21 21
         $vars = [];
22
-        foreach($this->data as $var => $value){
22
+        foreach ($this->data as $var => $value) {
23 23
             $vars[$var] = $value;
24 24
         }
25 25
         return $vars;
Please login to merge, or discard this patch.
examples/DefaultUseExample.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -7,11 +7,11 @@
 block discarded – undo
7 7
 
8 8
 /* NOTE: in case of error an exception is thrown */
9 9
 
10
-try{
10
+try {
11 11
 
12 12
     Viewer::path(__DIR__.'/Views/')->render('default', $data);
13 13
 
14
-}catch(Exception $er){
14
+}catch (Exception $er) {
15 15
 
16 16
     die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}.");
17 17
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@
 block discarded – undo
11 11
 
12 12
     Viewer::path(__DIR__.'/Views/')->render('default', $data);
13 13
 
14
-}catch(Exception $er){
14
+} catch(Exception $er){
15 15
 
16 16
     die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}.");
17 17
 
Please login to merge, or discard this patch.
examples/MiddlewareExample.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -9,19 +9,19 @@  discard block
 block discarded – undo
9 9
 
10 10
 use HnrAzevedo\Viewer\Viewer;
11 11
 
12
-try{
12
+try {
13 13
     $serverRequest = (new Factory())->createServerRequest(
14 14
         $_SERVER['REQUEST_METHOD'], 
15 15
         new Uri($_SERVER['REQUEST_URI'])
16 16
     );
17 17
 
18
-    $serverRequest = $serverRequest->withAttribute('viewer',[
18
+    $serverRequest = $serverRequest->withAttribute('viewer', [
19 19
         'path' => 'Views',
20 20
         'file' => 'default',
21 21
         'data' => $data
22 22
     ]);
23 23
     
24
-    class App implements MiddlewareInterface{
24
+    class App implements MiddlewareInterface {
25 25
         public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
26 26
         {
27 27
             echo $request->getBody()->getContents();
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
         }
30 30
     }
31 31
 
32
-    define('GLOBAL_MIDDLEWARES',[
32
+    define('GLOBAL_MIDDLEWARES', [
33 33
         Viewer::class,
34 34
         App::class
35 35
     ]);
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 
66 66
     function runMiddlewares($serverRequest)
67 67
     {
68
-        nextExample(new class implements RequestHandlerInterface{
68
+        nextExample(new class implements RequestHandlerInterface {
69 69
             public function handle(ServerRequestInterface $request): ResponseInterface
70 70
             {
71 71
                 return (new Factory())->createResponse(200);
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 
76 76
     runMiddlewares($serverRequest);
77 77
 
78
-}catch(Exception $er){
78
+}catch (Exception $er) {
79 79
 
80 80
     die("Code Error: {$er->getCode()}<br>Line: {$er->getLine()}<br>File: {$er->getFile()}<br>Message: {$er->getMessage()}.");
81 81
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@
 block discarded – undo
75 75
 
76 76
     runMiddlewares($serverRequest);
77 77
 
78
-}catch(Exception $er){
78
+} catch(Exception $er){
79 79
 
80 80
     die("Code Error: {$er->getCode()}<br>Line: {$er->getLine()}<br>File: {$er->getFile()}<br>Message: {$er->getMessage()}.");
81 81
 
Please login to merge, or discard this patch.