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