Passed
Push — master ( e8b00c...89139c )
by Anton
07:46
created
src/Stempler/src/Transform/Finalizer/StackCollector.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -40,11 +40,11 @@  discard block
 block discarded – undo
40 40
      */
41 41
     public function leaveNode($node, VisitorContext $ctx)
42 42
     {
43
-        if ($node instanceof Tag && strpos($node->name, $this->pushKeyword) === 0) {
43
+        if ($node instanceof Tag && strpos($node->name, $this->pushKeyword) === 0){
44 44
             return $this->registerPush(StackContext::on($ctx), $node);
45 45
         }
46 46
 
47
-        if ($node instanceof Tag && strpos($node->name, $this->prependKeyword) === 0) {
47
+        if ($node instanceof Tag && strpos($node->name, $this->prependKeyword) === 0){
48 48
             return $this->registerPrepend(StackContext::on($ctx), $node);
49 49
         }
50 50
 
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
     {
59 59
         $name = $this->stackName($node);
60 60
 
61
-        if ($name === null || !$ctx->push($name, $node, $this->uniqueID($node))) {
61
+        if ($name === null || !$ctx->push($name, $node, $this->uniqueID($node))){
62 62
             return null;
63 63
         }
64 64
 
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
     {
73 73
         $name = $this->stackName($node);
74 74
 
75
-        if ($name === null || !$ctx->prepend($name, $node, $this->uniqueID($node))) {
75
+        if ($name === null || !$ctx->prepend($name, $node, $this->uniqueID($node))){
76 76
             return null;
77 77
         }
78 78
 
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
 
82 82
     private function stackName(Tag $tag): ?string
83 83
     {
84
-        foreach ($tag->attrs as $attr) {
85
-            if (is_string($attr->value) && $attr->name === 'name') {
84
+        foreach ($tag->attrs as $attr){
85
+            if (is_string($attr->value) && $attr->name === 'name'){
86 86
                 return trim($attr->value, '\'"');
87 87
             }
88 88
         }
@@ -92,8 +92,8 @@  discard block
 block discarded – undo
92 92
 
93 93
     private function uniqueID(Tag $tag): ?string
94 94
     {
95
-        foreach ($tag->attrs as $attr) {
96
-            if (is_string($attr->value) && $attr->name === 'unique-id') {
95
+        foreach ($tag->attrs as $attr){
96
+            if (is_string($attr->value) && $attr->name === 'unique-id'){
97 97
                 return trim($attr->value, '\'"');
98 98
             }
99 99
         }
Please login to merge, or discard this patch.
Braces   +16 added lines, -8 removed lines patch added patch discarded remove patch
@@ -40,11 +40,13 @@  discard block
 block discarded – undo
40 40
      */
41 41
     public function leaveNode($node, VisitorContext $ctx)
42 42
     {
43
-        if ($node instanceof Tag && strpos($node->name, $this->pushKeyword) === 0) {
43
+        if ($node instanceof Tag && strpos($node->name, $this->pushKeyword) === 0)
44
+        {
44 45
             return $this->registerPush(StackContext::on($ctx), $node);
45 46
         }
46 47
 
47
-        if ($node instanceof Tag && strpos($node->name, $this->prependKeyword) === 0) {
48
+        if ($node instanceof Tag && strpos($node->name, $this->prependKeyword) === 0)
49
+        {
48 50
             return $this->registerPrepend(StackContext::on($ctx), $node);
49 51
         }
50 52
 
@@ -58,7 +60,8 @@  discard block
 block discarded – undo
58 60
     {
59 61
         $name = $this->stackName($node);
60 62
 
61
-        if ($name === null || !$ctx->push($name, $node, $this->uniqueID($node))) {
63
+        if ($name === null || !$ctx->push($name, $node, $this->uniqueID($node)))
64
+        {
62 65
             return null;
63 66
         }
64 67
 
@@ -72,7 +75,8 @@  discard block
 block discarded – undo
72 75
     {
73 76
         $name = $this->stackName($node);
74 77
 
75
-        if ($name === null || !$ctx->prepend($name, $node, $this->uniqueID($node))) {
78
+        if ($name === null || !$ctx->prepend($name, $node, $this->uniqueID($node)))
79
+        {
76 80
             return null;
77 81
         }
78 82
 
@@ -81,8 +85,10 @@  discard block
 block discarded – undo
81 85
 
82 86
     private function stackName(Tag $tag): ?string
83 87
     {
84
-        foreach ($tag->attrs as $attr) {
85
-            if (is_string($attr->value) && $attr->name === 'name') {
88
+        foreach ($tag->attrs as $attr)
89
+        {
90
+            if (is_string($attr->value) && $attr->name === 'name')
91
+            {
86 92
                 return trim($attr->value, '\'"');
87 93
             }
88 94
         }
@@ -92,8 +98,10 @@  discard block
 block discarded – undo
92 98
 
93 99
     private function uniqueID(Tag $tag): ?string
94 100
     {
95
-        foreach ($tag->attrs as $attr) {
96
-            if (is_string($attr->value) && $attr->name === 'unique-id') {
101
+        foreach ($tag->attrs as $attr)
102
+        {
103
+            if (is_string($attr->value) && $attr->name === 'unique-id')
104
+            {
97 105
                 return trim($attr->value, '\'"');
98 106
             }
99 107
         }
Please login to merge, or discard this patch.
src/Stempler/src/Transform/Finalizer/DynamicToPHP.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -72,17 +72,17 @@  discard block
 block discarded – undo
72 72
      */
73 73
     public function leaveNode($node, VisitorContext $ctx)
74 74
     {
75
-        if ($node instanceof Output) {
75
+        if ($node instanceof Output){
76 76
             return $this->output($node, $ctx);
77 77
         }
78 78
 
79
-        if ($node instanceof Directive) {
79
+        if ($node instanceof Directive){
80 80
             return $this->directive($node);
81 81
         }
82 82
 
83
-        if ($node instanceof Template) {
83
+        if ($node instanceof Template){
84 84
             $extendsTag = $node->getAttribute(ExtendsParent::class);
85
-            if ($extendsTag instanceof Tag) {
85
+            if ($extendsTag instanceof Tag){
86 86
                 $extendsTag->attrs = $this->traverser->traverse($extendsTag->attrs);
87 87
             }
88 88
         }
@@ -92,9 +92,9 @@  discard block
 block discarded – undo
92 92
 
93 93
     private function directive(Directive $node): PHP
94 94
     {
95
-        foreach ($this->directives as $renderer) {
95
+        foreach ($this->directives as $renderer){
96 96
             $result = $renderer->render($node);
97
-            if ($result !== null) {
97
+            if ($result !== null){
98 98
                 return new PHP($result, token_get_all($result), $node->getContext());
99 99
             }
100 100
         }
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
          * In future this method can support context aware escaping based on tag location.
112 112
          */
113 113
 
114
-        if ($node->rawOutput) {
114
+        if ($node->rawOutput){
115 115
             $result = sprintf('<?php echo %s; ?>', trim($node->body));
116
-        } else {
116
+        }else{
117 117
             $filter = $node->filter ?? $this->getFilterContext($ctx);
118 118
 
119 119
             $result = sprintf("<?php echo {$filter}; ?>", trim($node->body));
@@ -131,22 +131,22 @@  discard block
 block discarded – undo
131 131
         // only "interesting" nodes
132 132
         $context = [];
133 133
 
134
-        foreach (array_reverse($ctx->getScope()) as $node) {
135
-            if ($node instanceof Attr || $node instanceof Tag || $node instanceof Verbatim) {
134
+        foreach (array_reverse($ctx->getScope()) as $node){
135
+            if ($node instanceof Attr || $node instanceof Tag || $node instanceof Verbatim){
136 136
                 $context[] = $node;
137 137
             }
138 138
 
139
-            if (count($context) === 2) {
139
+            if (count($context) === 2){
140 140
                 break;
141 141
             }
142 142
         }
143 143
 
144
-        if (count($context) !== 2) {
144
+        if (count($context) !== 2){
145 145
             return $this->defaultFilter;
146 146
         }
147 147
 
148 148
         // php {{ }} in javascript code (variable passing), use {! !} to bypass the filter
149
-        if ($context[0] instanceof Verbatim && $context[1] instanceof Tag && $context[1]->name === 'script') {
149
+        if ($context[0] instanceof Verbatim && $context[1] instanceof Tag && $context[1]->name === 'script'){
150 150
             return sprintf(
151 151
                 'json_encode(%s, %s, %s)',
152 152
                 '%s',
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
         }
157 157
 
158 158
         // in on* and other attributes
159
-        if ($context[0] instanceof Verbatim && $context[1] instanceof Attr && $context[1]->name !== 'style') {
159
+        if ($context[0] instanceof Verbatim && $context[1] instanceof Attr && $context[1]->name !== 'style'){
160 160
             return sprintf("'%s', %s, '%s'", '&quot;', $this->defaultFilter, '&quot;');
161 161
         }
162 162
 
Please login to merge, or discard this patch.
Braces   +29 added lines, -14 removed lines patch added patch discarded remove patch
@@ -72,17 +72,21 @@  discard block
 block discarded – undo
72 72
      */
73 73
     public function leaveNode($node, VisitorContext $ctx)
74 74
     {
75
-        if ($node instanceof Output) {
75
+        if ($node instanceof Output)
76
+        {
76 77
             return $this->output($node, $ctx);
77 78
         }
78 79
 
79
-        if ($node instanceof Directive) {
80
+        if ($node instanceof Directive)
81
+        {
80 82
             return $this->directive($node);
81 83
         }
82 84
 
83
-        if ($node instanceof Template) {
85
+        if ($node instanceof Template)
86
+        {
84 87
             $extendsTag = $node->getAttribute(ExtendsParent::class);
85
-            if ($extendsTag instanceof Tag) {
88
+            if ($extendsTag instanceof Tag)
89
+            {
86 90
                 $extendsTag->attrs = $this->traverser->traverse($extendsTag->attrs);
87 91
             }
88 92
         }
@@ -92,9 +96,11 @@  discard block
 block discarded – undo
92 96
 
93 97
     private function directive(Directive $node): PHP
94 98
     {
95
-        foreach ($this->directives as $renderer) {
99
+        foreach ($this->directives as $renderer)
100
+        {
96 101
             $result = $renderer->render($node);
97
-            if ($result !== null) {
102
+            if ($result !== null)
103
+            {
98 104
                 return new PHP($result, token_get_all($result), $node->getContext());
99 105
             }
100 106
         }
@@ -111,9 +117,12 @@  discard block
 block discarded – undo
111 117
          * In future this method can support context aware escaping based on tag location.
112 118
          */
113 119
 
114
-        if ($node->rawOutput) {
120
+        if ($node->rawOutput)
121
+        {
115 122
             $result = sprintf('<?php echo %s; ?>', trim($node->body));
116
-        } else {
123
+        }
124
+        else
125
+        {
117 126
             $filter = $node->filter ?? $this->getFilterContext($ctx);
118 127
 
119 128
             $result = sprintf("<?php echo {$filter}; ?>", trim($node->body));
@@ -131,22 +140,27 @@  discard block
 block discarded – undo
131 140
         // only "interesting" nodes
132 141
         $context = [];
133 142
 
134
-        foreach (array_reverse($ctx->getScope()) as $node) {
135
-            if ($node instanceof Attr || $node instanceof Tag || $node instanceof Verbatim) {
143
+        foreach (array_reverse($ctx->getScope()) as $node)
144
+        {
145
+            if ($node instanceof Attr || $node instanceof Tag || $node instanceof Verbatim)
146
+            {
136 147
                 $context[] = $node;
137 148
             }
138 149
 
139
-            if (count($context) === 2) {
150
+            if (count($context) === 2)
151
+            {
140 152
                 break;
141 153
             }
142 154
         }
143 155
 
144
-        if (count($context) !== 2) {
156
+        if (count($context) !== 2)
157
+        {
145 158
             return $this->defaultFilter;
146 159
         }
147 160
 
148 161
         // php {{ }} in javascript code (variable passing), use {! !} to bypass the filter
149
-        if ($context[0] instanceof Verbatim && $context[1] instanceof Tag && $context[1]->name === 'script') {
162
+        if ($context[0] instanceof Verbatim && $context[1] instanceof Tag && $context[1]->name === 'script')
163
+        {
150 164
             return sprintf(
151 165
                 'json_encode(%s, %s, %s)',
152 166
                 '%s',
@@ -156,7 +170,8 @@  discard block
 block discarded – undo
156 170
         }
157 171
 
158 172
         // in on* and other attributes
159
-        if ($context[0] instanceof Verbatim && $context[1] instanceof Attr && $context[1]->name !== 'style') {
173
+        if ($context[0] instanceof Verbatim && $context[1] instanceof Attr && $context[1]->name !== 'style')
174
+        {
160 175
             return sprintf("'%s', %s, '%s'", '&quot;', $this->defaultFilter, '&quot;');
161 176
         }
162 177
 
Please login to merge, or discard this patch.
src/Stempler/src/Transform/Context/ImportContext.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
     public function add(ImportInterface $import): void
35 35
     {
36 36
         $node = $this->ctx->getParentNode();
37
-        if (!$node instanceof AttributedInterface) {
37
+        if (!$node instanceof AttributedInterface){
38 38
             throw new LogicException(\sprintf(
39 39
                 'Unable to create import on node without attribute storage (%s)',
40 40
                 \is_object($node) ? \get_class($node) : \gettype($node)
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
      */
52 52
     public function resolve(Builder $builder, string $name): ?Template
53 53
     {
54
-        foreach ($this->getImports() as $import) {
54
+        foreach ($this->getImports() as $import){
55 55
             $tpl = $import->resolve($builder, $name);
56
-            if ($tpl !== null) {
56
+            if ($tpl !== null){
57 57
                 return $tpl;
58 58
             }
59 59
         }
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
     public function getImports(): array
70 70
     {
71 71
         $imports = [];
72
-        foreach (array_reverse($this->ctx->getScope()) as $node) {
73
-            if ($node instanceof AttributedInterface) {
74
-                foreach ($node->getAttribute(self::class, []) as $import) {
72
+        foreach (array_reverse($this->ctx->getScope()) as $node){
73
+            if ($node instanceof AttributedInterface){
74
+                foreach ($node->getAttribute(self::class, []) as $import){
75 75
                     $imports[] = $import;
76 76
                 }
77 77
             }
Please login to merge, or discard this patch.
Braces   +12 added lines, -6 removed lines patch added patch discarded remove patch
@@ -34,7 +34,8 @@  discard block
 block discarded – undo
34 34
     public function add(ImportInterface $import): void
35 35
     {
36 36
         $node = $this->ctx->getParentNode();
37
-        if (!$node instanceof AttributedInterface) {
37
+        if (!$node instanceof AttributedInterface)
38
+        {
38 39
             throw new LogicException(\sprintf(
39 40
                 'Unable to create import on node without attribute storage (%s)',
40 41
                 \is_object($node) ? \get_class($node) : \gettype($node)
@@ -51,9 +52,11 @@  discard block
 block discarded – undo
51 52
      */
52 53
     public function resolve(Builder $builder, string $name): ?Template
53 54
     {
54
-        foreach ($this->getImports() as $import) {
55
+        foreach ($this->getImports() as $import)
56
+        {
55 57
             $tpl = $import->resolve($builder, $name);
56
-            if ($tpl !== null) {
58
+            if ($tpl !== null)
59
+            {
57 60
                 return $tpl;
58 61
             }
59 62
         }
@@ -69,9 +72,12 @@  discard block
 block discarded – undo
69 72
     public function getImports(): array
70 73
     {
71 74
         $imports = [];
72
-        foreach (array_reverse($this->ctx->getScope()) as $node) {
73
-            if ($node instanceof AttributedInterface) {
74
-                foreach ($node->getAttribute(self::class, []) as $import) {
75
+        foreach (array_reverse($this->ctx->getScope()) as $node)
76
+        {
77
+            if ($node instanceof AttributedInterface)
78
+            {
79
+                foreach ($node->getAttribute(self::class, []) as $import)
80
+                {
75 81
                     $imports[] = $import;
76 82
                 }
77 83
             }
Please login to merge, or discard this patch.
src/Stempler/src/Transform/Context/StackContext.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -41,17 +41,17 @@  discard block
 block discarded – undo
41 41
      */
42 42
     public function push(string $name, Tag $child, string $uniqueID = null): bool
43 43
     {
44
-        foreach ($this->getStacks() as $stack) {
45
-            if ($stack->accepts($name) !== $name) {
44
+        foreach ($this->getStacks() as $stack){
45
+            if ($stack->accepts($name) !== $name){
46 46
                 continue;
47 47
             }
48 48
 
49
-            if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) {
49
+            if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])){
50 50
                 return true;
51 51
             }
52 52
             $stack->uniqueIDs[$uniqueID] = true;
53 53
 
54
-            foreach ($child->nodes as $child) {
54
+            foreach ($child->nodes as $child){
55 55
                 $stack->nodes[] = $child;
56 56
             }
57 57
 
@@ -66,17 +66,17 @@  discard block
 block discarded – undo
66 66
      */
67 67
     public function prepend(string $name, Tag $child, string $uniqueID = null): bool
68 68
     {
69
-        foreach ($this->getStacks() as $stack) {
70
-            if ($stack->accepts($name) !== $name) {
69
+        foreach ($this->getStacks() as $stack){
70
+            if ($stack->accepts($name) !== $name){
71 71
                 continue;
72 72
             }
73 73
 
74
-            if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) {
74
+            if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])){
75 75
                 return true;
76 76
             }
77 77
             $stack->uniqueIDs[$uniqueID] = true;
78 78
 
79
-            foreach ($child->nodes as $child) {
79
+            foreach ($child->nodes as $child){
80 80
                 array_unshift($stack->nodes, $child);
81 81
             }
82 82
 
@@ -94,9 +94,9 @@  discard block
 block discarded – undo
94 94
     public function getStacks(): array
95 95
     {
96 96
         $stacks = [];
97
-        foreach (array_reverse($this->ctx->getScope()) as $node) {
98
-            if ($node instanceof AttributedInterface) {
99
-                foreach ($node->getAttribute(self::class, []) as $stack) {
97
+        foreach (array_reverse($this->ctx->getScope()) as $node){
98
+            if ($node instanceof AttributedInterface){
99
+                foreach ($node->getAttribute(self::class, []) as $stack){
100 100
                     $stacks[] = $stack;
101 101
                 }
102 102
             }
@@ -112,16 +112,16 @@  discard block
 block discarded – undo
112 112
 
113 113
     private function getStackRootNode(int $level): AttributedInterface
114 114
     {
115
-        if ($level === 0) {
115
+        if ($level === 0){
116 116
             $node = $this->ctx->getParentNode();
117
-        } else {
117
+        }else{
118 118
             $scope = $this->ctx->getScope();
119 119
 
120 120
             // looking for the parent node via given nesting level
121 121
             $node = $scope[count($scope) - 2 - $level] ?? $this->ctx->getFirstNode();
122 122
         }
123 123
 
124
-        if (!$node instanceof AttributedInterface) {
124
+        if (!$node instanceof AttributedInterface){
125 125
             throw new \LogicException(
126 126
                 sprintf(
127 127
                     'Unable to create import on node without attribute storage (%s)',
Please login to merge, or discard this patch.
Braces   +29 added lines, -14 removed lines patch added patch discarded remove patch
@@ -41,17 +41,21 @@  discard block
 block discarded – undo
41 41
      */
42 42
     public function push(string $name, Tag $child, string $uniqueID = null): bool
43 43
     {
44
-        foreach ($this->getStacks() as $stack) {
45
-            if ($stack->accepts($name) !== $name) {
44
+        foreach ($this->getStacks() as $stack)
45
+        {
46
+            if ($stack->accepts($name) !== $name)
47
+            {
46 48
                 continue;
47 49
             }
48 50
 
49
-            if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) {
51
+            if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID]))
52
+            {
50 53
                 return true;
51 54
             }
52 55
             $stack->uniqueIDs[$uniqueID] = true;
53 56
 
54
-            foreach ($child->nodes as $child) {
57
+            foreach ($child->nodes as $child)
58
+            {
55 59
                 $stack->nodes[] = $child;
56 60
             }
57 61
 
@@ -66,17 +70,21 @@  discard block
 block discarded – undo
66 70
      */
67 71
     public function prepend(string $name, Tag $child, string $uniqueID = null): bool
68 72
     {
69
-        foreach ($this->getStacks() as $stack) {
70
-            if ($stack->accepts($name) !== $name) {
73
+        foreach ($this->getStacks() as $stack)
74
+        {
75
+            if ($stack->accepts($name) !== $name)
76
+            {
71 77
                 continue;
72 78
             }
73 79
 
74
-            if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) {
80
+            if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID]))
81
+            {
75 82
                 return true;
76 83
             }
77 84
             $stack->uniqueIDs[$uniqueID] = true;
78 85
 
79
-            foreach ($child->nodes as $child) {
86
+            foreach ($child->nodes as $child)
87
+            {
80 88
                 array_unshift($stack->nodes, $child);
81 89
             }
82 90
 
@@ -94,9 +102,12 @@  discard block
 block discarded – undo
94 102
     public function getStacks(): array
95 103
     {
96 104
         $stacks = [];
97
-        foreach (array_reverse($this->ctx->getScope()) as $node) {
98
-            if ($node instanceof AttributedInterface) {
99
-                foreach ($node->getAttribute(self::class, []) as $stack) {
105
+        foreach (array_reverse($this->ctx->getScope()) as $node)
106
+        {
107
+            if ($node instanceof AttributedInterface)
108
+            {
109
+                foreach ($node->getAttribute(self::class, []) as $stack)
110
+                {
100 111
                     $stacks[] = $stack;
101 112
                 }
102 113
             }
@@ -112,16 +123,20 @@  discard block
 block discarded – undo
112 123
 
113 124
     private function getStackRootNode(int $level): AttributedInterface
114 125
     {
115
-        if ($level === 0) {
126
+        if ($level === 0)
127
+        {
116 128
             $node = $this->ctx->getParentNode();
117
-        } else {
129
+        }
130
+        else
131
+        {
118 132
             $scope = $this->ctx->getScope();
119 133
 
120 134
             // looking for the parent node via given nesting level
121 135
             $node = $scope[count($scope) - 2 - $level] ?? $this->ctx->getFirstNode();
122 136
         }
123 137
 
124
-        if (!$node instanceof AttributedInterface) {
138
+        if (!$node instanceof AttributedInterface)
139
+        {
125 140
             throw new \LogicException(
126 141
                 sprintf(
127 142
                     'Unable to create import on node without attribute storage (%s)',
Please login to merge, or discard this patch.
src/Stempler/src/Transform/Merge/Inject/PHPMixin.php 2 patches
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
     {
33 33
         $replace = [];
34 34
 
35
-        foreach ($this->blocks as $block) {
36
-            for ($i = $block['start']; $i <= $block['end']; $i++) {
35
+        foreach ($this->blocks as $block){
36
+            for ($i = $block['start']; $i <= $block['end']; $i++){
37 37
                 $replace[$i] = '';
38 38
             }
39 39
 
@@ -41,13 +41,13 @@  discard block
 block discarded – undo
41 41
         }
42 42
 
43 43
         $result = '';
44
-        foreach ($this->tokens as $position => $token) {
45
-            if (array_key_exists($position, $replace)) {
44
+        foreach ($this->tokens as $position => $token){
45
+            if (array_key_exists($position, $replace)){
46 46
                 $result .= $replace[$position];
47 47
                 continue;
48 48
             }
49 49
 
50
-            if (is_string($token)) {
50
+            if (is_string($token)){
51 51
                 $result .= $token;
52 52
                 continue;
53 53
             }
@@ -65,8 +65,8 @@  discard block
 block discarded – undo
65 65
     {
66 66
         $replace = [];
67 67
 
68
-        foreach ($this->blocks as $block) {
69
-            for ($i = $block['start']; $i <= $block['end']; $i++) {
68
+        foreach ($this->blocks as $block){
69
+            for ($i = $block['start']; $i <= $block['end']; $i++){
70 70
                 $replace[$i] = '';
71 71
             }
72 72
 
@@ -74,18 +74,18 @@  discard block
 block discarded – undo
74 74
         }
75 75
 
76 76
         $result = '';
77
-        foreach ($this->tokens as $position => $token) {
78
-            if (array_key_exists($position, $replace)) {
77
+        foreach ($this->tokens as $position => $token){
78
+            if (array_key_exists($position, $replace)){
79 79
                 $result .= $replace[$position];
80 80
                 continue;
81 81
             }
82 82
 
83
-            if (is_string($token)) {
83
+            if (is_string($token)){
84 84
                 $result .= $token;
85 85
                 continue;
86 86
             }
87 87
 
88
-            if (in_array($token[0], [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, T_CLOSE_TAG, T_ECHO])) {
88
+            if (in_array($token[0], [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, T_CLOSE_TAG, T_ECHO])){
89 89
                 continue;
90 90
             }
91 91
 
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
     public function getBlocks(): array
102 102
     {
103 103
         $result = [];
104
-        foreach ($this->blocks as $name => $macro) {
104
+        foreach ($this->blocks as $name => $macro){
105 105
             $result[$name] = $macro['value'];
106 106
         }
107 107
 
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 
116 116
     public function set(string $block, string $value): void
117 117
     {
118
-        if (!isset($this->blocks[$block])) {
118
+        if (!isset($this->blocks[$block])){
119 119
             return;
120 120
         }
121 121
 
@@ -126,26 +126,26 @@  discard block
 block discarded – undo
126 126
     {
127 127
         $level = 0;
128 128
         $start = $name = $value = null;
129
-        foreach ($this->tokens as $position => $token) {
130
-            if (!is_array($token)) {
129
+        foreach ($this->tokens as $position => $token){
130
+            if (!is_array($token)){
131 131
                 $token = [$token, $token, 0];
132 132
             }
133 133
 
134
-            switch ($token[0]) {
134
+            switch ($token[0]){
135 135
                 case '(':
136
-                    if ($start !== null) {
136
+                    if ($start !== null){
137 137
                         $level++;
138 138
                         $value .= $token[1];
139 139
                     }
140 140
                     break;
141 141
                 case ')':
142
-                    if ($start === null) {
142
+                    if ($start === null){
143 143
                         break;
144 144
                     }
145 145
 
146 146
                     $level--;
147 147
                     $value .= $token[1];
148
-                    if ($level === 0) {
148
+                    if ($level === 0){
149 149
                         $this->blocks[$name] = [
150 150
                             'start' => $start,
151 151
                             'value' => trim($value),
@@ -157,22 +157,22 @@  discard block
 block discarded – undo
157 157
                     }
158 158
                     break;
159 159
                 case T_STRING:
160
-                    if ($token[1] === $func) {
160
+                    if ($token[1] === $func){
161 161
                         $start = $position;
162 162
                         $value = $token[1];
163 163
                         break;
164 164
                     }
165 165
 
166
-                    if ($start !== null) {
166
+                    if ($start !== null){
167 167
                         $value .= $token[1];
168 168
                     }
169 169
                     break;
170 170
                 case T_CONSTANT_ENCAPSED_STRING:
171
-                    if ($start === null) {
171
+                    if ($start === null){
172 172
                         break;
173 173
                     }
174 174
 
175
-                    if ($name === null) {
175
+                    if ($name === null){
176 176
                         $name = stripcslashes(substr($token[1], 1, -1));
177 177
                     }
178 178
                     $value .= $token[1];
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
                     $value .= $token[1];
182 182
                     break;
183 183
                 default:
184
-                    if ($start !== null) {
184
+                    if ($start !== null){
185 185
                         $value .= $token[1];
186 186
                     }
187 187
             }
Please login to merge, or discard this patch.
Braces   +48 added lines, -24 removed lines patch added patch discarded remove patch
@@ -32,8 +32,10 @@  discard block
 block discarded – undo
32 32
     {
33 33
         $replace = [];
34 34
 
35
-        foreach ($this->blocks as $block) {
36
-            for ($i = $block['start']; $i <= $block['end']; $i++) {
35
+        foreach ($this->blocks as $block)
36
+        {
37
+            for ($i = $block['start']; $i <= $block['end']; $i++)
38
+            {
37 39
                 $replace[$i] = '';
38 40
             }
39 41
 
@@ -41,13 +43,16 @@  discard block
 block discarded – undo
41 43
         }
42 44
 
43 45
         $result = '';
44
-        foreach ($this->tokens as $position => $token) {
45
-            if (array_key_exists($position, $replace)) {
46
+        foreach ($this->tokens as $position => $token)
47
+        {
48
+            if (array_key_exists($position, $replace))
49
+            {
46 50
                 $result .= $replace[$position];
47 51
                 continue;
48 52
             }
49 53
 
50
-            if (is_string($token)) {
54
+            if (is_string($token))
55
+            {
51 56
                 $result .= $token;
52 57
                 continue;
53 58
             }
@@ -65,8 +70,10 @@  discard block
 block discarded – undo
65 70
     {
66 71
         $replace = [];
67 72
 
68
-        foreach ($this->blocks as $block) {
69
-            for ($i = $block['start']; $i <= $block['end']; $i++) {
73
+        foreach ($this->blocks as $block)
74
+        {
75
+            for ($i = $block['start']; $i <= $block['end']; $i++)
76
+            {
70 77
                 $replace[$i] = '';
71 78
             }
72 79
 
@@ -74,18 +81,22 @@  discard block
 block discarded – undo
74 81
         }
75 82
 
76 83
         $result = '';
77
-        foreach ($this->tokens as $position => $token) {
78
-            if (array_key_exists($position, $replace)) {
84
+        foreach ($this->tokens as $position => $token)
85
+        {
86
+            if (array_key_exists($position, $replace))
87
+            {
79 88
                 $result .= $replace[$position];
80 89
                 continue;
81 90
             }
82 91
 
83
-            if (is_string($token)) {
92
+            if (is_string($token))
93
+            {
84 94
                 $result .= $token;
85 95
                 continue;
86 96
             }
87 97
 
88
-            if (in_array($token[0], [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, T_CLOSE_TAG, T_ECHO])) {
98
+            if (in_array($token[0], [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, T_CLOSE_TAG, T_ECHO]))
99
+            {
89 100
                 continue;
90 101
             }
91 102
 
@@ -101,7 +112,8 @@  discard block
 block discarded – undo
101 112
     public function getBlocks(): array
102 113
     {
103 114
         $result = [];
104
-        foreach ($this->blocks as $name => $macro) {
115
+        foreach ($this->blocks as $name => $macro)
116
+        {
105 117
             $result[$name] = $macro['value'];
106 118
         }
107 119
 
@@ -115,7 +127,8 @@  discard block
 block discarded – undo
115 127
 
116 128
     public function set(string $block, string $value): void
117 129
     {
118
-        if (!isset($this->blocks[$block])) {
130
+        if (!isset($this->blocks[$block]))
131
+        {
119 132
             return;
120 133
         }
121 134
 
@@ -126,26 +139,32 @@  discard block
 block discarded – undo
126 139
     {
127 140
         $level = 0;
128 141
         $start = $name = $value = null;
129
-        foreach ($this->tokens as $position => $token) {
130
-            if (!is_array($token)) {
142
+        foreach ($this->tokens as $position => $token)
143
+        {
144
+            if (!is_array($token))
145
+            {
131 146
                 $token = [$token, $token, 0];
132 147
             }
133 148
 
134
-            switch ($token[0]) {
149
+            switch ($token[0])
150
+            {
135 151
                 case '(':
136
-                    if ($start !== null) {
152
+                    if ($start !== null)
153
+                    {
137 154
                         $level++;
138 155
                         $value .= $token[1];
139 156
                     }
140 157
                     break;
141 158
                 case ')':
142
-                    if ($start === null) {
159
+                    if ($start === null)
160
+                    {
143 161
                         break;
144 162
                     }
145 163
 
146 164
                     $level--;
147 165
                     $value .= $token[1];
148
-                    if ($level === 0) {
166
+                    if ($level === 0)
167
+                    {
149 168
                         $this->blocks[$name] = [
150 169
                             'start' => $start,
151 170
                             'value' => trim($value),
@@ -157,22 +176,26 @@  discard block
 block discarded – undo
157 176
                     }
158 177
                     break;
159 178
                 case T_STRING:
160
-                    if ($token[1] === $func) {
179
+                    if ($token[1] === $func)
180
+                    {
161 181
                         $start = $position;
162 182
                         $value = $token[1];
163 183
                         break;
164 184
                     }
165 185
 
166
-                    if ($start !== null) {
186
+                    if ($start !== null)
187
+                    {
167 188
                         $value .= $token[1];
168 189
                     }
169 190
                     break;
170 191
                 case T_CONSTANT_ENCAPSED_STRING:
171
-                    if ($start === null) {
192
+                    if ($start === null)
193
+                    {
172 194
                         break;
173 195
                     }
174 196
 
175
-                    if ($name === null) {
197
+                    if ($name === null)
198
+                    {
176 199
                         $name = stripcslashes(substr($token[1], 1, -1));
177 200
                     }
178 201
                     $value .= $token[1];
@@ -181,7 +204,8 @@  discard block
 block discarded – undo
181 204
                     $value .= $token[1];
182 205
                     break;
183 206
                 default:
184
-                    if ($start !== null) {
207
+                    if ($start !== null)
208
+                    {
185 209
                         $value .= $token[1];
186 210
                     }
187 211
             }
Please login to merge, or discard this patch.
src/Stempler/src/Transform/Merge/ExtendsParent.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
      */
48 48
     public function enterNode($node, VisitorContext $ctx)
49 49
     {
50
-        if ($node instanceof Tag && strpos($node->name, $this->extendsKeyword) === 0) {
50
+        if ($node instanceof Tag && strpos($node->name, $this->extendsKeyword) === 0){
51 51
             return self::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
52 52
         }
53 53
 
@@ -59,9 +59,9 @@  discard block
 block discarded – undo
59 59
      */
60 60
     public function leaveNode($node, VisitorContext $ctx)
61 61
     {
62
-        if ($node instanceof Tag && strpos($node->name, $this->extendsKeyword) === 0) {
62
+        if ($node instanceof Tag && strpos($node->name, $this->extendsKeyword) === 0){
63 63
             $parent = $ctx->getParentNode();
64
-            if (!$parent instanceof AttributedInterface) {
64
+            if (!$parent instanceof AttributedInterface){
65 65
                 throw new LogicException(sprintf(
66 66
                     'Unable to extend non attributable node (%s)',
67 67
                     is_object($node) ? get_class($node) : gettype($node)
@@ -74,20 +74,20 @@  discard block
 block discarded – undo
74 74
         }
75 75
 
76 76
         // extend current node
77
-        if ($node instanceof AttributedInterface && $node->getAttribute(self::class) !== null) {
77
+        if ($node instanceof AttributedInterface && $node->getAttribute(self::class) !== null){
78 78
             /** @var Tag $extends */
79 79
             $extends = $node->getAttribute(self::class);
80 80
 
81
-            foreach ($node->nodes as $child) {
81
+            foreach ($node->nodes as $child){
82 82
                 $extends->nodes[] = $child;
83 83
             }
84 84
 
85 85
             $path = 'undefined';
86
-            try {
86
+            try{
87 87
                 $path = $this->getPath($extends);
88 88
 
89 89
                 return $this->merger->merge($this->builder->load($path), $extends);
90
-            } catch (\Throwable $e) {
90
+            }catch (\Throwable $e){
91 91
                 throw new ExtendsException(
92 92
                     "Unable to extend parent `{$path}`",
93 93
                     $extends->getContext(),
@@ -101,14 +101,14 @@  discard block
 block discarded – undo
101 101
 
102 102
     private function getPath(Tag $tag): string
103 103
     {
104
-        if (strpos($tag->name, $this->extendsKeyword . ':') === 0) {
104
+        if (strpos($tag->name, $this->extendsKeyword.':') === 0){
105 105
             $name = substr($tag->name, strlen($this->extendsKeyword) + 1);
106 106
 
107 107
             return str_replace(['.'], DIRECTORY_SEPARATOR, $name);
108 108
         }
109 109
 
110
-        foreach ($tag->attrs as $attr) {
111
-            if ($attr->name === 'path' && is_string($attr->value)) {
110
+        foreach ($tag->attrs as $attr){
111
+            if ($attr->name === 'path' && is_string($attr->value)){
112 112
                 return trim($attr->value, '\'"');
113 113
             }
114 114
         }
Please login to merge, or discard this patch.
Braces   +21 added lines, -10 removed lines patch added patch discarded remove patch
@@ -47,7 +47,8 @@  discard block
 block discarded – undo
47 47
      */
48 48
     public function enterNode($node, VisitorContext $ctx)
49 49
     {
50
-        if ($node instanceof Tag && strpos($node->name, $this->extendsKeyword) === 0) {
50
+        if ($node instanceof Tag && strpos($node->name, $this->extendsKeyword) === 0)
51
+        {
51 52
             return self::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
52 53
         }
53 54
 
@@ -59,9 +60,11 @@  discard block
 block discarded – undo
59 60
      */
60 61
     public function leaveNode($node, VisitorContext $ctx)
61 62
     {
62
-        if ($node instanceof Tag && strpos($node->name, $this->extendsKeyword) === 0) {
63
+        if ($node instanceof Tag && strpos($node->name, $this->extendsKeyword) === 0)
64
+        {
63 65
             $parent = $ctx->getParentNode();
64
-            if (!$parent instanceof AttributedInterface) {
66
+            if (!$parent instanceof AttributedInterface)
67
+            {
65 68
                 throw new LogicException(sprintf(
66 69
                     'Unable to extend non attributable node (%s)',
67 70
                     is_object($node) ? get_class($node) : gettype($node)
@@ -74,20 +77,25 @@  discard block
 block discarded – undo
74 77
         }
75 78
 
76 79
         // extend current node
77
-        if ($node instanceof AttributedInterface && $node->getAttribute(self::class) !== null) {
80
+        if ($node instanceof AttributedInterface && $node->getAttribute(self::class) !== null)
81
+        {
78 82
             /** @var Tag $extends */
79 83
             $extends = $node->getAttribute(self::class);
80 84
 
81
-            foreach ($node->nodes as $child) {
85
+            foreach ($node->nodes as $child)
86
+            {
82 87
                 $extends->nodes[] = $child;
83 88
             }
84 89
 
85 90
             $path = 'undefined';
86
-            try {
91
+            try
92
+            {
87 93
                 $path = $this->getPath($extends);
88 94
 
89 95
                 return $this->merger->merge($this->builder->load($path), $extends);
90
-            } catch (\Throwable $e) {
96
+            }
97
+            catch (\Throwable $e)
98
+            {
91 99
                 throw new ExtendsException(
92 100
                     "Unable to extend parent `{$path}`",
93 101
                     $extends->getContext(),
@@ -101,14 +109,17 @@  discard block
 block discarded – undo
101 109
 
102 110
     private function getPath(Tag $tag): string
103 111
     {
104
-        if (strpos($tag->name, $this->extendsKeyword . ':') === 0) {
112
+        if (strpos($tag->name, $this->extendsKeyword . ':') === 0)
113
+        {
105 114
             $name = substr($tag->name, strlen($this->extendsKeyword) + 1);
106 115
 
107 116
             return str_replace(['.'], DIRECTORY_SEPARATOR, $name);
108 117
         }
109 118
 
110
-        foreach ($tag->attrs as $attr) {
111
-            if ($attr->name === 'path' && is_string($attr->value)) {
119
+        foreach ($tag->attrs as $attr)
120
+        {
121
+            if ($attr->name === 'path' && is_string($attr->value))
122
+            {
112 123
                 return trim($attr->value, '\'"');
113 124
             }
114 125
         }
Please login to merge, or discard this patch.
src/Stempler/src/Transform/Merge/ResolveImports.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
      */
50 50
     public function enterNode($node, VisitorContext $ctx)
51 51
     {
52
-        if ($node instanceof Tag && strpos($node->name, $this->useKeyword) === 0) {
52
+        if ($node instanceof Tag && strpos($node->name, $this->useKeyword) === 0){
53 53
             return self::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
54 54
         }
55 55
 
@@ -61,23 +61,23 @@  discard block
 block discarded – undo
61 61
      */
62 62
     public function leaveNode($node, VisitorContext $ctx)
63 63
     {
64
-        if (!$node instanceof Tag) {
64
+        if (!$node instanceof Tag){
65 65
             return null;
66 66
         }
67 67
 
68 68
         $importCtx = ImportContext::on($ctx);
69 69
 
70 70
         // import definition
71
-        if (\strpos($node->name, $this->useKeyword) === 0) {
71
+        if (\strpos($node->name, $this->useKeyword) === 0){
72 72
             $importCtx->add($this->makeImport($node));
73 73
 
74 74
             return self::REMOVE_NODE;
75 75
         }
76 76
 
77 77
         // imported tag
78
-        try {
78
+        try{
79 79
             $import = $importCtx->resolve($this->builder, $node->name);
80
-        } catch (\Throwable $e) {
80
+        }catch (\Throwable $e){
81 81
             throw new ImportException(
82 82
                 "Unable to resolve import `{$node->name}`",
83 83
                 $node->getContext(),
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
             );
86 86
         }
87 87
 
88
-        if ($import !== null) {
88
+        if ($import !== null){
89 89
             $node = $this->merger->merge($import, $node);
90 90
 
91 91
             return $this->merger->isolateNodes($node, $import->getContext()->getPath());
@@ -102,14 +102,14 @@  discard block
 block discarded – undo
102 102
     private function makeImport(Tag $tag): ImportInterface
103 103
     {
104 104
         $options = [];
105
-        foreach ($tag->attrs as $attr) {
106
-            if (!\is_string($attr->value) || !\is_string($attr->name)) {
105
+        foreach ($tag->attrs as $attr){
106
+            if (!\is_string($attr->value) || !\is_string($attr->name)){
107 107
                 continue;
108 108
             }
109 109
             $options[$attr->name] = trim($attr->value, '\'"');
110 110
         }
111 111
 
112
-        switch (\strtolower($tag->name)) {
112
+        switch (\strtolower($tag->name)){
113 113
             case 'use':
114 114
             case 'use:element':
115 115
                 $this->assertHasOption('path', $options, $tag);
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 
156 156
     private function assertHasOption(string $option, array $options, Tag $tag): void
157 157
     {
158
-        if (!isset($options[$option])) {
158
+        if (!isset($options[$option])){
159 159
             throw new ImportException("Missing `{$option}` option", $tag->getContext());
160 160
         }
161 161
     }
Please login to merge, or discard this patch.
Braces   +21 added lines, -10 removed lines patch added patch discarded remove patch
@@ -49,7 +49,8 @@  discard block
 block discarded – undo
49 49
      */
50 50
     public function enterNode($node, VisitorContext $ctx)
51 51
     {
52
-        if ($node instanceof Tag && strpos($node->name, $this->useKeyword) === 0) {
52
+        if ($node instanceof Tag && strpos($node->name, $this->useKeyword) === 0)
53
+        {
53 54
             return self::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
54 55
         }
55 56
 
@@ -61,23 +62,28 @@  discard block
 block discarded – undo
61 62
      */
62 63
     public function leaveNode($node, VisitorContext $ctx)
63 64
     {
64
-        if (!$node instanceof Tag) {
65
+        if (!$node instanceof Tag)
66
+        {
65 67
             return null;
66 68
         }
67 69
 
68 70
         $importCtx = ImportContext::on($ctx);
69 71
 
70 72
         // import definition
71
-        if (\strpos($node->name, $this->useKeyword) === 0) {
73
+        if (\strpos($node->name, $this->useKeyword) === 0)
74
+        {
72 75
             $importCtx->add($this->makeImport($node));
73 76
 
74 77
             return self::REMOVE_NODE;
75 78
         }
76 79
 
77 80
         // imported tag
78
-        try {
81
+        try
82
+        {
79 83
             $import = $importCtx->resolve($this->builder, $node->name);
80
-        } catch (\Throwable $e) {
84
+        }
85
+        catch (\Throwable $e)
86
+        {
81 87
             throw new ImportException(
82 88
                 "Unable to resolve import `{$node->name}`",
83 89
                 $node->getContext(),
@@ -85,7 +91,8 @@  discard block
 block discarded – undo
85 91
             );
86 92
         }
87 93
 
88
-        if ($import !== null) {
94
+        if ($import !== null)
95
+        {
89 96
             $node = $this->merger->merge($import, $node);
90 97
 
91 98
             return $this->merger->isolateNodes($node, $import->getContext()->getPath());
@@ -102,14 +109,17 @@  discard block
 block discarded – undo
102 109
     private function makeImport(Tag $tag): ImportInterface
103 110
     {
104 111
         $options = [];
105
-        foreach ($tag->attrs as $attr) {
106
-            if (!\is_string($attr->value) || !\is_string($attr->name)) {
112
+        foreach ($tag->attrs as $attr)
113
+        {
114
+            if (!\is_string($attr->value) || !\is_string($attr->name))
115
+            {
107 116
                 continue;
108 117
             }
109 118
             $options[$attr->name] = trim($attr->value, '\'"');
110 119
         }
111 120
 
112
-        switch (\strtolower($tag->name)) {
121
+        switch (\strtolower($tag->name))
122
+        {
113 123
             case 'use':
114 124
             case 'use:element':
115 125
                 $this->assertHasOption('path', $options, $tag);
@@ -155,7 +165,8 @@  discard block
 block discarded – undo
155 165
 
156 166
     private function assertHasOption(string $option, array $options, Tag $tag): void
157 167
     {
158
-        if (!isset($options[$option])) {
168
+        if (!isset($options[$option]))
169
+        {
159 170
             throw new ImportException("Missing `{$option}` option", $tag->getContext());
160 171
         }
161 172
     }
Please login to merge, or discard this patch.
src/Stempler/src/Lexer/Lexer.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -38,20 +38,20 @@  discard block
 block discarded – undo
38 38
     public function parse(StreamInterface $src): \Generator
39 39
     {
40 40
         $stream = new Buffer($this->generate($src));
41
-        foreach ($this->grammars as $grammar) {
41
+        foreach ($this->grammars as $grammar){
42 42
             $stream = new Buffer($this->wrap(clone $grammar, $stream));
43 43
         }
44 44
 
45 45
         // always group raw bytes into raw tokens
46
-        foreach ($this->wrap(new RawGrammar(), $stream) as $n) {
46
+        foreach ($this->wrap(new RawGrammar(), $stream) as $n){
47 47
             yield $n;
48 48
         }
49 49
     }
50 50
 
51 51
     private function wrap(GrammarInterface $grammar, Buffer $stream): \Generator
52 52
     {
53
-        foreach ($grammar->parse($stream) as $n) {
54
-            if ($n instanceof Token && $n->grammar === null) {
53
+        foreach ($grammar->parse($stream) as $n){
54
+            if ($n instanceof Token && $n->grammar === null){
55 55
                 $n->grammar = get_class($grammar);
56 56
             }
57 57
 
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      */
67 67
     private function generate(StreamInterface $src)
68 68
     {
69
-        while (!$src->isEOI()) {
69
+        while (!$src->isEOI()){
70 70
             yield new Byte($src->getOffset(), $src->peak());
71 71
         }
72 72
     }
Please login to merge, or discard this patch.
Braces   +10 added lines, -5 removed lines patch added patch discarded remove patch
@@ -38,20 +38,24 @@  discard block
 block discarded – undo
38 38
     public function parse(StreamInterface $src): \Generator
39 39
     {
40 40
         $stream = new Buffer($this->generate($src));
41
-        foreach ($this->grammars as $grammar) {
41
+        foreach ($this->grammars as $grammar)
42
+        {
42 43
             $stream = new Buffer($this->wrap(clone $grammar, $stream));
43 44
         }
44 45
 
45 46
         // always group raw bytes into raw tokens
46
-        foreach ($this->wrap(new RawGrammar(), $stream) as $n) {
47
+        foreach ($this->wrap(new RawGrammar(), $stream) as $n)
48
+        {
47 49
             yield $n;
48 50
         }
49 51
     }
50 52
 
51 53
     private function wrap(GrammarInterface $grammar, Buffer $stream): \Generator
52 54
     {
53
-        foreach ($grammar->parse($stream) as $n) {
54
-            if ($n instanceof Token && $n->grammar === null) {
55
+        foreach ($grammar->parse($stream) as $n)
56
+        {
57
+            if ($n instanceof Token && $n->grammar === null)
58
+            {
55 59
                 $n->grammar = get_class($grammar);
56 60
             }
57 61
 
@@ -66,7 +70,8 @@  discard block
 block discarded – undo
66 70
      */
67 71
     private function generate(StreamInterface $src)
68 72
     {
69
-        while (!$src->isEOI()) {
73
+        while (!$src->isEOI())
74
+        {
70 75
             yield new Byte($src->getOffset(), $src->peak());
71 76
         }
72 77
     }
Please login to merge, or discard this patch.
src/Stempler/src/Lexer/Grammar/HTMLGrammar.php 2 patches
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -59,15 +59,15 @@  discard block
 block discarded – undo
59 59
      */
60 60
     public function parse(Buffer $src): \Generator
61 61
     {
62
-        while ($n = $src->next()) {
63
-            if (!$n instanceof Byte || $n->char !== '<') {
62
+        while ($n = $src->next()){
63
+            if (!$n instanceof Byte || $n->char !== '<'){
64 64
                 yield $n;
65 65
                 continue;
66 66
             }
67 67
 
68 68
             // work with isolated token stream!
69 69
             $tag = (clone $this)->parseGrammar($src);
70
-            if ($tag === null) {
70
+            if ($tag === null){
71 71
                 yield $n;
72 72
                 $src->replay($n->offset);
73 73
                 continue;
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
             $tagName = $this->tagName($tag);
77 77
 
78 78
             // todo: add support for custom tag list
79
-            if (in_array($tagName, self::VERBATIM_TAGS)) {
79
+            if (in_array($tagName, self::VERBATIM_TAGS)){
80 80
                 yield from $tag;
81 81
                 yield from $this->parseVerbatim($src, $tagName);
82 82
                 continue;
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
      */
93 93
     public static function tokenName(int $token): string
94 94
     {
95
-        switch ($token) {
95
+        switch ($token){
96 96
             case self::TYPE_RAW:
97 97
                 return 'HTML:RAW';
98 98
             case self::TYPE_KEYWORD:
@@ -125,26 +125,26 @@  discard block
 block discarded – undo
125 125
     {
126 126
         $chunks = [];
127 127
 
128
-        while ($n = $src->next()) {
129
-            if ($n instanceof Token) {
128
+        while ($n = $src->next()){
129
+            if ($n instanceof Token){
130 130
                 $chunks[] = $n;
131 131
                 continue;
132 132
             }
133 133
 
134
-            switch ($n->char) {
134
+            switch ($n->char){
135 135
                 case '"':
136 136
                 case "'":
137 137
                 case '`':
138 138
                     $chunks[] = $n;
139 139
 
140 140
                     // language inclusions allow nested strings
141
-                    while ($nc = $src->next()) {
141
+                    while ($nc = $src->next()){
142 142
                         $chunks[] = $nc;
143
-                        if ($nc instanceof Token) {
143
+                        if ($nc instanceof Token){
144 144
                             continue;
145 145
                         }
146 146
 
147
-                        if ($nc->char === $n->char) {
147
+                        if ($nc->char === $n->char){
148 148
                             break;
149 149
                         }
150 150
                     }
@@ -155,22 +155,22 @@  discard block
 block discarded – undo
155 155
                     $chunks[] = $n;
156 156
 
157 157
                     $multiline = false;
158
-                    if ($src->lookaheadByte(1) === '/' || $src->lookaheadByte(1) === '*') {
159
-                        if ($src->lookaheadByte(1) === '*') {
158
+                    if ($src->lookaheadByte(1) === '/' || $src->lookaheadByte(1) === '*'){
159
+                        if ($src->lookaheadByte(1) === '*'){
160 160
                             $multiline = true;
161 161
                         }
162 162
 
163 163
                         $chunks[] = $src->next();
164 164
 
165 165
                         // language inclusions allow nested strings
166
-                        while ($nc = $src->next()) {
167
-                            if ($nc instanceof Token) {
166
+                        while ($nc = $src->next()){
167
+                            if ($nc instanceof Token){
168 168
                                 continue;
169 169
                             }
170 170
 
171
-                            if ($nc->char === '<') {
171
+                            if ($nc->char === '<'){
172 172
                                 $tag = (clone $this)->parseGrammar($src);
173
-                                if ($tag === null || $this->tagName($tag) !== $verbatim) {
173
+                                if ($tag === null || $this->tagName($tag) !== $verbatim){
174 174
                                     $src->replay($n->offset);
175 175
                                     break;
176 176
                                 }
@@ -181,12 +181,12 @@  discard block
 block discarded – undo
181 181
 
182 182
                             $chunks[] = $nc;
183 183
 
184
-                            if ($multiline) {
185
-                                if ($nc->char === '*' && $src->lookaheadByte(1) === '/') {
184
+                            if ($multiline){
185
+                                if ($nc->char === '*' && $src->lookaheadByte(1) === '/'){
186 186
                                     $chunks[] = $src->next();
187 187
                                     break;
188 188
                                 }
189
-                            } elseif ($nc->char === "\n") {
189
+                            } elseif ($nc->char === "\n"){
190 190
                                 break;
191 191
                             }
192 192
                         }
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
                 case '<':
198 198
                     // tag beginning?
199 199
                     $tag = (clone $this)->parseGrammar($src);
200
-                    if ($tag === null || $this->tagName($tag) !== $verbatim) {
200
+                    if ($tag === null || $this->tagName($tag) !== $verbatim){
201 201
                         $chunks[] = $n;
202 202
                         $src->replay($n->offset);
203 203
                         break;
@@ -217,8 +217,8 @@  discard block
 block discarded – undo
217 217
 
218 218
     private function tagName(array $tag): string
219 219
     {
220
-        foreach ($tag as $token) {
221
-            if ($token->type === self::TYPE_KEYWORD) {
220
+        foreach ($tag as $token){
221
+            if ($token->type === self::TYPE_KEYWORD){
222 222
                 return strtolower($token->content);
223 223
             }
224 224
         }
@@ -232,28 +232,28 @@  discard block
 block discarded – undo
232 232
             new Token(self::TYPE_OPEN, $src->getOffset(), '<'),
233 233
         ];
234 234
 
235
-        if ($src->lookaheadByte() === '/') {
235
+        if ($src->lookaheadByte() === '/'){
236 236
             $this->tokens[0]->type = self::TYPE_OPEN_SHORT;
237 237
             $this->tokens[0]->content .= $src->next()->char;
238 238
         }
239 239
 
240
-        while ($n = $src->next()) {
241
-            if ($this->attribute !== []) {
240
+        while ($n = $src->next()){
241
+            if ($this->attribute !== []){
242 242
                 $this->attribute[] = $n;
243 243
 
244
-                if ($n instanceof Byte && $n->char === $this->attribute[0]->char) {
244
+                if ($n instanceof Byte && $n->char === $this->attribute[0]->char){
245 245
                     $this->flushAttribute();
246 246
                 }
247 247
 
248 248
                 continue;
249 249
             }
250 250
 
251
-            if ($n instanceof Token) {
251
+            if ($n instanceof Token){
252 252
                 $this->keyword[] = $n;
253 253
                 continue;
254 254
             }
255 255
 
256
-            switch ($n->char) {
256
+            switch ($n->char){
257 257
                 case '"':
258 258
                 case "'":
259 259
                 case '`':
@@ -271,12 +271,12 @@  discard block
 block discarded – undo
271 271
                     break;
272 272
 
273 273
                 case '/':
274
-                    if ($src->lookaheadByte() === '>') {
274
+                    if ($src->lookaheadByte() === '>'){
275 275
                         $this->flush();
276 276
                         $this->tokens[] = new Token(
277 277
                             self::TYPE_CLOSE_SHORT,
278 278
                             $n->offset,
279
-                            $n->char . $src->next()->char
279
+                            $n->char.$src->next()->char
280 280
                         );
281 281
 
282 282
                         break 2;
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
                     break 2;
296 296
 
297 297
                 default:
298
-                    if (preg_match(self::REGEXP_WHITESPACE, $n->char)) {
298
+                    if (preg_match(self::REGEXP_WHITESPACE, $n->char)){
299 299
                         $this->flushKeyword();
300 300
                         $this->whitespace[] = $n;
301 301
                         break;
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
                     $this->flushWhitespace();
304 304
 
305 305
 
306
-                    if (!preg_match(self::REGEXP_KEYWORD, $n->char)) {
306
+                    if (!preg_match(self::REGEXP_KEYWORD, $n->char)){
307 307
                         // unexpected char
308 308
                         return null;
309 309
                     }
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
             }
313 313
         }
314 314
 
315
-        if (!$this->isValid()) {
315
+        if (!$this->isValid()){
316 316
             return null;
317 317
         }
318 318
 
@@ -322,17 +322,17 @@  discard block
 block discarded – undo
322 322
     private function isValid(): bool
323 323
     {
324 324
         // tag is too short or does not have name keyword
325
-        if (count($this->tokens) < 3) {
325
+        if (count($this->tokens) < 3){
326 326
             return false;
327 327
         }
328 328
 
329 329
         $last = $this->tokens[count($this->tokens) - 1];
330
-        if ($last->type !== self::TYPE_CLOSE && $last->type !== self::TYPE_CLOSE_SHORT) {
330
+        if ($last->type !== self::TYPE_CLOSE && $last->type !== self::TYPE_CLOSE_SHORT){
331 331
             return false;
332 332
         }
333 333
 
334
-        foreach ($this->tokens as $token) {
335
-            switch ($token->type) {
334
+        foreach ($this->tokens as $token){
335
+            switch ($token->type){
336 336
                 case self::TYPE_WHITESPACE:
337 337
                     // ignore
338 338
                     continue 2;
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
      */
364 364
     private function flushWhitespace(): void
365 365
     {
366
-        if ($this->whitespace === []) {
366
+        if ($this->whitespace === []){
367 367
             return;
368 368
         }
369 369
 
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
      */
377 377
     private function flushKeyword(): void
378 378
     {
379
-        if ($this->keyword === []) {
379
+        if ($this->keyword === []){
380 380
             return;
381 381
         }
382 382
 
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
      */
390 390
     private function flushAttribute(): void
391 391
     {
392
-        if ($this->attribute === []) {
392
+        if ($this->attribute === []){
393 393
             return;
394 394
         }
395 395
 
Please login to merge, or discard this patch.
Braces   +81 added lines, -40 removed lines patch added patch discarded remove patch
@@ -59,15 +59,18 @@  discard block
 block discarded – undo
59 59
      */
60 60
     public function parse(Buffer $src): \Generator
61 61
     {
62
-        while ($n = $src->next()) {
63
-            if (!$n instanceof Byte || $n->char !== '<') {
62
+        while ($n = $src->next())
63
+        {
64
+            if (!$n instanceof Byte || $n->char !== '<')
65
+            {
64 66
                 yield $n;
65 67
                 continue;
66 68
             }
67 69
 
68 70
             // work with isolated token stream!
69 71
             $tag = (clone $this)->parseGrammar($src);
70
-            if ($tag === null) {
72
+            if ($tag === null)
73
+            {
71 74
                 yield $n;
72 75
                 $src->replay($n->offset);
73 76
                 continue;
@@ -76,7 +79,8 @@  discard block
 block discarded – undo
76 79
             $tagName = $this->tagName($tag);
77 80
 
78 81
             // todo: add support for custom tag list
79
-            if (in_array($tagName, self::VERBATIM_TAGS)) {
82
+            if (in_array($tagName, self::VERBATIM_TAGS))
83
+            {
80 84
                 yield from $tag;
81 85
                 yield from $this->parseVerbatim($src, $tagName);
82 86
                 continue;
@@ -92,7 +96,8 @@  discard block
 block discarded – undo
92 96
      */
93 97
     public static function tokenName(int $token): string
94 98
     {
95
-        switch ($token) {
99
+        switch ($token)
100
+        {
96 101
             case self::TYPE_RAW:
97 102
                 return 'HTML:RAW';
98 103
             case self::TYPE_KEYWORD:
@@ -125,26 +130,32 @@  discard block
 block discarded – undo
125 130
     {
126 131
         $chunks = [];
127 132
 
128
-        while ($n = $src->next()) {
129
-            if ($n instanceof Token) {
133
+        while ($n = $src->next())
134
+        {
135
+            if ($n instanceof Token)
136
+            {
130 137
                 $chunks[] = $n;
131 138
                 continue;
132 139
             }
133 140
 
134
-            switch ($n->char) {
141
+            switch ($n->char)
142
+            {
135 143
                 case '"':
136 144
                 case "'":
137 145
                 case '`':
138 146
                     $chunks[] = $n;
139 147
 
140 148
                     // language inclusions allow nested strings
141
-                    while ($nc = $src->next()) {
149
+                    while ($nc = $src->next())
150
+                    {
142 151
                         $chunks[] = $nc;
143
-                        if ($nc instanceof Token) {
152
+                        if ($nc instanceof Token)
153
+                        {
144 154
                             continue;
145 155
                         }
146 156
 
147
-                        if ($nc->char === $n->char) {
157
+                        if ($nc->char === $n->char)
158
+                        {
148 159
                             break;
149 160
                         }
150 161
                     }
@@ -155,22 +166,28 @@  discard block
 block discarded – undo
155 166
                     $chunks[] = $n;
156 167
 
157 168
                     $multiline = false;
158
-                    if ($src->lookaheadByte(1) === '/' || $src->lookaheadByte(1) === '*') {
159
-                        if ($src->lookaheadByte(1) === '*') {
169
+                    if ($src->lookaheadByte(1) === '/' || $src->lookaheadByte(1) === '*')
170
+                    {
171
+                        if ($src->lookaheadByte(1) === '*')
172
+                        {
160 173
                             $multiline = true;
161 174
                         }
162 175
 
163 176
                         $chunks[] = $src->next();
164 177
 
165 178
                         // language inclusions allow nested strings
166
-                        while ($nc = $src->next()) {
167
-                            if ($nc instanceof Token) {
179
+                        while ($nc = $src->next())
180
+                        {
181
+                            if ($nc instanceof Token)
182
+                            {
168 183
                                 continue;
169 184
                             }
170 185
 
171
-                            if ($nc->char === '<') {
186
+                            if ($nc->char === '<')
187
+                            {
172 188
                                 $tag = (clone $this)->parseGrammar($src);
173
-                                if ($tag === null || $this->tagName($tag) !== $verbatim) {
189
+                                if ($tag === null || $this->tagName($tag) !== $verbatim)
190
+                                {
174 191
                                     $src->replay($n->offset);
175 192
                                     break;
176 193
                                 }
@@ -181,12 +198,16 @@  discard block
 block discarded – undo
181 198
 
182 199
                             $chunks[] = $nc;
183 200
 
184
-                            if ($multiline) {
185
-                                if ($nc->char === '*' && $src->lookaheadByte(1) === '/') {
201
+                            if ($multiline)
202
+                            {
203
+                                if ($nc->char === '*' && $src->lookaheadByte(1) === '/')
204
+                                {
186 205
                                     $chunks[] = $src->next();
187 206
                                     break;
188 207
                                 }
189
-                            } elseif ($nc->char === "\n") {
208
+                            }
209
+                            elseif ($nc->char === "\n")
210
+                            {
190 211
                                 break;
191 212
                             }
192 213
                         }
@@ -197,7 +218,8 @@  discard block
 block discarded – undo
197 218
                 case '<':
198 219
                     // tag beginning?
199 220
                     $tag = (clone $this)->parseGrammar($src);
200
-                    if ($tag === null || $this->tagName($tag) !== $verbatim) {
221
+                    if ($tag === null || $this->tagName($tag) !== $verbatim)
222
+                    {
201 223
                         $chunks[] = $n;
202 224
                         $src->replay($n->offset);
203 225
                         break;
@@ -217,8 +239,10 @@  discard block
 block discarded – undo
217 239
 
218 240
     private function tagName(array $tag): string
219 241
     {
220
-        foreach ($tag as $token) {
221
-            if ($token->type === self::TYPE_KEYWORD) {
242
+        foreach ($tag as $token)
243
+        {
244
+            if ($token->type === self::TYPE_KEYWORD)
245
+            {
222 246
                 return strtolower($token->content);
223 247
             }
224 248
         }
@@ -232,28 +256,34 @@  discard block
 block discarded – undo
232 256
             new Token(self::TYPE_OPEN, $src->getOffset(), '<'),
233 257
         ];
234 258
 
235
-        if ($src->lookaheadByte() === '/') {
259
+        if ($src->lookaheadByte() === '/')
260
+        {
236 261
             $this->tokens[0]->type = self::TYPE_OPEN_SHORT;
237 262
             $this->tokens[0]->content .= $src->next()->char;
238 263
         }
239 264
 
240
-        while ($n = $src->next()) {
241
-            if ($this->attribute !== []) {
265
+        while ($n = $src->next())
266
+        {
267
+            if ($this->attribute !== [])
268
+            {
242 269
                 $this->attribute[] = $n;
243 270
 
244
-                if ($n instanceof Byte && $n->char === $this->attribute[0]->char) {
271
+                if ($n instanceof Byte && $n->char === $this->attribute[0]->char)
272
+                {
245 273
                     $this->flushAttribute();
246 274
                 }
247 275
 
248 276
                 continue;
249 277
             }
250 278
 
251
-            if ($n instanceof Token) {
279
+            if ($n instanceof Token)
280
+            {
252 281
                 $this->keyword[] = $n;
253 282
                 continue;
254 283
             }
255 284
 
256
-            switch ($n->char) {
285
+            switch ($n->char)
286
+            {
257 287
                 case '"':
258 288
                 case "'":
259 289
                 case '`':
@@ -271,7 +301,8 @@  discard block
 block discarded – undo
271 301
                     break;
272 302
 
273 303
                 case '/':
274
-                    if ($src->lookaheadByte() === '>') {
304
+                    if ($src->lookaheadByte() === '>')
305
+                    {
275 306
                         $this->flush();
276 307
                         $this->tokens[] = new Token(
277 308
                             self::TYPE_CLOSE_SHORT,
@@ -295,7 +326,8 @@  discard block
 block discarded – undo
295 326
                     break 2;
296 327
 
297 328
                 default:
298
-                    if (preg_match(self::REGEXP_WHITESPACE, $n->char)) {
329
+                    if (preg_match(self::REGEXP_WHITESPACE, $n->char))
330
+                    {
299 331
                         $this->flushKeyword();
300 332
                         $this->whitespace[] = $n;
301 333
                         break;
@@ -303,7 +335,8 @@  discard block
 block discarded – undo
303 335
                     $this->flushWhitespace();
304 336
 
305 337
 
306
-                    if (!preg_match(self::REGEXP_KEYWORD, $n->char)) {
338
+                    if (!preg_match(self::REGEXP_KEYWORD, $n->char))
339
+                    {
307 340
                         // unexpected char
308 341
                         return null;
309 342
                     }
@@ -312,7 +345,8 @@  discard block
 block discarded – undo
312 345
             }
313 346
         }
314 347
 
315
-        if (!$this->isValid()) {
348
+        if (!$this->isValid())
349
+        {
316 350
             return null;
317 351
         }
318 352
 
@@ -322,17 +356,21 @@  discard block
 block discarded – undo
322 356
     private function isValid(): bool
323 357
     {
324 358
         // tag is too short or does not have name keyword
325
-        if (count($this->tokens) < 3) {
359
+        if (count($this->tokens) < 3)
360
+        {
326 361
             return false;
327 362
         }
328 363
 
329 364
         $last = $this->tokens[count($this->tokens) - 1];
330
-        if ($last->type !== self::TYPE_CLOSE && $last->type !== self::TYPE_CLOSE_SHORT) {
365
+        if ($last->type !== self::TYPE_CLOSE && $last->type !== self::TYPE_CLOSE_SHORT)
366
+        {
331 367
             return false;
332 368
         }
333 369
 
334
-        foreach ($this->tokens as $token) {
335
-            switch ($token->type) {
370
+        foreach ($this->tokens as $token)
371
+        {
372
+            switch ($token->type)
373
+            {
336 374
                 case self::TYPE_WHITESPACE:
337 375
                     // ignore
338 376
                     continue 2;
@@ -363,7 +401,8 @@  discard block
 block discarded – undo
363 401
      */
364 402
     private function flushWhitespace(): void
365 403
     {
366
-        if ($this->whitespace === []) {
404
+        if ($this->whitespace === [])
405
+        {
367 406
             return;
368 407
         }
369 408
 
@@ -376,7 +415,8 @@  discard block
 block discarded – undo
376 415
      */
377 416
     private function flushKeyword(): void
378 417
     {
379
-        if ($this->keyword === []) {
418
+        if ($this->keyword === [])
419
+        {
380 420
             return;
381 421
         }
382 422
 
@@ -389,7 +429,8 @@  discard block
 block discarded – undo
389 429
      */
390 430
     private function flushAttribute(): void
391 431
     {
392
-        if ($this->attribute === []) {
432
+        if ($this->attribute === [])
433
+        {
393 434
             return;
394 435
         }
395 436
 
Please login to merge, or discard this patch.