| Conditions | 3 |
| Paths | 1 |
| Total Lines | 123 |
| Code Lines | 87 |
| 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 |
||
| 23 | protected function configureOptions(OptionsResolver $resolver): void |
||
| 24 | { |
||
| 25 | $resolver |
||
| 26 | // Main info |
||
| 27 | ->setRequired('name') |
||
| 28 | ->setAllowedTypes('name', 'string') |
||
| 29 | ->setRequired('admin_name') |
||
| 30 | ->setAllowedTypes('admin_name', 'string') |
||
| 31 | ->setDefault('title', null) |
||
| 32 | ->addNormalizer('title', $this->getTitleNormalizer()) |
||
| 33 | ->setAllowedTypes('title', ['string', 'null']) |
||
| 34 | ->setDefault('icon', null) |
||
| 35 | ->setAllowedTypes('icon', ['string', 'null']) |
||
| 36 | ->setDefault('action_class', Action::class) |
||
| 37 | ->setAllowedTypes('action_class', 'string') |
||
| 38 | ->setDefault('template', null) |
||
| 39 | ->addNormalizer('template', $this->getTemplateNormalizer()) |
||
| 40 | ->setAllowedTypes('template', ['string', 'null']) |
||
| 41 | |||
| 42 | // Linked actions |
||
| 43 | ->setDefault('list_actions', [ |
||
| 44 | 'edit' => [], |
||
| 45 | 'delete' => [], |
||
| 46 | ]) |
||
| 47 | ->setAllowedTypes('list_actions', 'array') |
||
| 48 | ->setNormalizer('list_actions', function (Options $options, $value) { |
||
| 49 | foreach ($value as $actionName => $actionConfiguration) { |
||
| 50 | $value[$actionName] = LinkNormalizer::normalize( |
||
| 51 | $actionConfiguration, |
||
| 52 | $options->offsetGet('name'), |
||
| 53 | $actionName |
||
| 54 | ); |
||
| 55 | } |
||
| 56 | |||
| 57 | return $value; |
||
| 58 | }) |
||
| 59 | |||
| 60 | ->setDefault('item_actions', [ |
||
| 61 | 'create' => [], |
||
| 62 | ]) |
||
| 63 | ->setAllowedTypes('item_actions', 'array') |
||
| 64 | ->setNormalizer('item_actions', function (Options $options, $value) { |
||
| 65 | foreach ($value as $actionName => $actionConfiguration) { |
||
| 66 | $value[$actionName] = LinkNormalizer::normalize( |
||
| 67 | $actionConfiguration, |
||
| 68 | $options->offsetGet('name'), |
||
| 69 | $actionName |
||
| 70 | ); |
||
| 71 | } |
||
| 72 | |||
| 73 | return $value; |
||
| 74 | }) |
||
| 75 | |||
| 76 | // Routing |
||
| 77 | ->setDefault('controller', AdminAction::class) |
||
| 78 | ->setAllowedTypes('controller', 'string') |
||
| 79 | ->setRequired('route') |
||
| 80 | ->setAllowedTypes('route', 'string') |
||
| 81 | ->setDefault('route_parameters', []) |
||
| 82 | ->setAllowedTypes('route_parameters', 'array') |
||
| 83 | ->addNormalizer('route_parameters', $this->getRouteParametersNormalizer()) |
||
| 84 | ->setDefault('path', null) |
||
| 85 | ->setAllowedTypes('path', ['string', 'null']) |
||
| 86 | ->addNormalizer('path', $this->getPathNormalizer()) |
||
| 87 | |||
| 88 | // Fields |
||
| 89 | ->setDefault('fields', []) |
||
| 90 | ->setAllowedTypes('fields', 'array') |
||
| 91 | ->addNormalizer('fields', $this->getFieldsNormalizer()) |
||
| 92 | |||
| 93 | // Filter and orders |
||
| 94 | ->setDefault('order', []) |
||
| 95 | ->setAllowedTypes('order', 'array') |
||
| 96 | ->addNormalizer('order', $this->getOrderNormalizer()) |
||
| 97 | ->setDefault('criteria', []) |
||
| 98 | ->setAllowedTypes('criteria', 'array') |
||
| 99 | ->addNormalizer('criteria', $this->getCriteriaNormalizer()) |
||
| 100 | ->setDefault('filters', []) |
||
| 101 | ->setAllowedTypes('filters', 'array') |
||
| 102 | ->addNormalizer('filters', $this->getFiltersNormalizer()) |
||
| 103 | |||
| 104 | // Security |
||
| 105 | ->setDefault('permissions', ['ROLE_ADMIN']) |
||
| 106 | ->setAllowedTypes('permissions', 'array') |
||
| 107 | |||
| 108 | // Export |
||
| 109 | ->setDefault('export', ['csv', 'xml', 'yaml']) |
||
| 110 | ->setAllowedTypes('export', 'array') |
||
| 111 | |||
| 112 | // Data |
||
| 113 | ->setDefault('load_strategy', null) |
||
| 114 | ->setAllowedValues('load_strategy', [ |
||
| 115 | null, |
||
| 116 | AdminInterface::LOAD_STRATEGY_NONE, |
||
| 117 | AdminInterface::LOAD_STRATEGY_UNIQUE, |
||
| 118 | AdminInterface::LOAD_STRATEGY_MULTIPLE, |
||
| 119 | ]) |
||
| 120 | ->addNormalizer('load_strategy', $this->getLoadStrategyNormalizer()) |
||
| 121 | ->setDefault('repository_method', null) |
||
| 122 | ->setAllowedTypes('repository_method', ['string', 'null']) |
||
| 123 | |||
| 124 | // Pagination |
||
| 125 | ->setDefault('pager', 'pagerfanta') |
||
| 126 | ->setAllowedValues('pager', ['pagerfanta', false]) |
||
| 127 | ->setDefault('max_per_page', 25) |
||
| 128 | ->setAllowedTypes('max_per_page', 'integer') |
||
| 129 | ->setDefault('page_parameter', 'page') |
||
| 130 | ->setAllowedTypes('page_parameter', 'string') |
||
| 131 | |||
| 132 | ->setDefault('date_format', 'Y-m-d') |
||
| 133 | ->setAllowedTypes('date_format', 'string') |
||
| 134 | |||
| 135 | // Form |
||
| 136 | ->setDefault('form', null) |
||
| 137 | ->setAllowedTypes('form', ['string', 'null', 'boolean']) |
||
| 138 | ->setDefault('form_options', []) |
||
| 139 | ->setAllowedTypes('form_options', 'array') |
||
| 140 | |||
| 141 | // Redirection after success |
||
| 142 | ->setDefault('target_route', 'list') |
||
| 143 | ->setAllowedTypes('target_route', 'string') |
||
| 144 | ->setDefault('target_route_parameters', []) |
||
| 145 | ->setAllowedTypes('target_route_parameters', 'array') |
||
| 146 | ; |
||
| 538 |
This check looks for private methods that have been defined, but are not used inside the class.