Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php | ||
| 26 | class CreateUserCommand extends ContainerAwareCommand | ||
|  | |||
| 27 | { | ||
| 28 | protected static $defaultName = 'kuma:user:create'; | ||
| 29 | |||
| 30 | /** @var array */ | ||
| 31 | private $groups = []; | ||
| 32 | /** @var EntityManagerInterface */ | ||
| 33 | private $em; | ||
| 34 | /** @var GroupManager */ | ||
| 35 | private $groupManager; | ||
| 36 | /** @var UserManager */ | ||
| 37 | private $userManager; | ||
| 38 | /** @var string */ | ||
| 39 | private $defaultLocale; | ||
| 40 | |||
| 41 | public function __construct(/* EntityManagerInterface */ $em = null, /* GroupManager */ $groupManager = null, /* UserManager */ $userManager, $defaultLocale = null) | ||
| 42 |     { | ||
| 43 | parent::__construct(); | ||
| 44 | |||
| 45 |         if (!$em instanceof EntityManagerInterface) { | ||
| 46 |             @trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version symfony 3.4 and will be removed in symfony 4.0. If the command was registered by convention, make it a service instead. ', __METHOD__), E_USER_DEPRECATED); | ||
| 47 | |||
| 48 | $this->setName(null === $em ? 'kuma:user:create' : $em); | ||
| 49 | |||
| 50 | return; | ||
| 51 | } | ||
| 52 | |||
| 53 |         if (!$groupManager instanceof GroupManager && !$groupManager instanceof FOSGroupManager) { | ||
| 54 |             throw new \InvalidArgumentException(sprintf('The "$groupManager" argument must be of type "%s" or type "%s"', GroupManager::class, FOSGroupManager::class)); | ||
| 55 | } | ||
| 56 |         if ($groupManager instanceof FOSGroupManager) { | ||
| 57 | // NEXT_MAJOR set the groupmanager typehint to the kunstmaan groupmanager. | ||
| 58 |             @trigger_error(sprintf('Passing the groupmanager from FOSUserBundle as the first argument of "%s" is deprecated since KunstmaanAdminBundle 5.8 and will be removed in KunstmaanAdminBundle 6.0. Use the "%s" class instead.', __METHOD__, GroupManager::class), E_USER_DEPRECATED); | ||
| 59 | } | ||
| 60 | |||
| 61 |         if (!$userManager instanceof UserManager && !$userManager instanceof FOSUserManager) { | ||
| 62 |             throw new \InvalidArgumentException(sprintf('The "$userManager" argument must be of type "%s" or type "%s"', UserManager::class, FOSUserManager::class)); | ||
| 63 | } | ||
| 64 |         if ($userManager instanceof FOSUserManager) { | ||
| 65 | // NEXT_MAJOR set the usermanager typehint to the kunstmaan usermanager. | ||
| 66 |             @trigger_error(sprintf('Passing the usermanager from FOSUserBundle as the first argument of "%s" is deprecated since KunstmaanAdminBundle 5.8 and will be removed in KunstmaanAdminBundle 6.0. Use the "%s" class instead.', __METHOD__, UserManager::class), E_USER_DEPRECATED); | ||
| 67 | } | ||
| 68 | |||
| 69 | $this->em = $em; | ||
| 70 | $this->groupManager = $groupManager; | ||
| 71 | $this->userManager = $userManager; | ||
| 72 | $this->defaultLocale = $defaultLocale; | ||
| 73 | } | ||
| 74 | |||
| 75 | protected function configure() | ||
| 76 |     { | ||
| 77 | parent::configure(); | ||
| 78 | |||
| 79 |         $this->setDescription('Create a user.') | ||
| 80 | ->setDefinition([ | ||
| 81 |                 new InputArgument('username', InputArgument::REQUIRED, 'The username'), | ||
| 82 |                 new InputArgument('email', InputArgument::REQUIRED, 'The email'), | ||
| 83 |                 new InputArgument('password', InputArgument::REQUIRED, 'The password'), | ||
| 84 |                 new InputArgument('locale', InputArgument::OPTIONAL, 'The locale (language)'), | ||
| 85 |                 new InputOption('group', null, InputOption::VALUE_REQUIRED, 'The group(s) the user should belong to'), | ||
| 86 |                 new InputOption('super-admin', null, InputOption::VALUE_NONE, 'Set the user as super admin'), | ||
| 87 |                 new InputOption('inactive', null, InputOption::VALUE_NONE, 'Set the user as inactive'), | ||
| 88 | ]) | ||
| 89 | ->setHelp(<<<'EOT' | ||
| 90 | The <info>kuma:user:create</info> command creates a user: | ||
| 91 | |||
| 92 | <info>php bin/console kuma:user:create matthieu --group=Users</info> | ||
| 93 | |||
| 94 | This interactive shell will ask you for an email and then a password. | ||
| 95 | |||
| 96 | You can alternatively specify the email, password and locale and group as extra arguments: | ||
| 97 | |||
| 98 | <info>php bin/console kuma:user:create matthieu [email protected] mypassword en --group=Users</info> | ||
| 99 | |||
| 100 | You can create a super admin via the super-admin flag: | ||
| 101 | |||
| 102 | <info>php bin/console kuma:user:create admin --super-admin --group=Administrators</info> | ||
| 103 | |||
| 104 | You can create an inactive user (will not be able to log in): | ||
| 105 | |||
| 106 | <info>php bin/console kuma:user:create thibault --inactive --group=Users</info> | ||
| 107 | |||
| 108 | <comment>Note:</comment> You have to specify at least one group. | ||
| 109 | |||
| 110 | EOT | ||
| 111 | ); | ||
| 112 | } | ||
| 113 | |||
| 114 | protected function initialize(InputInterface $input, OutputInterface $output) | ||
| 118 | |||
| 119 | private function getGroups() | ||
| 120 |     { | ||
| 131 | |||
| 132 | /** | ||
| 133 | * Executes the current command. | ||
| 134 | * | ||
| 135 | * @param InputInterface $input The input | ||
| 136 | * @param OutputInterface $output The output | ||
| 137 | * | ||
| 138 | * @return int | ||
| 139 | */ | ||
| 140 | protected function execute(InputInterface $input, OutputInterface $output) | ||
| 206 | |||
| 207 | /** | ||
| 208 | * Interacts with the user. | ||
| 209 | * | ||
| 210 | * @param InputInterface $input The input | ||
| 211 | * @param OutputInterface $output The output | ||
| 212 | * | ||
| 213 | * @throws \InvalidArgumentException | ||
| 214 | */ | ||
| 215 | protected function interact(InputInterface $input, OutputInterface $output) | ||
| 311 | } | ||
| 312 | 
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.