@@ -98,7 +98,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
9898 continue ;
9999 }
100100
101- $ classes [] = str_replace (' / ' , '\\' , str_replace ( ' .php ' , '' , $ item ->getRelativePathname () ));
101+ $ classes [] = str_replace ([ ' .php ' , '/ ' ], [ ' ' , '\\' ] , $ item ->getRelativePathname ());
102102 }
103103
104104 $ argument = $ command ->getDefinition ()->getArgument ('name ' );
@@ -191,7 +191,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
191191 $ fileManagerOperations = [];
192192 $ fileManagerOperations [$ entityPath ] = $ manipulator ;
193193
194- if (is_array ($ newField )) {
194+ if (\ is_array ($ newField )) {
195195 $ annotationOptions = $ newField ;
196196 unset($ annotationOptions ['fieldName ' ]);
197197 $ manipulator ->addEntityField ($ newField ['fieldName ' ], $ annotationOptions );
@@ -254,7 +254,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
254254 }
255255
256256 foreach ($ fileManagerOperations as $ path => $ manipulatorOrMessage ) {
257- if (is_string ($ manipulatorOrMessage )) {
257+ if (\ is_string ($ manipulatorOrMessage )) {
258258 $ io ->comment ($ manipulatorOrMessage );
259259 } else {
260260 $ this ->fileManager ->dumpFile ($ path , $ manipulatorOrMessage ->getSourceCode ());
@@ -300,28 +300,29 @@ private function askForNextField(ConsoleStyle $io, array $fields, string $entity
300300 return $ name ;
301301 }
302302
303- if (in_array ($ name , $ fields )) {
303+ if (\ in_array ($ name , $ fields )) {
304304 throw new \InvalidArgumentException (sprintf ('The "%s" property already exists. ' , $ name ));
305305 }
306306
307307 return Validator::validateDoctrineFieldName ($ name , $ this ->doctrineHelper ->getRegistry ());
308308 });
309309
310310 if (!$ fieldName ) {
311- return ;
311+ return null ;
312312 }
313313
314314 $ defaultType = 'string ' ;
315315 // try to guess the type by the field name prefix/suffix
316316 // convert to snake case for simplicity
317317 $ snakeCasedField = Str::asSnakeCase ($ fieldName );
318- if ('_at ' == substr ($ snakeCasedField , -3 )) {
318+
319+ if ('_at ' === $ suffix = substr ($ snakeCasedField , -3 )) {
319320 $ defaultType = 'datetime ' ;
320- } elseif ('_id ' == substr ( $ snakeCasedField , - 3 ) ) {
321+ } elseif ('_id ' === $ suffix ) {
321322 $ defaultType = 'integer ' ;
322- } elseif (' is_ ' == substr ($ snakeCasedField , 0 , 3 )) {
323+ } elseif (0 === strpos ($ snakeCasedField , ' is_ ' )) {
323324 $ defaultType = 'boolean ' ;
324- } elseif (' has_ ' == substr ($ snakeCasedField , 0 , 4 )) {
325+ } elseif (0 === strpos ($ snakeCasedField , ' has_ ' )) {
325326 $ defaultType = 'boolean ' ;
326327 }
327328
@@ -341,7 +342,7 @@ private function askForNextField(ConsoleStyle $io, array $fields, string $entity
341342 $ io ->writeln ('' );
342343
343344 $ type = null ;
344- } elseif (!in_array ($ type , $ allValidTypes )) {
345+ } elseif (!\ in_array ($ type , $ allValidTypes )) {
345346 $ this ->printAvailableTypes ($ io );
346347 $ io ->error (sprintf ('Invalid type "%s". ' , $ type ));
347348 $ io ->writeln ('' );
@@ -350,7 +351,7 @@ private function askForNextField(ConsoleStyle $io, array $fields, string $entity
350351 }
351352 }
352353
353- if ('relation ' === $ type || in_array ($ type , EntityRelation::getValidRelationTypes ())) {
354+ if ('relation ' === $ type || \ in_array ($ type , EntityRelation::getValidRelationTypes ())) {
354355 return $ this ->askRelationDetails ($ io , $ entityClass , $ type , $ fieldName );
355356 }
356357
@@ -414,9 +415,9 @@ private function printAvailableTypes(ConsoleStyle $io)
414415 unset($ allTypes [$ mainType ]);
415416 $ line = sprintf (' * <comment>%s</comment> ' , $ mainType );
416417
417- if (is_string ($ subTypes ) && $ subTypes ) {
418+ if (\ is_string ($ subTypes ) && $ subTypes ) {
418419 $ line .= sprintf (' (%s) ' , $ subTypes );
419- } elseif (is_array ($ subTypes ) && !empty ($ subTypes )) {
420+ } elseif (\ is_array ($ subTypes ) && !empty ($ subTypes )) {
420421 $ line .= sprintf (' (or %s) ' , implode (', ' , array_map (function ($ subType ) {
421422 return sprintf ('<comment>%s</comment> ' , $ subType );
422423 }, $ subTypes )));
@@ -560,7 +561,7 @@ function ($name) use ($targetClass) {
560561 }
561562
562563 // recommend an inverse side, except for OneToOne, where it's inefficient
563- $ recommendMappingInverse = EntityRelation::ONE_TO_ONE === $ relation ->getType () ? false : true ;
564+ $ recommendMappingInverse = EntityRelation::ONE_TO_ONE !== $ relation ->getType ();
564565
565566 $ getterMethodName = 'get ' .Str::asCamelCase (Str::getShortClassName ($ relation ->getOwningClass ()));
566567 if (EntityRelation::ONE_TO_ONE !== $ relation ->getType ()) {
@@ -742,7 +743,7 @@ private function askRelationType(ConsoleStyle $io, string $entityClass, string $
742743 ));
743744 $ question ->setAutocompleterValues (EntityRelation::getValidRelationTypes ());
744745 $ question ->setValidator (function ($ type ) {
745- if (!in_array ($ type , EntityRelation::getValidRelationTypes ())) {
746+ if (!\ in_array ($ type , EntityRelation::getValidRelationTypes ())) {
746747 throw new \InvalidArgumentException (sprintf ('Invalid type: use one of: %s ' , implode (', ' , EntityRelation::getValidRelationTypes ())));
747748 }
748749
@@ -801,7 +802,7 @@ private function doesEntityUseAnnotationMapping(string $className): bool
801802 return false ;
802803 }
803804
804- $ className = ( reset ($ otherClassMetadatas) )->getName ();
805+ $ className = reset ($ otherClassMetadatas )->getName ();
805806 }
806807
807808 $ driver = $ this ->doctrineHelper ->getMappingDriverForClass ($ className );
0 commit comments