11<?php
22namespace gossi \codegen \config ;
33
4+ use gossi \code \profiles \Profile ;
45use gossi \codegen \generator \CodeGenerator ;
56use phootwork \lang \Comparator ;
67use Symfony \Component \OptionsResolver \Options ;
@@ -15,6 +16,9 @@ class CodeGeneratorConfig {
1516
1617 protected $ options ;
1718
19+ /** @var Profile */
20+ protected $ profile ;
21+
1822 /**
1923 * Creates a new configuration for code generator
2024 *
@@ -25,34 +29,62 @@ public function __construct(array $options = []) {
2529 $ resolver = new OptionsResolver ();
2630 $ this ->configureOptions ($ resolver );
2731 $ this ->options = $ resolver ->resolve ($ options );
32+ $ this ->profile = is_string ($ this ->options ['profile ' ]) ? new Profile ($ this ->options ['profile ' ]) : $ this ->options ['profile ' ];
2833 }
29-
34+
3035 protected function configureOptions (OptionsResolver $ resolver ) {
3136 $ resolver ->setDefaults ([
37+ 'profile ' => 'default ' ,
3238 'generateDocblock ' => true ,
3339 'generateEmptyDocblock ' => function (Options $ options ) {
3440 return $ options ['generateDocblock ' ];
3541 },
3642 'generateScalarTypeHints ' => false ,
3743 'generateReturnTypeHints ' => false ,
44+ 'enableFormatting ' => false ,
3845 'enableSorting ' => true ,
3946 'useStatementSorting ' => CodeGenerator::SORT_USESTATEMENTS_DEFAULT ,
4047 'constantSorting ' => CodeGenerator::SORT_CONSTANTS_DEFAULT ,
4148 'propertySorting ' => CodeGenerator::SORT_PROPERTIES_DEFAULT ,
4249 'methodSorting ' => CodeGenerator::SORT_METHODS_DEFAULT
4350 ]);
44-
51+
52+ $ resolver ->setAllowedTypes ('profile ' , ['string ' , 'gossi\code\profiles\Profile ' ]);
4553 $ resolver ->setAllowedTypes ('generateDocblock ' , 'bool ' );
4654 $ resolver ->setAllowedTypes ('generateEmptyDocblock ' , 'bool ' );
4755 $ resolver ->setAllowedTypes ('generateScalarTypeHints ' , 'bool ' );
4856 $ resolver ->setAllowedTypes ('generateReturnTypeHints ' , 'bool ' );
57+ $ resolver ->setAllowedTypes ('enableFormatting ' , 'bool ' );
4958 $ resolver ->setAllowedTypes ('enableSorting ' , 'bool ' );
5059 $ resolver ->setAllowedTypes ('useStatementSorting ' , ['bool ' , 'string ' , '\Closure ' , 'phootwork\lang\Comparator ' ]);
5160 $ resolver ->setAllowedTypes ('constantSorting ' , ['bool ' , 'string ' , '\Closure ' , 'phootwork\lang\Comparator ' ]);
5261 $ resolver ->setAllowedTypes ('propertySorting ' , ['bool ' , 'string ' , '\Closure ' , 'phootwork\lang\Comparator ' ]);
5362 $ resolver ->setAllowedTypes ('methodSorting ' , ['bool ' , 'string ' , '\Closure ' , 'phootwork\lang\Comparator ' ]);
5463 }
5564
65+ /**
66+ * Returns the code style profile
67+ *
68+ * @return Profile
69+ */
70+ public function getProfile () {
71+ return $ this ->profile ;
72+ }
73+
74+ /**
75+ * Sets the code style profile
76+ *
77+ * @param Profile/string $profile
78+ * @return $this
79+ */
80+ public function setProfile ($ profile ) {
81+ if (is_string ($ profile )) {
82+ $ profile = new Profile ($ profile );
83+ }
84+ $ this ->profile = $ profile ;
85+ return $ this ;
86+ }
87+
5688 /**
5789 * Returns whether docblocks should be generated
5890 *
@@ -107,25 +139,34 @@ public function setGenerateEmptyDocblock($generate) {
107139 public function getGenerateScalarTypeHints () {
108140 return $ this ->options ['generateScalarTypeHints ' ];
109141 }
110-
142+
111143 /**
112144 * Returns whether sorting is enabled
113- *
145+ *
114146 * @return bool `true` if it is enabled and `false` if not
115147 */
116148 public function isSortingEnabled () {
117149 return $ this ->options ['enableSorting ' ];
118150 }
119-
151+
152+ /**
153+ * Returns whether formatting is enalbed
154+ *
155+ * @return bool `true` if it is enabled and `false` if not
156+ */
157+ public function isFormattingEnabled () {
158+ return $ this ->options ['enableFormatting ' ];
159+ }
160+
120161 /**
121162 * Returns the use statement sorting
122- *
163+ *
123164 * @return string|bool|Comparator|\Closure
124165 */
125166 public function getUseStatementSorting () {
126167 return $ this ->options ['useStatementSorting ' ];
127168 }
128-
169+
129170 /**
130171 * Returns the constant sorting
131172 *
@@ -134,7 +175,7 @@ public function getUseStatementSorting() {
134175 public function getConstantSorting () {
135176 return $ this ->options ['constantSorting ' ];
136177 }
137-
178+
138179 /**
139180 * Returns the property sorting
140181 *
@@ -143,7 +184,7 @@ public function getConstantSorting() {
143184 public function getPropertySorting () {
144185 return $ this ->options ['propertySorting ' ];
145186 }
146-
187+
147188 /**
148189 * Returns the method sorting
149190 *
@@ -183,9 +224,9 @@ public function setGenerateReturnTypeHints($generate) {
183224 $ this ->options ['generateReturnTypeHints ' ] = $ generate ;
184225 return $ this ;
185226 }
186-
227+
187228 /**
188- * Returns whether sorting is enabled
229+ * Sets whether sorting is enabled
189230 *
190231 * @param $enabled bool `true` if it is enabled and `false` if not
191232 * @return $this
@@ -194,7 +235,18 @@ public function setSortingEnabled($enabled) {
194235 $ this ->options ['enableSorting ' ] = $ enabled ;
195236 return $ this ;
196237 }
197-
238+
239+ /**
240+ * Sets whether formatting is enabled
241+ *
242+ * @param $enabled bool `true` if it is enabled and `false` if not
243+ * @return $this
244+ */
245+ public function setFormattingEnabled ($ enabled ) {
246+ $ this ->options ['enableFormatting ' ] = $ enabled ;
247+ return $ this ;
248+ }
249+
198250 /**
199251 * Returns the use statement sorting
200252 *
@@ -205,7 +257,7 @@ public function setUseStatementSorting($sorting) {
205257 $ this ->options ['useStatementSorting ' ] = $ sorting ;
206258 return $ this ;
207259 }
208-
260+
209261 /**
210262 * Returns the constant sorting
211263 *
@@ -216,7 +268,7 @@ public function setConstantSorting($sorting) {
216268 $ this ->options ['constantSorting ' ] = $ sorting ;
217269 return $ this ;
218270 }
219-
271+
220272 /**
221273 * Returns the property sorting
222274 *
@@ -227,7 +279,7 @@ public function setPropertySorting($sorting) {
227279 $ this ->options ['propertySorting ' ] = $ sorting ;
228280 return $ this ;
229281 }
230-
282+
231283 /**
232284 * Returns the method sorting
233285 *
0 commit comments