@@ -26,11 +26,11 @@ |
||
26 | 26 | |
27 | 27 | public function store(string $name): void |
28 | 28 | { |
29 | - $this->storage[$name] = file_get_contents($this->dir . $name); |
|
29 | + $this->storage[$name] = file_get_contents($this->dir.$name); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | public function restore(string $name): void |
33 | 33 | { |
34 | - file_put_contents($this->dir . $name, $this->storage[$name]); |
|
34 | + file_put_contents($this->dir.$name, $this->storage[$name]); |
|
35 | 35 | } |
36 | 36 | } |
@@ -57,12 +57,12 @@ |
||
57 | 57 | { |
58 | 58 | $line = 0; |
59 | 59 | |
60 | - for ($i = 0; $i < $offset; $i++) { |
|
61 | - if (!isset($content[$i])) { |
|
60 | + for ($i = 0; $i < $offset; $i++){ |
|
61 | + if (!isset($content[$i])){ |
|
62 | 62 | break; |
63 | 63 | } |
64 | 64 | |
65 | - if ($content[$i] === "\n") { |
|
65 | + if ($content[$i] === "\n"){ |
|
66 | 66 | $line++; |
67 | 67 | } |
68 | 68 | } |
@@ -57,12 +57,15 @@ |
||
57 | 57 | { |
58 | 58 | $line = 0; |
59 | 59 | |
60 | - for ($i = 0; $i < $offset; $i++) { |
|
61 | - if (!isset($content[$i])) { |
|
60 | + for ($i = 0; $i < $offset; $i++) |
|
61 | + { |
|
62 | + if (!isset($content[$i])) |
|
63 | + { |
|
62 | 64 | break; |
63 | 65 | } |
64 | 66 | |
65 | - if ($content[$i] === "\n") { |
|
67 | + if ($content[$i] === "\n") |
|
68 | + { |
|
66 | 69 | $line++; |
67 | 70 | } |
68 | 71 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | */ |
33 | 33 | public function load(string $path): Source |
34 | 34 | { |
35 | - if (!array_key_exists($path, $this->paths)) { |
|
35 | + if (!array_key_exists($path, $this->paths)){ |
|
36 | 36 | throw new LoaderException("Unable to load path `{$path}`"); |
37 | 37 | } |
38 | 38 |
@@ -32,7 +32,8 @@ |
||
32 | 32 | */ |
33 | 33 | public function load(string $path): Source |
34 | 34 | { |
35 | - if (!array_key_exists($path, $this->paths)) { |
|
35 | + if (!array_key_exists($path, $this->paths)) |
|
36 | + { |
|
36 | 37 | throw new LoaderException("Unable to load path `{$path}`"); |
37 | 38 | } |
38 | 39 |
@@ -50,7 +50,7 @@ |
||
50 | 50 | $this->extension |
51 | 51 | ); |
52 | 52 | |
53 | - if (!file_exists($filename)) { |
|
53 | + if (!file_exists($filename)){ |
|
54 | 54 | throw new LoaderException("Unable to load `{$path}`, no such file"); |
55 | 55 | } |
56 | 56 |
@@ -50,7 +50,8 @@ |
||
50 | 50 | $this->extension |
51 | 51 | ); |
52 | 52 | |
53 | - if (!file_exists($filename)) { |
|
53 | + if (!file_exists($filename)) |
|
54 | + { |
|
54 | 55 | throw new LoaderException("Unable to load `{$path}`, no such file"); |
55 | 56 | } |
56 | 57 |
@@ -51,17 +51,17 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function push(string $name, Tag $child, string $uniqueID = null): bool |
53 | 53 | { |
54 | - foreach ($this->getStacks() as $stack) { |
|
55 | - if ($stack->accepts($name) !== $name) { |
|
54 | + foreach ($this->getStacks() as $stack){ |
|
55 | + if ($stack->accepts($name) !== $name){ |
|
56 | 56 | continue; |
57 | 57 | } |
58 | 58 | |
59 | - if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) { |
|
59 | + if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])){ |
|
60 | 60 | return true; |
61 | 61 | } |
62 | 62 | $stack->uniqueIDs[$uniqueID] = true; |
63 | 63 | |
64 | - foreach ($child->nodes as $child) { |
|
64 | + foreach ($child->nodes as $child){ |
|
65 | 65 | $stack->nodes[] = $child; |
66 | 66 | } |
67 | 67 | |
@@ -79,17 +79,17 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public function prepend(string $name, Tag $child, string $uniqueID = null): bool |
81 | 81 | { |
82 | - foreach ($this->getStacks() as $stack) { |
|
83 | - if ($stack->accepts($name) !== $name) { |
|
82 | + foreach ($this->getStacks() as $stack){ |
|
83 | + if ($stack->accepts($name) !== $name){ |
|
84 | 84 | continue; |
85 | 85 | } |
86 | 86 | |
87 | - if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) { |
|
87 | + if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])){ |
|
88 | 88 | return true; |
89 | 89 | } |
90 | 90 | $stack->uniqueIDs[$uniqueID] = true; |
91 | 91 | |
92 | - foreach ($child->nodes as $child) { |
|
92 | + foreach ($child->nodes as $child){ |
|
93 | 93 | array_unshift($stack->nodes, $child); |
94 | 94 | } |
95 | 95 | |
@@ -107,9 +107,9 @@ discard block |
||
107 | 107 | public function getStacks(): array |
108 | 108 | { |
109 | 109 | $stacks = []; |
110 | - foreach (array_reverse($this->ctx->getScope()) as $node) { |
|
111 | - if ($node instanceof AttributedInterface) { |
|
112 | - foreach ($node->getAttribute(self::class, []) as $stack) { |
|
110 | + foreach (array_reverse($this->ctx->getScope()) as $node){ |
|
111 | + if ($node instanceof AttributedInterface){ |
|
112 | + foreach ($node->getAttribute(self::class, []) as $stack){ |
|
113 | 113 | $stacks[] = $stack; |
114 | 114 | } |
115 | 115 | } |
@@ -133,16 +133,16 @@ discard block |
||
133 | 133 | */ |
134 | 134 | private function getStackRootNode(int $level): AttributedInterface |
135 | 135 | { |
136 | - if ($level === 0) { |
|
136 | + if ($level === 0){ |
|
137 | 137 | $node = $this->ctx->getParentNode(); |
138 | - } else { |
|
138 | + }else{ |
|
139 | 139 | $scope = $this->ctx->getScope(); |
140 | 140 | |
141 | 141 | // looking for the parent node via given nesting level |
142 | 142 | $node = $scope[count($scope) - 2 - $level] ?? $this->ctx->getFirstNode(); |
143 | 143 | } |
144 | 144 | |
145 | - if (!$node instanceof AttributedInterface) { |
|
145 | + if (!$node instanceof AttributedInterface){ |
|
146 | 146 | throw new \LogicException( |
147 | 147 | sprintf( |
148 | 148 | 'Unable to create import on node without attribute storage (%s)', |
@@ -51,17 +51,21 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function push(string $name, Tag $child, string $uniqueID = null): bool |
53 | 53 | { |
54 | - foreach ($this->getStacks() as $stack) { |
|
55 | - if ($stack->accepts($name) !== $name) { |
|
54 | + foreach ($this->getStacks() as $stack) |
|
55 | + { |
|
56 | + if ($stack->accepts($name) !== $name) |
|
57 | + { |
|
56 | 58 | continue; |
57 | 59 | } |
58 | 60 | |
59 | - if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) { |
|
61 | + if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) |
|
62 | + { |
|
60 | 63 | return true; |
61 | 64 | } |
62 | 65 | $stack->uniqueIDs[$uniqueID] = true; |
63 | 66 | |
64 | - foreach ($child->nodes as $child) { |
|
67 | + foreach ($child->nodes as $child) |
|
68 | + { |
|
65 | 69 | $stack->nodes[] = $child; |
66 | 70 | } |
67 | 71 | |
@@ -79,17 +83,21 @@ discard block |
||
79 | 83 | */ |
80 | 84 | public function prepend(string $name, Tag $child, string $uniqueID = null): bool |
81 | 85 | { |
82 | - foreach ($this->getStacks() as $stack) { |
|
83 | - if ($stack->accepts($name) !== $name) { |
|
86 | + foreach ($this->getStacks() as $stack) |
|
87 | + { |
|
88 | + if ($stack->accepts($name) !== $name) |
|
89 | + { |
|
84 | 90 | continue; |
85 | 91 | } |
86 | 92 | |
87 | - if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) { |
|
93 | + if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) |
|
94 | + { |
|
88 | 95 | return true; |
89 | 96 | } |
90 | 97 | $stack->uniqueIDs[$uniqueID] = true; |
91 | 98 | |
92 | - foreach ($child->nodes as $child) { |
|
99 | + foreach ($child->nodes as $child) |
|
100 | + { |
|
93 | 101 | array_unshift($stack->nodes, $child); |
94 | 102 | } |
95 | 103 | |
@@ -107,9 +115,12 @@ discard block |
||
107 | 115 | public function getStacks(): array |
108 | 116 | { |
109 | 117 | $stacks = []; |
110 | - foreach (array_reverse($this->ctx->getScope()) as $node) { |
|
111 | - if ($node instanceof AttributedInterface) { |
|
112 | - foreach ($node->getAttribute(self::class, []) as $stack) { |
|
118 | + foreach (array_reverse($this->ctx->getScope()) as $node) |
|
119 | + { |
|
120 | + if ($node instanceof AttributedInterface) |
|
121 | + { |
|
122 | + foreach ($node->getAttribute(self::class, []) as $stack) |
|
123 | + { |
|
113 | 124 | $stacks[] = $stack; |
114 | 125 | } |
115 | 126 | } |
@@ -133,16 +144,20 @@ discard block |
||
133 | 144 | */ |
134 | 145 | private function getStackRootNode(int $level): AttributedInterface |
135 | 146 | { |
136 | - if ($level === 0) { |
|
147 | + if ($level === 0) |
|
148 | + { |
|
137 | 149 | $node = $this->ctx->getParentNode(); |
138 | - } else { |
|
150 | + } |
|
151 | + else |
|
152 | + { |
|
139 | 153 | $scope = $this->ctx->getScope(); |
140 | 154 | |
141 | 155 | // looking for the parent node via given nesting level |
142 | 156 | $node = $scope[count($scope) - 2 - $level] ?? $this->ctx->getFirstNode(); |
143 | 157 | } |
144 | 158 | |
145 | - if (!$node instanceof AttributedInterface) { |
|
159 | + if (!$node instanceof AttributedInterface) |
|
160 | + { |
|
146 | 161 | throw new \LogicException( |
147 | 162 | sprintf( |
148 | 163 | 'Unable to create import on node without attribute storage (%s)', |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | public function add(ImportInterface $import): void |
42 | 42 | { |
43 | 43 | $node = $this->ctx->getParentNode(); |
44 | - if (!$node instanceof AttributedInterface) { |
|
44 | + if (!$node instanceof AttributedInterface){ |
|
45 | 45 | throw new LogicException(sprintf( |
46 | 46 | 'Unable to create import on node without attribute storage (%s)', |
47 | 47 | is_object($node) ? get_class($node) : gettype($node) |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function resolve(Builder $builder, string $name): ?Template |
66 | 66 | { |
67 | - foreach ($this->getImports() as $import) { |
|
67 | + foreach ($this->getImports() as $import){ |
|
68 | 68 | $tpl = $import->resolve($builder, $name); |
69 | - if ($tpl !== null) { |
|
69 | + if ($tpl !== null){ |
|
70 | 70 | return $tpl; |
71 | 71 | } |
72 | 72 | } |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | public function getImports(): array |
83 | 83 | { |
84 | 84 | $imports = []; |
85 | - foreach (array_reverse($this->ctx->getScope()) as $node) { |
|
86 | - if ($node instanceof AttributedInterface) { |
|
87 | - foreach ($node->getAttribute(self::class, []) as $import) { |
|
85 | + foreach (array_reverse($this->ctx->getScope()) as $node){ |
|
86 | + if ($node instanceof AttributedInterface){ |
|
87 | + foreach ($node->getAttribute(self::class, []) as $import){ |
|
88 | 88 | $imports[] = $import; |
89 | 89 | } |
90 | 90 | } |
@@ -41,7 +41,8 @@ discard block |
||
41 | 41 | public function add(ImportInterface $import): void |
42 | 42 | { |
43 | 43 | $node = $this->ctx->getParentNode(); |
44 | - if (!$node instanceof AttributedInterface) { |
|
44 | + if (!$node instanceof AttributedInterface) |
|
45 | + { |
|
45 | 46 | throw new LogicException(sprintf( |
46 | 47 | 'Unable to create import on node without attribute storage (%s)', |
47 | 48 | is_object($node) ? get_class($node) : gettype($node) |
@@ -64,9 +65,11 @@ discard block |
||
64 | 65 | */ |
65 | 66 | public function resolve(Builder $builder, string $name): ?Template |
66 | 67 | { |
67 | - foreach ($this->getImports() as $import) { |
|
68 | + foreach ($this->getImports() as $import) |
|
69 | + { |
|
68 | 70 | $tpl = $import->resolve($builder, $name); |
69 | - if ($tpl !== null) { |
|
71 | + if ($tpl !== null) |
|
72 | + { |
|
70 | 73 | return $tpl; |
71 | 74 | } |
72 | 75 | } |
@@ -82,9 +85,12 @@ discard block |
||
82 | 85 | public function getImports(): array |
83 | 86 | { |
84 | 87 | $imports = []; |
85 | - foreach (array_reverse($this->ctx->getScope()) as $node) { |
|
86 | - if ($node instanceof AttributedInterface) { |
|
87 | - foreach ($node->getAttribute(self::class, []) as $import) { |
|
88 | + foreach (array_reverse($this->ctx->getScope()) as $node) |
|
89 | + { |
|
90 | + if ($node instanceof AttributedInterface) |
|
91 | + { |
|
92 | + foreach ($node->getAttribute(self::class, []) as $import) |
|
93 | + { |
|
88 | 94 | $imports[] = $import; |
89 | 95 | } |
90 | 96 | } |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | { |
32 | 32 | $blocks = ['context' => []]; |
33 | 33 | |
34 | - foreach ($caller->attrs as $attr) { |
|
35 | - if (!$attr instanceof Attr || $attr->name instanceof NodeInterface) { |
|
34 | + foreach ($caller->attrs as $attr){ |
|
35 | + if (!$attr instanceof Attr || $attr->name instanceof NodeInterface){ |
|
36 | 36 | // ignore name when attribute is dynamic |
37 | 37 | $blocks[sprintf('attr-%s', count($blocks))] = $attr; |
38 | 38 | continue; |
@@ -42,15 +42,15 @@ discard block |
||
42 | 42 | $blocks[$attr->name] = new QuotedValue($attr->value); |
43 | 43 | } |
44 | 44 | |
45 | - foreach ($caller->nodes as $node) { |
|
46 | - if ($node instanceof Block) { |
|
45 | + foreach ($caller->nodes as $node){ |
|
46 | + if ($node instanceof Block){ |
|
47 | 47 | $blocks[$node->name] = $node->nodes; |
48 | - } else { |
|
48 | + }else{ |
|
49 | 49 | $blocks['context'][] = $node; |
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
53 | - if ($blocks['context'] === []) { |
|
53 | + if ($blocks['context'] === []){ |
|
54 | 54 | unset($blocks['context']); |
55 | 55 | } |
56 | 56 |
@@ -31,8 +31,10 @@ discard block |
||
31 | 31 | { |
32 | 32 | $blocks = ['context' => []]; |
33 | 33 | |
34 | - foreach ($caller->attrs as $attr) { |
|
35 | - if (!$attr instanceof Attr || $attr->name instanceof NodeInterface) { |
|
34 | + foreach ($caller->attrs as $attr) |
|
35 | + { |
|
36 | + if (!$attr instanceof Attr || $attr->name instanceof NodeInterface) |
|
37 | + { |
|
36 | 38 | // ignore name when attribute is dynamic |
37 | 39 | $blocks[sprintf('attr-%s', count($blocks))] = $attr; |
38 | 40 | continue; |
@@ -42,15 +44,20 @@ discard block |
||
42 | 44 | $blocks[$attr->name] = new QuotedValue($attr->value); |
43 | 45 | } |
44 | 46 | |
45 | - foreach ($caller->nodes as $node) { |
|
46 | - if ($node instanceof Block) { |
|
47 | + foreach ($caller->nodes as $node) |
|
48 | + { |
|
49 | + if ($node instanceof Block) |
|
50 | + { |
|
47 | 51 | $blocks[$node->name] = $node->nodes; |
48 | - } else { |
|
52 | + } |
|
53 | + else |
|
54 | + { |
|
49 | 55 | $blocks['context'][] = $node; |
50 | 56 | } |
51 | 57 | } |
52 | 58 | |
53 | - if ($blocks['context'] === []) { |
|
59 | + if ($blocks['context'] === []) |
|
60 | + { |
|
54 | 61 | unset($blocks['context']); |
55 | 62 | } |
56 | 63 |
@@ -96,7 +96,7 @@ |
||
96 | 96 | protected function traverse(array $nodes, VisitorInterface ...$visitors) |
97 | 97 | { |
98 | 98 | $traverser = new Traverser(); |
99 | - foreach ($visitors as $visitor) { |
|
99 | + foreach ($visitors as $visitor){ |
|
100 | 100 | $traverser->addVisitor($visitor); |
101 | 101 | } |
102 | 102 |
@@ -96,7 +96,8 @@ |
||
96 | 96 | protected function traverse(array $nodes, VisitorInterface ...$visitors) |
97 | 97 | { |
98 | 98 | $traverser = new Traverser(); |
99 | - foreach ($visitors as $visitor) { |
|
99 | + foreach ($visitors as $visitor) |
|
100 | + { |
|
100 | 101 | $traverser->addVisitor($visitor); |
101 | 102 | } |
102 | 103 |
@@ -36,7 +36,7 @@ |
||
36 | 36 | */ |
37 | 37 | public function enterNode($node, VisitorContext $ctx): void |
38 | 38 | { |
39 | - if ($node instanceof Block && $node->getContext()->getPath() === $this->path) { |
|
39 | + if ($node instanceof Block && $node->getContext()->getPath() === $this->path){ |
|
40 | 40 | $node->name = null; |
41 | 41 | } |
42 | 42 | } |
@@ -36,7 +36,8 @@ |
||
36 | 36 | */ |
37 | 37 | public function enterNode($node, VisitorContext $ctx): void |
38 | 38 | { |
39 | - if ($node instanceof Block && $node->getContext()->getPath() === $this->path) { |
|
39 | + if ($node instanceof Block && $node->getContext()->getPath() === $this->path) |
|
40 | + { |
|
40 | 41 | $node->name = null; |
41 | 42 | } |
42 | 43 | } |