| Conditions | 15 | 
| Paths | 34 | 
| Total Lines | 76 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php  | 
            ||
| 101 | public function execute(InputInterface $input, OutputInterface $output)  | 
            ||
| 102 |     { | 
            ||
| 103 |         $output->writeln('Welcome to the AdminBundle object ACL generator'); | 
            ||
| 104 | $output->writeln([  | 
            ||
| 105 | '',  | 
            ||
| 106 | 'This command helps you to generate ACL entities for the objects handled by the AdminBundle.',  | 
            ||
| 107 | '',  | 
            ||
| 108 | 'If the step option is used, you will be asked if you want to generate the object ACL entities for each Admin.',  | 
            ||
| 109 | 'You must use the shortcut notation like <comment>AcmeDemoBundle:User</comment> if you want to set an object owner.',  | 
            ||
| 110 | '',  | 
            ||
| 111 | ]);  | 
            ||
| 112 | |||
| 113 |         if (!$this->registry) { | 
            ||
| 114 |             $msg = sprintf('The command "%s" has a dependency on a non-existent service "doctrine".', static::$defaultName); | 
            ||
| 115 | |||
| 116 |             throw new ServiceNotFoundException('doctrine', static::class, null, [], $msg); | 
            ||
| 117 | }  | 
            ||
| 118 | |||
| 119 |         if ($input->getOption('user_model')) { | 
            ||
| 120 |             try { | 
            ||
| 121 | $this->getUserEntityClass($input, $output);  | 
            ||
| 122 |             } catch (\Exception $e) { | 
            ||
| 123 |                 $output->writeln(sprintf('<error>%s</error>', $e->getMessage())); | 
            ||
| 124 | |||
| 125 | return 1;  | 
            ||
| 126 | }  | 
            ||
| 127 | }  | 
            ||
| 128 | |||
| 129 |         if (!$this->aclObjectManipulators) { | 
            ||
| 130 |             $output->writeln('No manipulators are implemented : <info>ignoring</info>'); | 
            ||
| 131 | |||
| 132 | return 1;  | 
            ||
| 133 | }  | 
            ||
| 134 | |||
| 135 |         foreach ($this->pool->getAdminServiceIds() as $id) { | 
            ||
| 136 |             try { | 
            ||
| 137 | $admin = $this->pool->getInstance($id);  | 
            ||
| 138 |             } catch (\Exception $e) { | 
            ||
| 139 |                 $output->writeln('<error>Warning : The admin class cannot be initiated from the command line</error>'); | 
            ||
| 140 |                 $output->writeln(sprintf('<error>%s</error>', $e->getMessage())); | 
            ||
| 141 | |||
| 142 | continue;  | 
            ||
| 143 | }  | 
            ||
| 144 | |||
| 145 |             if ($input->getOption('step') && !$this->askConfirmation($input, $output, sprintf("<question>Generate ACLs for the object instances handled by \"%s\"?</question>\n", $id), 'no', '?')) { | 
            ||
| 146 | continue;  | 
            ||
| 147 | }  | 
            ||
| 148 | |||
| 149 | $securityIdentity = null;  | 
            ||
| 150 |             if ($input->getOption('step') && $this->askConfirmation($input, $output, "<question>Set an object owner?</question>\n", 'no', '?')) { | 
            ||
| 151 | $username = $this->askAndValidate($input, $output, 'Please enter the username: ', '', 'Sonata\AdminBundle\Command\Validators::validateUsername');  | 
            ||
| 152 | |||
| 153 | $securityIdentity = new UserSecurityIdentity($username, $this->getUserEntityClass($input, $output));  | 
            ||
| 154 | }  | 
            ||
| 155 |             if (!$input->getOption('step') && $input->getOption('object_owner')) { | 
            ||
| 156 |                 $securityIdentity = new UserSecurityIdentity($input->getOption('object_owner'), $this->getUserEntityClass($input, $output)); | 
            ||
| 157 | }  | 
            ||
| 158 | |||
| 159 |             $manipulatorId = sprintf('sonata.admin.manipulator.acl.object.%s', $admin->getManagerType()); | 
            ||
| 160 |             if (!$manipulator = $this->aclObjectManipulators[$manipulatorId] ?? null) { | 
            ||
| 161 |                 $output->writeln('Admin class is using a manager type that has no manipulator implemented : <info>ignoring</info>'); | 
            ||
| 162 | |||
| 163 | continue;  | 
            ||
| 164 | }  | 
            ||
| 165 |             if (!$manipulator instanceof ObjectAclManipulatorInterface) { | 
            ||
| 166 |                 $output->writeln(sprintf('The interface "ObjectAclManipulatorInterface" is not implemented for %s: <info>ignoring</info>', \get_class($manipulator))); | 
            ||
| 167 | |||
| 168 | continue;  | 
            ||
| 169 | }  | 
            ||
| 170 | |||
| 171 | \assert($admin instanceof AdminInterface);  | 
            ||
| 172 | $manipulator->batchConfigureAcls($output, $admin, $securityIdentity);  | 
            ||
| 173 | }  | 
            ||
| 174 | |||
| 175 | return 0;  | 
            ||
| 176 | }  | 
            ||
| 177 | |||
| 242 | 
If you suppress an error, we recommend checking for the error condition explicitly: