| Conditions | 15 |
| Paths | 34 |
| Total Lines | 77 |
| 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 |
||
| 74 | public function execute(InputInterface $input, OutputInterface $output): int |
||
| 75 | { |
||
| 76 | $output->writeln('Welcome to the AdminBundle object ACL generator'); |
||
| 77 | $output->writeln([ |
||
|
|
|||
| 78 | '', |
||
| 79 | 'This command helps you to generate ACL entities for the objects handled by the AdminBundle.', |
||
| 80 | '', |
||
| 81 | 'If the step option is used, you will be asked if you want to generate the object ACL entities for each Admin.', |
||
| 82 | 'You must use the shortcut notation like <comment>AcmeDemoBundle:User</comment> if you want to set an object owner.', |
||
| 83 | '', |
||
| 84 | ]); |
||
| 85 | |||
| 86 | if (!$this->registry) { |
||
| 87 | throw new ServiceNotFoundException('doctrine', static::class, null, [], sprintf( |
||
| 88 | 'The command "%s" has a dependency on a non-existent service "doctrine".', |
||
| 89 | static::$defaultName |
||
| 90 | )); |
||
| 91 | } |
||
| 92 | |||
| 93 | if ($input->getOption('user_model')) { |
||
| 94 | try { |
||
| 95 | $this->getUserModelClass($input, $output); |
||
| 96 | } catch (\Exception $e) { |
||
| 97 | $output->writeln(sprintf('<error>%s</error>', $e->getMessage())); |
||
| 98 | |||
| 99 | return 1; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | if (!$this->aclObjectManipulators) { |
||
| 104 | $output->writeln('No manipulators are implemented : <info>ignoring</info>'); |
||
| 105 | |||
| 106 | return 1; |
||
| 107 | } |
||
| 108 | |||
| 109 | foreach ($this->pool->getAdminServiceIds() as $id) { |
||
| 110 | try { |
||
| 111 | $admin = $this->pool->getInstance($id); |
||
| 112 | } catch (\Exception $e) { |
||
| 113 | $output->writeln('<error>Warning : The admin class cannot be initiated from the command line</error>'); |
||
| 114 | $output->writeln(sprintf('<error>%s</error>', $e->getMessage())); |
||
| 115 | |||
| 116 | continue; |
||
| 117 | } |
||
| 118 | |||
| 119 | if ($input->getOption('step') && !$this->askConfirmation($input, $output, sprintf("<question>Generate ACLs for the object instances handled by \"%s\"?</question>\n", $id), 'no')) { |
||
| 120 | continue; |
||
| 121 | } |
||
| 122 | |||
| 123 | $securityIdentity = null; |
||
| 124 | if ($input->getOption('step') && $this->askConfirmation($input, $output, "<question>Set an object owner?</question>\n", 'no')) { |
||
| 125 | $username = $this->askAndValidate($input, $output, 'Please enter the username: ', '', 'Sonata\AdminBundle\Command\Validators::validateUsername'); |
||
| 126 | |||
| 127 | $securityIdentity = new UserSecurityIdentity($username, $this->getUserModelClass($input, $output)); |
||
| 128 | } |
||
| 129 | if (!$input->getOption('step') && $input->getOption('object_owner')) { |
||
| 130 | $securityIdentity = new UserSecurityIdentity($input->getOption('object_owner'), $this->getUserModelClass($input, $output)); |
||
| 131 | } |
||
| 132 | |||
| 133 | $manipulatorId = sprintf('sonata.admin.manipulator.acl.object.%s', $admin->getManagerType()); |
||
| 134 | if (!$manipulator = $this->aclObjectManipulators[$manipulatorId] ?? null) { |
||
| 135 | $output->writeln('Admin class is using a manager type that has no manipulator implemented : <info>ignoring</info>'); |
||
| 136 | |||
| 137 | continue; |
||
| 138 | } |
||
| 139 | if (!$manipulator instanceof ObjectAclManipulatorInterface) { |
||
| 140 | $output->writeln(sprintf('The interface "ObjectAclManipulatorInterface" is not implemented for %s: <info>ignoring</info>', \get_class($manipulator))); |
||
| 141 | |||
| 142 | continue; |
||
| 143 | } |
||
| 144 | |||
| 145 | \assert($admin instanceof AdminInterface); |
||
| 146 | $manipulator->batchConfigureAcls($output, $admin, $securityIdentity); |
||
| 147 | } |
||
| 148 | |||
| 149 | return 0; |
||
| 150 | } |
||
| 151 | |||
| 180 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: