| Conditions | 9 |
| Paths | 12 |
| Total Lines | 72 |
| 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 |
||
| 40 | public function loadConfiguration() |
||
| 41 | { |
||
| 42 | $builder = $this->getContainerBuilder(); |
||
| 43 | $config = $this->getConfig($this->defaults); |
||
| 44 | |||
| 45 | $builder->addDefinition($this->prefix('environment')) |
||
| 46 | ->setType(Environment::class); |
||
| 47 | |||
| 48 | $builder->addDefinition($this->prefix('detector')) |
||
| 49 | ->setType(NetteRequestDetector::class); |
||
| 50 | |||
| 51 | $builder->addDefinition($this->prefix('profileStorage')) |
||
| 52 | ->setType(SessionProfileStorage::class); |
||
| 53 | |||
| 54 | $profileContainer = $builder->addDefinition($this->prefix('profileContainer')) |
||
| 55 | ->setType(ProfileContainer::class); |
||
| 56 | |||
| 57 | if (empty($config['profile'])) { |
||
| 58 | throw new ConfigurationException("You must define some profile combination in your configuration."); |
||
| 59 | } |
||
| 60 | |||
| 61 | $requiredProfileParams = ['country', 'language', 'currency']; |
||
| 62 | foreach ($config['profile'] as $profileName => $profile) { |
||
| 63 | if (!empty(array_diff($requiredProfileParams, array_keys($profile)))) { |
||
| 64 | throw new ConfigurationException("Problem with \"{$profileName}\" profile configuration. There are missing some of the required parameters (country, language, currency)."); |
||
| 65 | } |
||
| 66 | |||
| 67 | $profileContainer->addSetup('addProfile', [ |
||
| 68 | $profileName, |
||
| 69 | (array) $profile['country'], |
||
| 70 | (array) $profile['language'], |
||
| 71 | (array) $profile['currency'], |
||
| 72 | array_key_exists('domain', $profile) ? (array) $profile['domain'] : [], |
||
| 73 | !(array_key_exists('disable', $profile) && $profile['disable'] === TRUE), |
||
| 74 | ]); |
||
| 75 | } |
||
| 76 | |||
| 77 | if ($config['translations']['enable']) { |
||
| 78 | $extensions = $this->compiler->getExtensions($extensionClass = '\Kdyby\Translation\DI\TranslationExtension'); |
||
| 79 | if (empty($extensions)) { |
||
| 80 | throw new AssertionException('You should register \'' . $extensionClass . '\' before \'' . get_class($this) . '\'.', E_USER_NOTICE); |
||
| 81 | } |
||
| 82 | /** @var \Nette\DI\CompilerExtension $extension */ |
||
| 83 | $extension = $extensions[array_keys($extensions)[0]]; |
||
| 84 | |||
| 85 | $builder->addDefinition($this->prefix('translationResolver')) |
||
| 86 | ->setType(ProfileStorageResolver::class) |
||
| 87 | ->setArguments([ |
||
| 88 | 'useDefault' => (bool) $config['translations']['useDefault'], |
||
| 89 | ]); |
||
| 90 | |||
| 91 | $chain = $builder->getDefinition($extension->name . '.userLocaleResolver'); |
||
| 92 | $chain->addSetup('addResolver', [ |
||
| 93 | $this->prefix('@translationResolver') |
||
| 94 | ]); |
||
| 95 | |||
| 96 | $builder->addDefinition($this->prefix('changeTranslatorLocaleHandler')) |
||
| 97 | ->setType(ChangeTranslatorLocaleHandler::class) |
||
| 98 | ->setTags([ |
||
| 99 | 'run' => TRUE |
||
| 100 | ]); |
||
| 101 | |||
| 102 | # @todo: Add resolver to Tracy Bar |
||
| 103 | } |
||
| 104 | |||
| 105 | if ($this->useDebugger()) { |
||
| 106 | $builder->addDefinition($this->prefix('panel')) |
||
| 107 | ->setType(Panel::class) |
||
| 108 | ->setInject(FALSE) |
||
| 109 | ->setAutowired(FALSE); |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 166 |