| Conditions | 9 |
| Paths | 34 |
| Total Lines | 77 |
| Code Lines | 40 |
| 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 |
||
| 28 | public function create(Request $request, AdminInterface $admin): ViewInterface |
||
| 29 | { |
||
| 30 | if (RedirectionUtils::isRedirectionRequired($admin)) { |
||
| 31 | $targetRoute = $admin->getAction()->getConfiguration()->getTargetRoute(); |
||
| 32 | $targetRouteParameters = $admin->getAction()->getConfiguration()->getTargetRouteParameters(); |
||
| 33 | |||
| 34 | if ($admin->getConfiguration()->hasAction($targetRoute)) { |
||
| 35 | $targetRoute = $this->routeNameGenerator->generateRouteName($admin->getName(), $targetRoute); |
||
| 36 | } |
||
| 37 | |||
| 38 | return new RedirectView( |
||
| 39 | $targetRoute, |
||
| 40 | (new ParametersMapper())->map($admin->getData(), $targetRouteParameters), |
||
| 41 | ); |
||
| 42 | } |
||
| 43 | $actionConfiguration = $admin->getAction()->getConfiguration(); |
||
| 44 | $fields = []; |
||
| 45 | $fieldConfigurations = $actionConfiguration->getFields(); |
||
| 46 | $context = [ |
||
| 47 | 'admin_name' => $actionConfiguration->getAdminName(), |
||
| 48 | 'action_name' => $actionConfiguration->getName(), |
||
| 49 | 'entity_class' => $admin->getConfiguration()->getEntityClass(), |
||
| 50 | ]; |
||
| 51 | |||
| 52 | |||
| 53 | if (count($fieldConfigurations) > 0) { |
||
| 54 | foreach ($actionConfiguration->getFields() as $name => $configuration) { |
||
| 55 | $fields[$name] = $this->fieldFactory->create($name, $configuration, $context); |
||
| 56 | } |
||
| 57 | } else { |
||
| 58 | $reflectionClass = new \ReflectionClass($admin->getEntityClass()); |
||
| 59 | |||
| 60 | foreach ($reflectionClass->getProperties() as $reflectionProperty) { |
||
| 61 | $fields[$reflectionProperty->getName()] = $this |
||
| 62 | ->fieldFactory |
||
| 63 | ->create($reflectionProperty->getName(), [], $context) |
||
| 64 | ; |
||
| 65 | } |
||
| 66 | // $allowedItemActions = []; |
||
| 67 | // |
||
| 68 | // if ($admin->getConfiguration()->hasAction('edit')) { |
||
| 69 | // $allowedItemActions['edit'] = []; |
||
| 70 | // } |
||
| 71 | // |
||
| 72 | // if ($admin->getConfiguration()->hasAction('delete')) { |
||
| 73 | // $allowedItemActions['delete'] = []; |
||
| 74 | // } |
||
| 75 | // |
||
| 76 | // if (count($allowedItemActions) > 0) { |
||
| 77 | // $fields['_actions'] = $this->fieldFactory->create('_actions', [ |
||
| 78 | // 'type' => ActionCollectionField::class, |
||
| 79 | // ], $context); |
||
| 80 | // } |
||
| 81 | } |
||
| 82 | |||
| 83 | if ($request->isXmlHttpRequest()) { |
||
| 84 | $template = $this->applicationConfiguration->get('ajax_template'); |
||
| 85 | } else { |
||
| 86 | $template = $this->applicationConfiguration->get('base_template'); |
||
| 87 | } |
||
| 88 | $template = new Template($actionConfiguration->getTemplate(), $template); |
||
| 89 | $fieldViews = []; |
||
| 90 | |||
| 91 | foreach ($fields as $name => $field) { |
||
| 92 | $fieldViews[$name] = $field->createView(); |
||
| 93 | } |
||
| 94 | $formViews = []; |
||
| 95 | |||
| 96 | foreach ($admin->getForms() as $identifier => $form) { |
||
| 97 | $formViews[$identifier] = $form->createView(); |
||
| 98 | } |
||
| 99 | |||
| 100 | return new AdminView( |
||
| 101 | $admin, |
||
| 102 | $template, |
||
| 103 | $fieldViews, |
||
| 104 | $formViews, |
||
| 105 | ); |
||
| 108 |