@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function addUses(array $uses): self |
58 | 58 | { |
59 | - foreach ($uses as $class => $alias) { |
|
59 | + foreach ($uses as $class => $alias){ |
|
60 | 60 | $this->addUse($class, $alias); |
61 | 61 | } |
62 | 62 | |
@@ -112,12 +112,12 @@ discard block |
||
112 | 112 | private function renderUses(int $indentLevel = 0): string |
113 | 113 | { |
114 | 114 | $lines = []; |
115 | - foreach ($this->getUses() as $class => $alias) { |
|
115 | + foreach ($this->getUses() as $class => $alias){ |
|
116 | 116 | $line = "use {$class}"; |
117 | 117 | |
118 | - if (!empty($alias)) { |
|
118 | + if (!empty($alias)){ |
|
119 | 119 | $line .= " as {$alias};"; |
120 | - } else { |
|
120 | + }else{ |
|
121 | 121 | $line .= ';'; |
122 | 122 | } |
123 | 123 |
@@ -56,7 +56,8 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function addUses(array $uses): self |
58 | 58 | { |
59 | - foreach ($uses as $class => $alias) { |
|
59 | + foreach ($uses as $class => $alias) |
|
60 | + { |
|
60 | 61 | $this->addUse($class, $alias); |
61 | 62 | } |
62 | 63 | |
@@ -112,12 +113,16 @@ discard block |
||
112 | 113 | private function renderUses(int $indentLevel = 0): string |
113 | 114 | { |
114 | 115 | $lines = []; |
115 | - foreach ($this->getUses() as $class => $alias) { |
|
116 | + foreach ($this->getUses() as $class => $alias) |
|
117 | + { |
|
116 | 118 | $line = "use {$class}"; |
117 | 119 | |
118 | - if (!empty($alias)) { |
|
120 | + if (!empty($alias)) |
|
121 | + { |
|
119 | 122 | $line .= " as {$alias};"; |
120 | - } else { |
|
123 | + } |
|
124 | + else |
|
125 | + { |
|
121 | 126 | $line .= ';'; |
122 | 127 | } |
123 | 128 |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function serialize($value): string |
37 | 37 | { |
38 | - if (is_array($value)) { |
|
38 | + if (is_array($value)){ |
|
39 | 39 | return $this->packArray($value); |
40 | 40 | } |
41 | 41 | |
@@ -50,49 +50,49 @@ discard block |
||
50 | 50 | */ |
51 | 51 | protected function packArray(array $array, int $level = 0): string |
52 | 52 | { |
53 | - if ($array === []) { |
|
53 | + if ($array === []){ |
|
54 | 54 | return '[]'; |
55 | 55 | } |
56 | 56 | //Delimiters between rows and sub-arrays. |
57 | - $subIndent = "\n" . str_repeat(self::INDENT, $level + 2); |
|
58 | - $keyIndent = "\n" . str_repeat(self::INDENT, $level + 1); |
|
57 | + $subIndent = "\n".str_repeat(self::INDENT, $level + 2); |
|
58 | + $keyIndent = "\n".str_repeat(self::INDENT, $level + 1); |
|
59 | 59 | //No keys for associated array |
60 | 60 | $associated = array_diff_key($array, array_keys(array_keys($array))); |
61 | 61 | $result = []; |
62 | 62 | $innerIndent = 0; |
63 | - if (!empty($associated)) { |
|
64 | - foreach ($array as $key => $value) { |
|
63 | + if (!empty($associated)){ |
|
64 | + foreach ($array as $key => $value){ |
|
65 | 65 | //Based on biggest key length |
66 | 66 | $innerIndent = max(strlen(var_export($key, true)), $innerIndent); |
67 | 67 | } |
68 | 68 | } |
69 | - foreach ($array as $key => $value) { |
|
69 | + foreach ($array as $key => $value){ |
|
70 | 70 | $prefix = ''; |
71 | - if (!empty($associated)) { |
|
71 | + if (!empty($associated)){ |
|
72 | 72 | //Key prefix |
73 | 73 | $prefix = str_pad( |
74 | 74 | var_export($key, true), |
75 | 75 | $innerIndent, |
76 | 76 | ' ', |
77 | 77 | STR_PAD_RIGHT |
78 | - ) . ' => '; |
|
78 | + ).' => '; |
|
79 | 79 | } |
80 | - if (!is_array($value)) { |
|
81 | - $result[] = $prefix . $this->packValue($value); |
|
80 | + if (!is_array($value)){ |
|
81 | + $result[] = $prefix.$this->packValue($value); |
|
82 | 82 | continue; |
83 | 83 | } |
84 | - if ($value === []) { |
|
85 | - $result[] = $prefix . '[]'; |
|
84 | + if ($value === []){ |
|
85 | + $result[] = $prefix.'[]'; |
|
86 | 86 | continue; |
87 | 87 | } |
88 | 88 | $subArray = $this->packArray($value, $level + 1); |
89 | - $result[] = $prefix . "[{$subIndent}" . $subArray . "{$keyIndent}]"; |
|
89 | + $result[] = $prefix."[{$subIndent}".$subArray."{$keyIndent}]"; |
|
90 | 90 | } |
91 | - if ($level !== 0) { |
|
91 | + if ($level !== 0){ |
|
92 | 92 | return $result ? implode(",{$keyIndent}", $result) : ''; |
93 | 93 | } |
94 | 94 | |
95 | - return "[{$keyIndent}" . implode(",{$keyIndent}", $result) . "\n]"; |
|
95 | + return "[{$keyIndent}".implode(",{$keyIndent}", $result)."\n]"; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -105,31 +105,31 @@ discard block |
||
105 | 105 | */ |
106 | 106 | protected function packValue($value): string |
107 | 107 | { |
108 | - if ($value instanceof DeclarationInterface) { |
|
108 | + if ($value instanceof DeclarationInterface){ |
|
109 | 109 | //No indentation here |
110 | 110 | return $value->render(); |
111 | 111 | } |
112 | 112 | |
113 | - if ($value === null) { |
|
113 | + if ($value === null){ |
|
114 | 114 | return 'null'; |
115 | 115 | } |
116 | 116 | |
117 | - if (is_bool($value)) { |
|
117 | + if (is_bool($value)){ |
|
118 | 118 | return ($value ? 'true' : 'false'); |
119 | 119 | } |
120 | 120 | |
121 | - if (is_object($value) && method_exists($value, '__set_state')) { |
|
122 | - return '\\' . var_export($value, true); |
|
121 | + if (is_object($value) && method_exists($value, '__set_state')){ |
|
122 | + return '\\'.var_export($value, true); |
|
123 | 123 | } |
124 | 124 | |
125 | - if (!is_string($value) && !is_numeric($value)) { |
|
125 | + if (!is_string($value) && !is_numeric($value)){ |
|
126 | 126 | throw new SerializeException('Unable to pack non scalar value'); |
127 | 127 | } |
128 | 128 | |
129 | - if (is_string($value) && class_exists($value)) { |
|
129 | + if (is_string($value) && class_exists($value)){ |
|
130 | 130 | $reflection = new ReflectionClass($value); |
131 | - if ($value === $reflection->getName()) { |
|
132 | - return '\\' . $reflection->getName() . '::class'; |
|
131 | + if ($value === $reflection->getName()){ |
|
132 | + return '\\'.$reflection->getName().'::class'; |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 |
@@ -35,7 +35,8 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function serialize($value): string |
37 | 37 | { |
38 | - if (is_array($value)) { |
|
38 | + if (is_array($value)) |
|
39 | + { |
|
39 | 40 | return $this->packArray($value); |
40 | 41 | } |
41 | 42 | |
@@ -50,7 +51,8 @@ discard block |
||
50 | 51 | */ |
51 | 52 | protected function packArray(array $array, int $level = 0): string |
52 | 53 | { |
53 | - if ($array === []) { |
|
54 | + if ($array === []) |
|
55 | + { |
|
54 | 56 | return '[]'; |
55 | 57 | } |
56 | 58 | //Delimiters between rows and sub-arrays. |
@@ -60,15 +62,19 @@ discard block |
||
60 | 62 | $associated = array_diff_key($array, array_keys(array_keys($array))); |
61 | 63 | $result = []; |
62 | 64 | $innerIndent = 0; |
63 | - if (!empty($associated)) { |
|
64 | - foreach ($array as $key => $value) { |
|
65 | + if (!empty($associated)) |
|
66 | + { |
|
67 | + foreach ($array as $key => $value) |
|
68 | + { |
|
65 | 69 | //Based on biggest key length |
66 | 70 | $innerIndent = max(strlen(var_export($key, true)), $innerIndent); |
67 | 71 | } |
68 | 72 | } |
69 | - foreach ($array as $key => $value) { |
|
73 | + foreach ($array as $key => $value) |
|
74 | + { |
|
70 | 75 | $prefix = ''; |
71 | - if (!empty($associated)) { |
|
76 | + if (!empty($associated)) |
|
77 | + { |
|
72 | 78 | //Key prefix |
73 | 79 | $prefix = str_pad( |
74 | 80 | var_export($key, true), |
@@ -77,18 +83,21 @@ discard block |
||
77 | 83 | STR_PAD_RIGHT |
78 | 84 | ) . ' => '; |
79 | 85 | } |
80 | - if (!is_array($value)) { |
|
86 | + if (!is_array($value)) |
|
87 | + { |
|
81 | 88 | $result[] = $prefix . $this->packValue($value); |
82 | 89 | continue; |
83 | 90 | } |
84 | - if ($value === []) { |
|
91 | + if ($value === []) |
|
92 | + { |
|
85 | 93 | $result[] = $prefix . '[]'; |
86 | 94 | continue; |
87 | 95 | } |
88 | 96 | $subArray = $this->packArray($value, $level + 1); |
89 | 97 | $result[] = $prefix . "[{$subIndent}" . $subArray . "{$keyIndent}]"; |
90 | 98 | } |
91 | - if ($level !== 0) { |
|
99 | + if ($level !== 0) |
|
100 | + { |
|
92 | 101 | return $result ? implode(",{$keyIndent}", $result) : ''; |
93 | 102 | } |
94 | 103 | |
@@ -105,30 +114,37 @@ discard block |
||
105 | 114 | */ |
106 | 115 | protected function packValue($value): string |
107 | 116 | { |
108 | - if ($value instanceof DeclarationInterface) { |
|
117 | + if ($value instanceof DeclarationInterface) |
|
118 | + { |
|
109 | 119 | //No indentation here |
110 | 120 | return $value->render(); |
111 | 121 | } |
112 | 122 | |
113 | - if ($value === null) { |
|
123 | + if ($value === null) |
|
124 | + { |
|
114 | 125 | return 'null'; |
115 | 126 | } |
116 | 127 | |
117 | - if (is_bool($value)) { |
|
128 | + if (is_bool($value)) |
|
129 | + { |
|
118 | 130 | return ($value ? 'true' : 'false'); |
119 | 131 | } |
120 | 132 | |
121 | - if (is_object($value) && method_exists($value, '__set_state')) { |
|
133 | + if (is_object($value) && method_exists($value, '__set_state')) |
|
134 | + { |
|
122 | 135 | return '\\' . var_export($value, true); |
123 | 136 | } |
124 | 137 | |
125 | - if (!is_string($value) && !is_numeric($value)) { |
|
138 | + if (!is_string($value) && !is_numeric($value)) |
|
139 | + { |
|
126 | 140 | throw new SerializeException('Unable to pack non scalar value'); |
127 | 141 | } |
128 | 142 | |
129 | - if (is_string($value) && class_exists($value)) { |
|
143 | + if (is_string($value) && class_exists($value)) |
|
144 | + { |
|
130 | 145 | $reflection = new ReflectionClass($value); |
131 | - if ($value === $reflection->getName()) { |
|
146 | + if ($value === $reflection->getName()) |
|
147 | + { |
|
132 | 148 | return '\\' . $reflection->getName() . '::class'; |
133 | 149 | } |
134 | 150 | } |
@@ -38,12 +38,12 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function render(int $indentLevel = 0): string |
40 | 40 | { |
41 | - if ($this->isEmpty()) { |
|
41 | + if ($this->isEmpty()){ |
|
42 | 42 | return ''; |
43 | 43 | } |
44 | 44 | |
45 | 45 | $result = $this->addIndent("/**\n", $indentLevel); |
46 | - foreach ($this->getLines() as $line) { |
|
46 | + foreach ($this->getLines() as $line){ |
|
47 | 47 | $result .= $this->addIndent(" * {$line}\n", $indentLevel); |
48 | 48 | } |
49 | 49 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | protected function prepareLine(string $line): ?string |
59 | 59 | { |
60 | 60 | $line = trim($line); |
61 | - if (in_array($line, ['/*', '/**', '*/'], true)) { |
|
61 | + if (in_array($line, ['/*', '/**', '*/'], true)){ |
|
62 | 62 | return null; |
63 | 63 | } |
64 | 64 |
@@ -38,12 +38,14 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function render(int $indentLevel = 0): string |
40 | 40 | { |
41 | - if ($this->isEmpty()) { |
|
41 | + if ($this->isEmpty()) |
|
42 | + { |
|
42 | 43 | return ''; |
43 | 44 | } |
44 | 45 | |
45 | 46 | $result = $this->addIndent("/**\n", $indentLevel); |
46 | - foreach ($this->getLines() as $line) { |
|
47 | + foreach ($this->getLines() as $line) |
|
48 | + { |
|
47 | 49 | $result .= $this->addIndent(" * {$line}\n", $indentLevel); |
48 | 50 | } |
49 | 51 | |
@@ -58,7 +60,8 @@ discard block |
||
58 | 60 | protected function prepareLine(string $line): ?string |
59 | 61 | { |
60 | 62 | $line = trim($line); |
61 | - if (in_array($line, ['/*', '/**', '*/'], true)) { |
|
63 | + if (in_array($line, ['/*', '/**', '*/'], true)) |
|
64 | + { |
|
62 | 65 | return null; |
63 | 66 | } |
64 | 67 |
@@ -89,18 +89,18 @@ discard block |
||
89 | 89 | public function render(int $indentLevel = 0): string |
90 | 90 | { |
91 | 91 | $result = ''; |
92 | - if (!$this->docComment->isEmpty()) { |
|
93 | - $result .= $this->docComment->render($indentLevel) . "\n"; |
|
92 | + if (!$this->docComment->isEmpty()){ |
|
93 | + $result .= $this->docComment->render($indentLevel)."\n"; |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | $result .= $this->addIndent("{$this->access} const {$this->getName()} = ", $indentLevel); |
97 | 97 | |
98 | 98 | $value = $this->getSerializer()->serialize($this->value); |
99 | - if (is_array($this->value)) { |
|
99 | + if (is_array($this->value)){ |
|
100 | 100 | $value = $this->mountIndents($value, $indentLevel); |
101 | 101 | } |
102 | 102 | |
103 | - return $result . "{$value};"; |
|
103 | + return $result."{$value};"; |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | private function mountIndents(string $serialized, int $indentLevel): string |
114 | 114 | { |
115 | 115 | $lines = explode("\n", $serialized); |
116 | - foreach ($lines as &$line) { |
|
116 | + foreach ($lines as &$line){ |
|
117 | 117 | $line = $this->addIndent($line, $indentLevel); |
118 | 118 | unset($line); |
119 | 119 | } |
@@ -89,14 +89,16 @@ discard block |
||
89 | 89 | public function render(int $indentLevel = 0): string |
90 | 90 | { |
91 | 91 | $result = ''; |
92 | - if (!$this->docComment->isEmpty()) { |
|
92 | + if (!$this->docComment->isEmpty()) |
|
93 | + { |
|
93 | 94 | $result .= $this->docComment->render($indentLevel) . "\n"; |
94 | 95 | } |
95 | 96 | |
96 | 97 | $result .= $this->addIndent("{$this->access} const {$this->getName()} = ", $indentLevel); |
97 | 98 | |
98 | 99 | $value = $this->getSerializer()->serialize($this->value); |
99 | - if (is_array($this->value)) { |
|
100 | + if (is_array($this->value)) |
|
101 | + { |
|
100 | 102 | $value = $this->mountIndents($value, $indentLevel); |
101 | 103 | } |
102 | 104 | |
@@ -113,7 +115,8 @@ discard block |
||
113 | 115 | private function mountIndents(string $serialized, int $indentLevel): string |
114 | 116 | { |
115 | 117 | $lines = explode("\n", $serialized); |
116 | - foreach ($lines as &$line) { |
|
118 | + foreach ($lines as &$line) |
|
119 | + { |
|
117 | 120 | $line = $this->addIndent($line, $indentLevel); |
118 | 121 | unset($line); |
119 | 122 | } |
@@ -148,16 +148,16 @@ |
||
148 | 148 | public function render(int $indentLevel = 0): string |
149 | 149 | { |
150 | 150 | $type = ''; |
151 | - if (!empty($this->type)) { |
|
152 | - $type = $this->type . ' '; |
|
151 | + if (!empty($this->type)){ |
|
152 | + $type = $this->type.' '; |
|
153 | 153 | } |
154 | 154 | |
155 | - $result = $type . ($this->pdb ? '&' : '') . '$' . $this->getName(); |
|
155 | + $result = $type.($this->pdb ? '&' : '').'$'.$this->getName(); |
|
156 | 156 | |
157 | - if (!$this->isOptional) { |
|
157 | + if (!$this->isOptional){ |
|
158 | 158 | return $result; |
159 | 159 | } |
160 | 160 | |
161 | - return $result . ' = ' . $this->getSerializer()->serialize($this->defaultValue); |
|
161 | + return $result.' = '.$this->getSerializer()->serialize($this->defaultValue); |
|
162 | 162 | } |
163 | 163 | } |
@@ -148,13 +148,15 @@ |
||
148 | 148 | public function render(int $indentLevel = 0): string |
149 | 149 | { |
150 | 150 | $type = ''; |
151 | - if (!empty($this->type)) { |
|
151 | + if (!empty($this->type)) |
|
152 | + { |
|
152 | 153 | $type = $this->type . ' '; |
153 | 154 | } |
154 | 155 | |
155 | 156 | $result = $type . ($this->pdb ? '&' : '') . '$' . $this->getName(); |
156 | 157 | |
157 | - if (!$this->isOptional) { |
|
158 | + if (!$this->isOptional) |
|
159 | + { |
|
158 | 160 | return $result; |
159 | 161 | } |
160 | 162 |
@@ -31,10 +31,10 @@ |
||
31 | 31 | */ |
32 | 32 | public function render(int $indentLevel = 0): string |
33 | 33 | { |
34 | - if (empty($this->directives)) { |
|
34 | + if (empty($this->directives)){ |
|
35 | 35 | return ''; |
36 | 36 | } |
37 | 37 | |
38 | - return 'declare(' . implode(', ', $this->directives) . ');'; |
|
38 | + return 'declare('.implode(', ', $this->directives).');'; |
|
39 | 39 | } |
40 | 40 | } |
@@ -31,7 +31,8 @@ |
||
31 | 31 | */ |
32 | 32 | public function render(int $indentLevel = 0): string |
33 | 33 | { |
34 | - if (empty($this->directives)) { |
|
34 | + if (empty($this->directives)) |
|
35 | + { |
|
35 | 36 | return ''; |
36 | 37 | } |
37 | 38 |
@@ -101,10 +101,10 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public function setSource($source): Method |
103 | 103 | { |
104 | - if (!empty($source)) { |
|
105 | - if (is_array($source)) { |
|
104 | + if (!empty($source)){ |
|
105 | + if (is_array($source)){ |
|
106 | 106 | $this->source->setLines($source); |
107 | - } elseif (is_string($source)) { |
|
107 | + } elseif (is_string($source)){ |
|
108 | 108 | $this->source->setString($source); |
109 | 109 | } |
110 | 110 | } |
@@ -147,26 +147,26 @@ discard block |
||
147 | 147 | public function render(int $indentLevel = 0): string |
148 | 148 | { |
149 | 149 | $result = ''; |
150 | - if (!$this->docComment->isEmpty()) { |
|
151 | - $result .= $this->docComment->render($indentLevel) . "\n"; |
|
150 | + if (!$this->docComment->isEmpty()){ |
|
151 | + $result .= $this->docComment->render($indentLevel)."\n"; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | $method = $this->renderModifiers(); |
155 | - if (!$this->parameters->isEmpty()) { |
|
155 | + if (!$this->parameters->isEmpty()){ |
|
156 | 156 | $method .= "({$this->parameters->render()})"; |
157 | - } else { |
|
157 | + }else{ |
|
158 | 158 | $method .= '()'; |
159 | 159 | } |
160 | 160 | |
161 | - if ($this->return) { |
|
161 | + if ($this->return){ |
|
162 | 162 | $method .= ": {$this->return}"; |
163 | 163 | } |
164 | 164 | |
165 | - $result .= $this->addIndent($method, $indentLevel) . "\n"; |
|
166 | - $result .= $this->addIndent('{', $indentLevel) . "\n"; |
|
165 | + $result .= $this->addIndent($method, $indentLevel)."\n"; |
|
166 | + $result .= $this->addIndent('{', $indentLevel)."\n"; |
|
167 | 167 | |
168 | - if (!$this->source->isEmpty()) { |
|
169 | - $result .= $this->source->render($indentLevel + 1) . "\n"; |
|
168 | + if (!$this->source->isEmpty()){ |
|
169 | + $result .= $this->source->render($indentLevel + 1)."\n"; |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | $result .= $this->addIndent('}', $indentLevel); |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | { |
182 | 182 | $chunks = [$this->getAccess()]; |
183 | 183 | |
184 | - if ($this->isStatic()) { |
|
184 | + if ($this->isStatic()){ |
|
185 | 185 | $chunks[] = 'static'; |
186 | 186 | } |
187 | 187 | |
@@ -197,14 +197,14 @@ discard block |
||
197 | 197 | */ |
198 | 198 | private function initSource($source): void |
199 | 199 | { |
200 | - if (empty($this->source)) { |
|
200 | + if (empty($this->source)){ |
|
201 | 201 | $this->source = new Source(); |
202 | 202 | } |
203 | 203 | |
204 | - if (!empty($source)) { |
|
205 | - if (is_array($source)) { |
|
204 | + if (!empty($source)){ |
|
205 | + if (is_array($source)){ |
|
206 | 206 | $this->source->setLines($source); |
207 | - } elseif (is_string($source)) { |
|
207 | + } elseif (is_string($source)){ |
|
208 | 208 | $this->source->setString($source); |
209 | 209 | } |
210 | 210 | } |
@@ -101,10 +101,14 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public function setSource($source): Method |
103 | 103 | { |
104 | - if (!empty($source)) { |
|
105 | - if (is_array($source)) { |
|
104 | + if (!empty($source)) |
|
105 | + { |
|
106 | + if (is_array($source)) |
|
107 | + { |
|
106 | 108 | $this->source->setLines($source); |
107 | - } elseif (is_string($source)) { |
|
109 | + } |
|
110 | + elseif (is_string($source)) |
|
111 | + { |
|
108 | 112 | $this->source->setString($source); |
109 | 113 | } |
110 | 114 | } |
@@ -147,25 +151,31 @@ discard block |
||
147 | 151 | public function render(int $indentLevel = 0): string |
148 | 152 | { |
149 | 153 | $result = ''; |
150 | - if (!$this->docComment->isEmpty()) { |
|
154 | + if (!$this->docComment->isEmpty()) |
|
155 | + { |
|
151 | 156 | $result .= $this->docComment->render($indentLevel) . "\n"; |
152 | 157 | } |
153 | 158 | |
154 | 159 | $method = $this->renderModifiers(); |
155 | - if (!$this->parameters->isEmpty()) { |
|
160 | + if (!$this->parameters->isEmpty()) |
|
161 | + { |
|
156 | 162 | $method .= "({$this->parameters->render()})"; |
157 | - } else { |
|
163 | + } |
|
164 | + else |
|
165 | + { |
|
158 | 166 | $method .= '()'; |
159 | 167 | } |
160 | 168 | |
161 | - if ($this->return) { |
|
169 | + if ($this->return) |
|
170 | + { |
|
162 | 171 | $method .= ": {$this->return}"; |
163 | 172 | } |
164 | 173 | |
165 | 174 | $result .= $this->addIndent($method, $indentLevel) . "\n"; |
166 | 175 | $result .= $this->addIndent('{', $indentLevel) . "\n"; |
167 | 176 | |
168 | - if (!$this->source->isEmpty()) { |
|
177 | + if (!$this->source->isEmpty()) |
|
178 | + { |
|
169 | 179 | $result .= $this->source->render($indentLevel + 1) . "\n"; |
170 | 180 | } |
171 | 181 | |
@@ -181,7 +191,8 @@ discard block |
||
181 | 191 | { |
182 | 192 | $chunks = [$this->getAccess()]; |
183 | 193 | |
184 | - if ($this->isStatic()) { |
|
194 | + if ($this->isStatic()) |
|
195 | + { |
|
185 | 196 | $chunks[] = 'static'; |
186 | 197 | } |
187 | 198 | |
@@ -197,14 +208,19 @@ discard block |
||
197 | 208 | */ |
198 | 209 | private function initSource($source): void |
199 | 210 | { |
200 | - if (empty($this->source)) { |
|
211 | + if (empty($this->source)) |
|
212 | + { |
|
201 | 213 | $this->source = new Source(); |
202 | 214 | } |
203 | 215 | |
204 | - if (!empty($source)) { |
|
205 | - if (is_array($source)) { |
|
216 | + if (!empty($source)) |
|
217 | + { |
|
218 | + if (is_array($source)) |
|
219 | + { |
|
206 | 220 | $this->source->setLines($source); |
207 | - } elseif (is_string($source)) { |
|
221 | + } |
|
222 | + elseif (is_string($source)) |
|
223 | + { |
|
208 | 224 | $this->source->setString($source); |
209 | 225 | } |
210 | 226 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | public function __construct(string $name, $defaultValue = null, $comment = '') |
49 | 49 | { |
50 | 50 | $this->setName($name); |
51 | - if ($defaultValue !== null) { |
|
51 | + if ($defaultValue !== null){ |
|
52 | 52 | $this->setDefaultValue($defaultValue); |
53 | 53 | } |
54 | 54 | |
@@ -118,21 +118,21 @@ discard block |
||
118 | 118 | public function render(int $indentLevel = 0): string |
119 | 119 | { |
120 | 120 | $result = ''; |
121 | - if (!$this->docComment->isEmpty()) { |
|
122 | - $result .= $this->docComment->render($indentLevel) . "\n"; |
|
121 | + if (!$this->docComment->isEmpty()){ |
|
122 | + $result .= $this->docComment->render($indentLevel)."\n"; |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | $result .= $this->addIndent("{$this->access} \${$this->getName()}", $indentLevel); |
126 | 126 | |
127 | - if ($this->hasDefault) { |
|
127 | + if ($this->hasDefault){ |
|
128 | 128 | $value = $this->getSerializer()->serialize($this->defaultValue); |
129 | 129 | |
130 | - if (is_array($this->defaultValue)) { |
|
130 | + if (is_array($this->defaultValue)){ |
|
131 | 131 | $value = $this->mountIndents($value, $indentLevel); |
132 | 132 | } |
133 | 133 | |
134 | 134 | $result .= " = {$value};"; |
135 | - } else { |
|
135 | + }else{ |
|
136 | 136 | $result .= ';'; |
137 | 137 | } |
138 | 138 | |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | private function mountIndents(string $serialized, int $indentLevel): string |
150 | 150 | { |
151 | 151 | $lines = explode("\n", $serialized); |
152 | - foreach ($lines as &$line) { |
|
152 | + foreach ($lines as &$line){ |
|
153 | 153 | $line = $this->addIndent($line, $indentLevel); |
154 | 154 | unset($line); |
155 | 155 | } |
@@ -48,7 +48,8 @@ discard block |
||
48 | 48 | public function __construct(string $name, $defaultValue = null, $comment = '') |
49 | 49 | { |
50 | 50 | $this->setName($name); |
51 | - if ($defaultValue !== null) { |
|
51 | + if ($defaultValue !== null) |
|
52 | + { |
|
52 | 53 | $this->setDefaultValue($defaultValue); |
53 | 54 | } |
54 | 55 | |
@@ -118,21 +119,26 @@ discard block |
||
118 | 119 | public function render(int $indentLevel = 0): string |
119 | 120 | { |
120 | 121 | $result = ''; |
121 | - if (!$this->docComment->isEmpty()) { |
|
122 | + if (!$this->docComment->isEmpty()) |
|
123 | + { |
|
122 | 124 | $result .= $this->docComment->render($indentLevel) . "\n"; |
123 | 125 | } |
124 | 126 | |
125 | 127 | $result .= $this->addIndent("{$this->access} \${$this->getName()}", $indentLevel); |
126 | 128 | |
127 | - if ($this->hasDefault) { |
|
129 | + if ($this->hasDefault) |
|
130 | + { |
|
128 | 131 | $value = $this->getSerializer()->serialize($this->defaultValue); |
129 | 132 | |
130 | - if (is_array($this->defaultValue)) { |
|
133 | + if (is_array($this->defaultValue)) |
|
134 | + { |
|
131 | 135 | $value = $this->mountIndents($value, $indentLevel); |
132 | 136 | } |
133 | 137 | |
134 | 138 | $result .= " = {$value};"; |
135 | - } else { |
|
139 | + } |
|
140 | + else |
|
141 | + { |
|
136 | 142 | $result .= ';'; |
137 | 143 | } |
138 | 144 | |
@@ -149,7 +155,8 @@ discard block |
||
149 | 155 | private function mountIndents(string $serialized, int $indentLevel): string |
150 | 156 | { |
151 | 157 | $lines = explode("\n", $serialized); |
152 | - foreach ($lines as &$line) { |
|
158 | + foreach ($lines as &$line) |
|
159 | + { |
|
153 | 160 | $line = $this->addIndent($line, $indentLevel); |
154 | 161 | unset($line); |
155 | 162 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function addLine(string $line): Source |
68 | 68 | { |
69 | - if (strpos($line, "\n") !== false) { |
|
69 | + if (strpos($line, "\n") !== false){ |
|
70 | 70 | throw new MultilineException( |
71 | 71 | 'New line character is forbidden in addLine method argument' |
72 | 72 | ); |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public static function normalizeEndings(string $string, bool $joinMultiple = true): string |
134 | 134 | { |
135 | - if (!$joinMultiple) { |
|
135 | + if (!$joinMultiple){ |
|
136 | 136 | return str_replace("\r\n", "\n", $string); |
137 | 137 | } |
138 | 138 | |
@@ -164,30 +164,30 @@ discard block |
||
164 | 164 | $string = self::normalizeEndings($string, false); |
165 | 165 | $lines = explode("\n", $string); |
166 | 166 | $minIndent = null; |
167 | - foreach ($lines as $line) { |
|
168 | - if (!trim($line)) { |
|
167 | + foreach ($lines as $line){ |
|
168 | + if (!trim($line)){ |
|
169 | 169 | continue; |
170 | 170 | } |
171 | 171 | $line = str_replace("\t", $tabulationCost, $line); |
172 | 172 | //Getting indent size |
173 | - if (!preg_match('/^( +)/', $line, $matches)) { |
|
173 | + if (!preg_match('/^( +)/', $line, $matches)){ |
|
174 | 174 | //Some line has no indent |
175 | 175 | return $string; |
176 | 176 | } |
177 | - if ($minIndent === null) { |
|
177 | + if ($minIndent === null){ |
|
178 | 178 | $minIndent = strlen($matches[1]); |
179 | 179 | } |
180 | 180 | $minIndent = min($minIndent, strlen($matches[1])); |
181 | 181 | } |
182 | 182 | //Fixing indent |
183 | - foreach ($lines as &$line) { |
|
184 | - if (empty($line)) { |
|
183 | + foreach ($lines as &$line){ |
|
184 | + if (empty($line)){ |
|
185 | 185 | continue; |
186 | 186 | } |
187 | 187 | //Getting line indent |
188 | 188 | preg_match("/^([ \t]+)/", $line, $matches); |
189 | 189 | $indent = $matches[1]; |
190 | - if (!trim($line)) { |
|
190 | + if (!trim($line)){ |
|
191 | 191 | $line = ''; |
192 | 192 | continue; |
193 | 193 | } |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | ' ', |
197 | 197 | strlen(str_replace("\t", $tabulationCost, $indent)) - $minIndent |
198 | 198 | ); |
199 | - $line = $useIndent . substr($line, strlen($indent)); |
|
199 | + $line = $useIndent.substr($line, strlen($indent)); |
|
200 | 200 | unset($line); |
201 | 201 | } |
202 | 202 | |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | */ |
213 | 213 | protected function fetchLines(string $string, bool $cutIndents): array |
214 | 214 | { |
215 | - if ($cutIndents) { |
|
215 | + if ($cutIndents){ |
|
216 | 216 | $string = self::normalizeIndents($string, ''); |
217 | 217 | } |
218 | 218 |
@@ -66,7 +66,8 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function addLine(string $line): Source |
68 | 68 | { |
69 | - if (strpos($line, "\n") !== false) { |
|
69 | + if (strpos($line, "\n") !== false) |
|
70 | + { |
|
70 | 71 | throw new MultilineException( |
71 | 72 | 'New line character is forbidden in addLine method argument' |
72 | 73 | ); |
@@ -132,7 +133,8 @@ discard block |
||
132 | 133 | */ |
133 | 134 | public static function normalizeEndings(string $string, bool $joinMultiple = true): string |
134 | 135 | { |
135 | - if (!$joinMultiple) { |
|
136 | + if (!$joinMultiple) |
|
137 | + { |
|
136 | 138 | return str_replace("\r\n", "\n", $string); |
137 | 139 | } |
138 | 140 | |
@@ -164,30 +166,37 @@ discard block |
||
164 | 166 | $string = self::normalizeEndings($string, false); |
165 | 167 | $lines = explode("\n", $string); |
166 | 168 | $minIndent = null; |
167 | - foreach ($lines as $line) { |
|
168 | - if (!trim($line)) { |
|
169 | + foreach ($lines as $line) |
|
170 | + { |
|
171 | + if (!trim($line)) |
|
172 | + { |
|
169 | 173 | continue; |
170 | 174 | } |
171 | 175 | $line = str_replace("\t", $tabulationCost, $line); |
172 | 176 | //Getting indent size |
173 | - if (!preg_match('/^( +)/', $line, $matches)) { |
|
177 | + if (!preg_match('/^( +)/', $line, $matches)) |
|
178 | + { |
|
174 | 179 | //Some line has no indent |
175 | 180 | return $string; |
176 | 181 | } |
177 | - if ($minIndent === null) { |
|
182 | + if ($minIndent === null) |
|
183 | + { |
|
178 | 184 | $minIndent = strlen($matches[1]); |
179 | 185 | } |
180 | 186 | $minIndent = min($minIndent, strlen($matches[1])); |
181 | 187 | } |
182 | 188 | //Fixing indent |
183 | - foreach ($lines as &$line) { |
|
184 | - if (empty($line)) { |
|
189 | + foreach ($lines as &$line) |
|
190 | + { |
|
191 | + if (empty($line)) |
|
192 | + { |
|
185 | 193 | continue; |
186 | 194 | } |
187 | 195 | //Getting line indent |
188 | 196 | preg_match("/^([ \t]+)/", $line, $matches); |
189 | 197 | $indent = $matches[1]; |
190 | - if (!trim($line)) { |
|
198 | + if (!trim($line)) |
|
199 | + { |
|
191 | 200 | $line = ''; |
192 | 201 | continue; |
193 | 202 | } |
@@ -212,7 +221,8 @@ discard block |
||
212 | 221 | */ |
213 | 222 | protected function fetchLines(string $string, bool $cutIndents): array |
214 | 223 | { |
215 | - if ($cutIndents) { |
|
224 | + if ($cutIndents) |
|
225 | + { |
|
216 | 226 | $string = self::normalizeIndents($string, ''); |
217 | 227 | } |
218 | 228 |