| Conditions | 11 |
| Paths | 50 |
| Total Lines | 70 |
| 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 |
||
| 57 | public function execute(XmlConfigDomDocument $document) |
||
| 58 | { |
||
| 59 | // set up our default namespace |
||
| 60 | $document->setDefaultNamespace(self::XML_NAMESPACE, 'translation'); |
||
| 61 | |||
| 62 | $config = $document->documentURI; |
||
| 63 | |||
| 64 | $translatorData = array(); |
||
| 65 | $localeData = array(); |
||
| 66 | |||
| 67 | $defaultDomain = ''; |
||
| 68 | $defaultLocale = null; |
||
| 69 | $defaultTimeZone = null; |
||
| 70 | |||
| 71 | foreach ($document->getConfigurationElements() as $cfg) { |
||
| 72 | if ($cfg->hasChild('available_locales')) { |
||
| 73 | /** @var XmlConfigDomElement $availableLocales */ |
||
| 74 | $availableLocales = $cfg->getChild('available_locales'); |
||
| 75 | // TODO: is this really optional? according to the schema: yes... |
||
| 76 | $defaultLocale = $availableLocales->getAttribute('default_locale', $defaultLocale); |
||
| 77 | $defaultTimeZone = $availableLocales->getAttribute('default_timezone', $defaultTimeZone); |
||
| 78 | /** @var XmlConfigDomElement $locale */ |
||
| 79 | foreach ($availableLocales as $locale) { |
||
| 80 | $name = $locale->getAttribute('identifier'); |
||
| 81 | if (!isset($localeData[$name])) { |
||
| 82 | $localeData[$name] = array('name' => $name, 'params' => array(), 'fallback' => null, 'ldml_file' => null); |
||
| 83 | } |
||
| 84 | $localeData[$name]['params'] = $locale->getAgaviParameters($localeData[$name]['params']); |
||
| 85 | $localeData[$name]['fallback'] = $locale->getAttribute('fallback', $localeData[$name]['fallback']); |
||
| 86 | $localeData[$name]['ldml_file'] = $locale->getAttribute('ldml_file', $localeData[$name]['ldml_file']); |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | if ($cfg->hasChild('translators')) { |
||
| 91 | /** @var XmlConfigDomElement $translators */ |
||
| 92 | $translators = $cfg->getChild('translators'); |
||
| 93 | $defaultDomain = $translators->getAttribute('default_domain', $defaultDomain); |
||
| 94 | $this->getTranslators($translators, $translatorData); |
||
|
|
|||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | $data = array(); |
||
| 99 | |||
| 100 | $data[] = sprintf('$this->defaultDomain = %s;', var_export($defaultDomain, true)); |
||
| 101 | $data[] = sprintf('$this->defaultLocaleIdentifier = %s;', var_export($defaultLocale, true)); |
||
| 102 | $data[] = sprintf('$this->defaultTimeZone = %s;', var_export($defaultTimeZone, true)); |
||
| 103 | |||
| 104 | foreach ($localeData as $locale) { |
||
| 105 | // TODO: fallback stuff |
||
| 106 | |||
| 107 | $data[] = sprintf('$this->availableConfigLocales[%s] = array(\'identifier\' => %s, \'identifierData\' => %s, \'parameters\' => %s);', var_export($locale['name'], true), var_export($locale['name'], true), var_export(Locale::parseLocaleIdentifier($locale['name']), true), var_export($locale['params'], true)); |
||
| 108 | } |
||
| 109 | |||
| 110 | foreach ($translatorData as $domain => $translator) { |
||
| 111 | foreach (array('msg', 'num', 'cur', 'date') as $type) { |
||
| 112 | if (isset($translator[$type]['class'])) { |
||
| 113 | if (!class_exists($translator[$type]['class'])) { |
||
| 114 | throw new ConfigurationException(sprintf('The Translator or Formatter class "%s" for domain "%s" could not be found.', $translator[$type]['class'], $domain)); |
||
| 115 | } |
||
| 116 | $data[] = join("\n", array( |
||
| 117 | sprintf('$this->translators[%s][%s] = new %s();', var_export($domain, true), var_export($type, true), $translator[$type]['class']), |
||
| 118 | sprintf('$this->translators[%s][%s]->initialize($this->getContext(), %s);', var_export($domain, true), var_export($type, true), var_export($translator[$type]['params'], true)), |
||
| 119 | sprintf('$this->translatorFilters[%s][%s] = %s;', var_export($domain, true), var_export($type, true), var_export($translator[$type]['filters'], true)), |
||
| 120 | )); |
||
| 121 | } |
||
| 122 | } |
||
| 123 | } |
||
| 124 | |||
| 125 | return $this->generate($data, $config); |
||
| 126 | } |
||
| 127 | |||
| 214 |
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: