1414use Doctrine \Persistence \ManagerRegistry ;
1515use Silverback \ApiComponentsBundle \Entity \Core \AbstractPageData ;
1616use Silverback \ApiComponentsBundle \Entity \Core \ComponentGroup ;
17- use Silverback \ApiComponentsBundle \Entity \Core \Route ;
1817use Silverback \ApiComponentsBundle \Entity \Core \ComponentPosition ;
1918use Silverback \ApiComponentsBundle \Entity \Core \Layout ;
2019use Silverback \ApiComponentsBundle \Entity \Core \Page ;
20+ use Silverback \ApiComponentsBundle \Entity \Core \Route ;
2121use Symfony \Component \Console \Command \Command ;
2222use Symfony \Component \Console \Input \InputInterface ;
2323use Symfony \Component \Console \Input \InputOption ;
@@ -63,15 +63,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6363 $ childPagesByParent = [];
6464 foreach ($ pages as $ page ) {
6565 $ parent = $ page ->getParentPageData () ?? $ page ->getParentPage ();
66- if ($ parent !== null ) {
66+ if (null !== $ parent ) {
6767 $ childPagesByParent [spl_object_id ($ parent )][] = $ page ;
6868 }
6969 }
7070
7171 $ childPageDataByParent = [];
7272 foreach ($ allPageData as $ pd ) {
7373 $ parent = $ pd ->getParentPageData () ?? $ pd ->getParentPage ();
74- if ($ parent !== null ) {
74+ if (null !== $ parent ) {
7575 $ childPageDataByParent [spl_object_id ($ parent )][] = $ pd ;
7676 }
7777 }
@@ -83,22 +83,22 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8383 }
8484
8585 foreach ($ pages as $ page ) {
86- if ($ page ->getParentPage () !== null || $ page ->getParentPageData () !== null ) {
86+ if (null !== $ page ->getParentPage () || null !== $ page ->getParentPageData ()) {
8787 continue ;
8888 }
8989 $ body .= $ this ->emitPage ($ page , $ childPagesByParent , $ childPageDataByParent );
9090 }
9191
9292 foreach ($ allPageData as $ pd ) {
93- if ($ pd ->getParentPage () !== null || $ pd ->getParentPageData () !== null ) {
93+ if (null !== $ pd ->getParentPage () || null !== $ pd ->getParentPageData ()) {
9494 continue ;
9595 }
9696 $ body .= $ this ->emitPageData ($ pd , $ childPagesByParent , $ childPageDataByParent );
9797 }
9898
9999 file_put_contents ($ outputPath , $ this ->buildFile ($ body ));
100100
101- $ output ->writeln (sprintf ('<info>Fixture class written to %s</info> ' , $ outputPath ));
101+ $ output ->writeln (\ sprintf ('<info>Fixture class written to %s</info> ' , $ outputPath ));
102102
103103 return Command::SUCCESS ;
104104 }
@@ -110,7 +110,7 @@ private function emitLayout(Layout $layout): string
110110 $ ui = var_export ($ layout ->uiComponent , true );
111111
112112 $ extra = '' ;
113- if ($ layout -> uiClassNames !== null ) {
113+ if (null !== $ layout -> uiClassNames ) {
114114 $ extra .= ', uiClassNames: ' . $ this ->exportArray ($ layout ->uiClassNames );
115115 }
116116
@@ -133,15 +133,15 @@ private function emitGroupCall(ComponentGroup $group, string $ownerVar, string $
133133
134134 $ positions = $ group ->componentPositions ;
135135 if ($ positions ->isEmpty ()) {
136- return sprintf ("%s%s->group(%s%s); \n" , $ indent , $ ownerVar , var_export ($ groupName , true ), $ extra );
136+ return \ sprintf ("%s%s->group(%s%s); \n" , $ indent , $ ownerVar , var_export ($ groupName , true ), $ extra );
137137 }
138138
139139 $ posCode = '' ;
140140 foreach ($ positions as $ position ) {
141141 $ posCode .= $ this ->emitPosition ($ position , $ indent . ' ' );
142142 }
143143
144- return sprintf (
144+ return \ sprintf (
145145 "%s%s->group(%s%s, function (GroupBuilder \$g): void { \n%s%s}); \n" ,
146146 $ indent ,
147147 $ ownerVar ,
@@ -154,8 +154,8 @@ private function emitGroupCall(ComponentGroup $group, string $ownerVar, string $
154154
155155 private function emitPosition (ComponentPosition $ position , string $ indent ): string
156156 {
157- if ($ position -> pageDataProperty !== null ) {
158- return sprintf (
157+ if (null !== $ position -> pageDataProperty ) {
158+ return \ sprintf (
159159 "%s \$g->pageDataPosition(%s, %s); \n" ,
160160 $ indent ,
161161 var_export ($ position ->pageDataClass , true ),
@@ -164,21 +164,21 @@ private function emitPosition(ComponentPosition $position, string $indent): stri
164164 }
165165
166166 $ component = $ position ->component ;
167- if ($ component === null ) {
167+ if (null === $ component ) {
168168 return '' ;
169169 }
170170
171- $ fqcn = get_class ( $ component) ;
171+ $ fqcn = $ component::class ;
172172 $ shortName = (new \ReflectionClass ($ component ))->getShortName ();
173173 $ this ->addUseClass ($ fqcn );
174174
175175 $ varName = '$comp ' . (++$ this ->compCounter );
176176 $ code = "{$ indent }{$ varName } = new {$ shortName }(); \n" ;
177177
178- if ($ component -> uiComponent !== null ) {
178+ if (null !== $ component -> uiComponent ) {
179179 $ code .= "{$ indent }{$ varName }->uiComponent = " . var_export ($ component ->uiComponent , true ) . "; \n" ;
180180 }
181- if ($ component -> uiClassNames !== null ) {
181+ if (null !== $ component -> uiClassNames ) {
182182 $ code .= "{$ indent }{$ varName }->uiClassNames = " . $ this ->exportArray ($ component ->uiClassNames ) . "; \n" ;
183183 }
184184
@@ -188,7 +188,7 @@ private function emitPosition(ComponentPosition $position, string $indent): stri
188188 continue ;
189189 }
190190 $ value = $ prop ->getValue ($ component );
191- if ($ value === null ) {
191+ if (null === $ value ) {
192192 continue ;
193193 }
194194 $ code .= "{$ indent }{$ varName }-> {$ prop ->getName ()} = " . var_export ($ value , true ) . "; \n" ;
@@ -213,10 +213,10 @@ private function emitPage(
213213 $ args = "{$ ref }, {$ ui }, layout: {$ layoutRef }" ;
214214
215215 $ route = $ page ->getRoute ();
216- if ($ route !== null ) {
216+ if (null !== $ route ) {
217217 $ args .= ', route: ' . var_export ($ route ->getPath (), true );
218218 $ routeName = $ this ->getRouteName ($ route );
219- if ($ routeName !== null ) {
219+ if (null !== $ routeName ) {
220220 $ args .= ', routeName: ' . var_export ($ routeName , true );
221221 }
222222 }
@@ -225,7 +225,7 @@ private function emitPage(
225225 $ args .= ', isTemplate: true ' ;
226226 }
227227
228- if ($ page -> uiClassNames !== null ) {
228+ if (null !== $ page -> uiClassNames ) {
229229 $ args .= ', uiClassNames: ' . $ this ->exportArray ($ page ->uiClassNames );
230230 }
231231
@@ -235,12 +235,12 @@ private function emitPage(
235235 $ hasChildren = !empty ($ childPages ) || !empty ($ childPd );
236236 $ title = $ page ->getTitle ();
237237
238- if ($ groups ->isEmpty () && !$ hasChildren && $ title === null ) {
238+ if ($ groups ->isEmpty () && !$ hasChildren && null === $ title ) {
239239 return "{$ indent }{$ builderVar }->page( {$ args }); \n" ;
240240 }
241241
242242 $ configureLines = '' ;
243- if ($ title !== null ) {
243+ if (null !== $ title ) {
244244 $ configureLines .= "{$ indent } \$page->title( " . var_export ($ title , true ) . "); \n" ;
245245 }
246246 foreach ($ groups as $ group ) {
@@ -258,11 +258,11 @@ private function emitPage(
258258 }
259259
260260 return <<<CODE
261- {$ indent }{$ builderVar }->page( {$ args },
262- {$ indent } configure: function (PageBuilder \$page) use ( \$cwa): void {
263- {$ configureLines }{$ indent } }
264- {$ indent });
265- CODE . "\n" ;
261+ {$ indent }{$ builderVar }->page( {$ args },
262+ {$ indent } configure: function (PageBuilder \$page) use ( \$cwa): void {
263+ {$ configureLines }{$ indent } }
264+ {$ indent });
265+ CODE . "\n" ;
266266 }
267267
268268 private function emitPageData (
@@ -272,15 +272,15 @@ private function emitPageData(
272272 string $ indent = ' ' ,
273273 string $ builderVar = '$cwa ' ,
274274 ): string {
275- $ fqcn = get_class ( $ pd) ;
275+ $ fqcn = $ pd::class ;
276276 $ shortName = (new \ReflectionClass ($ pd ))->getShortName ();
277277 $ this ->addUseClass ($ fqcn );
278278
279279 $ varName = '$pd_ ' . $ this ->toVar ($ pd ->getTitle () ?? 'pageData ' );
280280 $ code = "{$ indent }{$ varName } = new {$ shortName }(); \n" ;
281281
282282 $ title = $ pd ->getTitle ();
283- if ($ title !== null ) {
283+ if (null !== $ title ) {
284284 $ code .= "{$ indent }{$ varName }->setTitle( " . var_export ($ title , true ) . "); \n" ;
285285 }
286286
@@ -293,7 +293,7 @@ private function emitPageData(
293293 continue ;
294294 }
295295 $ value = $ prop ->getValue ($ pd );
296- if ($ value === null ) {
296+ if (null === $ value ) {
297297 continue ;
298298 }
299299 $ code .= "{$ indent }{$ varName }-> {$ prop ->getName ()} = " . var_export ($ value , true ) . "; \n" ;
@@ -307,13 +307,13 @@ private function emitPageData(
307307 $ route = $ pd ->getRoute ();
308308
309309 $ pdArgs = $ varName ;
310- if ($ templateRef !== null ) {
310+ if (null !== $ templateRef ) {
311311 $ pdArgs .= ', template: ' . var_export ($ templateRef , true );
312312 }
313- if ($ route !== null ) {
313+ if (null !== $ route ) {
314314 $ pdArgs .= ', route: ' . var_export ($ route ->getPath (), true );
315315 $ routeName = $ this ->getRouteName ($ route );
316- if ($ routeName !== null ) {
316+ if (null !== $ routeName ) {
317317 $ pdArgs .= ', routeName: ' . var_export ($ routeName , true );
318318 }
319319 }
@@ -351,23 +351,23 @@ private function buildFile(string $body): string
351351 $ extraUses = '' ;
352352 if (!empty ($ this ->useClasses )) {
353353 sort ($ this ->useClasses );
354- $ extraUses = "\n" . implode ("\n" , array_map (fn ($ c ) => "use {$ c }; " , $ this ->useClasses ));
354+ $ extraUses = "\n" . implode ("\n" , array_map (static fn ($ c ) => "use {$ c }; " , $ this ->useClasses ));
355355 }
356356
357357 return <<<PHP
358- <?php
358+ <?php
359359
360- namespace App\\DataFixtures;
360+ namespace App\\DataFixtures;
361361
362- {$ coreUses }{$ extraUses }
362+ {$ coreUses }{$ extraUses }
363363
364- class GeneratedScaffold extends AbstractCwaScaffold
365- {
366- public function build(CwaFixtureBuilder \$cwa): void
367- {
368- {$ body } }
369- }
370- PHP ;
364+ class GeneratedScaffold extends AbstractCwaScaffold
365+ {
366+ public function build(CwaFixtureBuilder \$cwa): void
367+ {
368+ {$ body } }
369+ }
370+ PHP ;
371371 }
372372
373373 private function addUseClass (string $ fqcn ): void
@@ -381,7 +381,7 @@ private function extractGroupName(ComponentGroup $group): string
381381 {
382382 $ reference = $ group ->reference ?? '' ;
383383 $ location = $ group ->location ?? '' ;
384- if ($ location !== '' && str_contains ($ reference , '_ ' . $ location )) {
384+ if ('' !== $ location && str_contains ($ reference , '_ ' . $ location )) {
385385 $ name = substr ($ reference , 0 , strpos ($ reference , '_ ' . $ location ));
386386 if (false !== $ name && '' !== $ name ) {
387387 return $ name ;
@@ -398,7 +398,7 @@ private function toVar(string $str): string
398398
399399 private function exportArray (array $ arr ): string
400400 {
401- $ items = implode (', ' , array_map (fn ($ v ) => var_export ($ v , true ), $ arr ));
401+ $ items = implode (', ' , array_map (static fn ($ v ) => var_export ($ v , true ), $ arr ));
402402
403403 return '[ ' . $ items . '] ' ;
404404 }
0 commit comments