| Conditions | 5 |
| Paths | 1 |
| Total Lines | 101 |
| Code Lines | 75 |
| Lines | 14 |
| Ratio | 13.86 % |
| Changes | 6 | ||
| Bugs | 2 | Features | 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 |
||
| 123 | public function __construct(array $applicationConfiguration = [], $locale) |
||
| 124 | { |
||
| 125 | $resolver = new OptionsResolver(); |
||
| 126 | $resolver->setDefaults([ |
||
| 127 | 'enable_extra_configuration' => true, |
||
| 128 | 'title' => '', |
||
| 129 | 'description' => '', |
||
| 130 | 'locale' => $locale, |
||
| 131 | 'layout' => 'LAGAdminBundle::admin.layout.html.twig', |
||
| 132 | 'block_template' => 'LAGAdminBundle:Form:fields.html.twig', |
||
| 133 | 'bootstrap' => false, |
||
| 134 | 'date_format' => 'd/m/Y', |
||
| 135 | 'string_length' => 0, |
||
| 136 | 'string_length_truncate' => '...', |
||
| 137 | 'routing' => [ |
||
| 138 | 'url_pattern' => '/{admin}/{action}', |
||
| 139 | 'name_pattern' => 'lag.admin.{admin}', |
||
| 140 | ], |
||
| 141 | 'translation' => [ |
||
| 142 | 'enabled' => true, |
||
| 143 | 'pattern' => 'lag.admin.{key}', |
||
| 144 | ], |
||
| 145 | 'max_per_page' => 25, |
||
| 146 | 'fields_mapping' => [ |
||
| 147 | ], |
||
| 148 | ]); |
||
| 149 | $resolver->setAllowedValues('enable_extra_configuration', [true, false]); |
||
| 150 | $applicationConfiguration = $resolver->resolve($applicationConfiguration); |
||
| 151 | // merge default field configuration |
||
| 152 | $applicationConfiguration['fields_mapping'] = array_merge([ |
||
| 153 | Field::TYPE_STRING => 'LAG\AdminBundle\Field\Field\StringField', |
||
| 154 | Field::TYPE_ARRAY => 'LAG\AdminBundle\Field\Field\ArrayField', |
||
| 155 | Field::TYPE_LINK => 'LAG\AdminBundle\Field\Field\Link', |
||
| 156 | Field::TYPE_DATE => 'LAG\AdminBundle\Field\Field\Date', |
||
| 157 | Field::TYPE_COUNT => 'LAG\AdminBundle\Field\Field\Count', |
||
| 158 | Field::TYPE_ACTION => 'LAG\AdminBundle\Field\Field\Action', |
||
| 159 | Field::TYPE_COLLECTION => 'LAG\AdminBundle\Field\Field\Collection', |
||
| 160 | Field::TYPE_BOOLEAN => 'LAG\AdminBundle\Field\Field\Boolean', |
||
| 161 | ], $applicationConfiguration['fields_mapping']); |
||
| 162 | |||
| 163 | // resolving routing options |
||
| 164 | $routingConfiguration = $applicationConfiguration['routing']; |
||
| 165 | $resolver->clear(); |
||
| 166 | $resolver->setRequired([ |
||
| 167 | 'url_pattern', |
||
| 168 | 'name_pattern', |
||
| 169 | ]); |
||
| 170 | $resolver->setNormalizer('url_pattern', function (Options $options, $value) { |
||
| 171 | if (strstr($value, '{admin}') === false) { |
||
| 172 | throw new InvalidOptionsException('Admin routing configuration url pattern should contains {admin} placeholder'); |
||
| 173 | } |
||
| 174 | if (strstr($value, '{action}') === false) { |
||
| 175 | throw new InvalidOptionsException('Admin routing configuration url pattern should contains {action} placeholder'); |
||
| 176 | } |
||
| 177 | |||
| 178 | return $value; |
||
| 179 | }); |
||
| 180 | View Code Duplication | $resolver->setNormalizer('name_pattern', function (Options $options, $value) { |
|
| 181 | if (strstr($value, '{admin}') === false) { |
||
| 182 | throw new InvalidOptionsException('Admin routing configuration pattern name should contains {admin} placeholder'); |
||
| 183 | } |
||
| 184 | |||
| 185 | return $value; |
||
| 186 | }); |
||
| 187 | $routingConfiguration = $resolver->resolve($routingConfiguration); |
||
| 188 | // routing configuration |
||
| 189 | $this->routingUrlPattern = $routingConfiguration['url_pattern']; |
||
| 190 | $this->routingNamePattern = $routingConfiguration['name_pattern']; |
||
| 191 | |||
| 192 | // resolving translation configuration |
||
| 193 | $translationConfiguration = $applicationConfiguration['translation']; |
||
| 194 | $resolver |
||
| 195 | ->clear() |
||
| 196 | ->setDefault('enabled', true) |
||
| 197 | ->setDefault('pattern', 'lag.admin.{key}'); |
||
| 198 | View Code Duplication | $resolver->setNormalizer('pattern', function (Options $options, $value) { |
|
| 199 | if (strstr($value, 'key') === false) { |
||
| 200 | throw new InvalidOptionsException('Admin translation configuration pattern should contains {key} placeholder'); |
||
| 201 | } |
||
| 202 | |||
| 203 | return $value; |
||
| 204 | }); |
||
| 205 | $translationConfiguration = $resolver->resolve($translationConfiguration); |
||
| 206 | // translation configuration |
||
| 207 | $this->useTranslation = $translationConfiguration['enabled']; |
||
| 208 | $this->translationPattern = $translationConfiguration['pattern']; |
||
| 209 | |||
| 210 | // application main configuration |
||
| 211 | $this->title = $applicationConfiguration['title']; |
||
| 212 | $this->description = $applicationConfiguration['description']; |
||
| 213 | $this->locale = $applicationConfiguration['locale']; |
||
| 214 | $this->title = $applicationConfiguration['title']; |
||
| 215 | $this->layout = $applicationConfiguration['layout']; |
||
| 216 | $this->blockTemplate = $applicationConfiguration['block_template']; |
||
| 217 | $this->bootstrap = $applicationConfiguration['bootstrap']; |
||
| 218 | $this->dateFormat = $applicationConfiguration['date_format']; |
||
| 219 | $this->stringLength = $applicationConfiguration['string_length']; |
||
| 220 | $this->stringLengthTruncate = $applicationConfiguration['string_length_truncate']; |
||
| 221 | $this->maxPerPage = $applicationConfiguration['max_per_page']; |
||
| 222 | $this->fieldsMapping = $applicationConfiguration['fields_mapping']; |
||
| 223 | } |
||
| 224 | |||
| 498 |