Conditions | 29 |
Paths | 536 |
Total Lines | 107 |
Code Lines | 58 |
Lines | 6 |
Ratio | 5.61 % |
Changes | 15 | ||
Bugs | 9 | 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 |
||
66 | protected function afterInitialize() |
||
67 | { |
||
68 | // multi-language is enabled? |
||
69 | if (App::$Properties->get('multiLanguage') === true) { |
||
70 | // maybe its a language domain alias? |
||
71 | if (Obj::isArray(App::$Properties->get('languageDomainAlias'))) { |
||
72 | /** @var array $domainAlias */ |
||
73 | $domainAlias = App::$Properties->get('languageDomainAlias'); |
||
74 | if (Obj::isArray($domainAlias) && !Str::likeEmpty($domainAlias[$this->getHost()])) { |
||
75 | $this->language = $domainAlias[$this->getHost()]; |
||
76 | } |
||
77 | } else { |
||
78 | // try to find language in pathway |
||
79 | foreach (App::$Properties->get('languages') as $lang) { |
||
|
|||
80 | if (Str::startsWith('/' . $lang, $this->getPathInfo())) { |
||
81 | $this->language = $lang; |
||
82 | $this->languageInPath = true; |
||
83 | } |
||
84 | } |
||
85 | |||
86 | // try to find in ?lang get |
||
87 | if ($this->language === null && Arr::in($this->query->get('lang'), App::$Properties->get('languages'))) { |
||
88 | $this->language = $this->query->get('lang'); |
||
89 | } |
||
90 | |||
91 | // language still not defined?! |
||
92 | if ($this->language === null) { |
||
93 | $userLang = App::$Properties->get('singleLanguage'); |
||
94 | $browserAccept = $this->getLanguages(); |
||
95 | if (Obj::isArray($browserAccept) && count($browserAccept) > 0) { |
||
96 | foreach ($browserAccept as $bLang) { |
||
97 | if (Arr::in($bLang, App::$Properties->get('languages'))) { |
||
98 | $userLang = $bLang; |
||
99 | break; // stop calculating, language is founded in priority |
||
100 | } |
||
101 | } |
||
102 | } |
||
103 | |||
104 | $queryString = null; |
||
105 | if (count($this->query->all()) > 0) { |
||
106 | $queryString = '?' . http_build_query($this->query->all()); |
||
107 | } |
||
108 | |||
109 | $response = new Redirect($this->getSchemeAndHttpHost() . $this->basePath . '/' . $userLang . $this->getPathInfo() . $queryString); |
||
110 | $response->send(); |
||
111 | exit(); |
||
112 | } |
||
113 | } |
||
114 | } else { // multi-language is disabled? Use default language |
||
115 | $this->language = App::$Properties->get('singleLanguage'); |
||
116 | } |
||
117 | |||
118 | // calculated depend of language |
||
119 | $pathway = $this->getPathInfo(); |
||
120 | $routing = App::$Properties->getAll('Routing'); |
||
121 | |||
122 | // try to find static routing alias |
||
123 | /** @var bool|array $aliasMap */ |
||
124 | $aliasMap = false; |
||
125 | View Code Duplication | if (isset($routing['Alias']) && isset($routing['Alias'][env_name])) { |
|
126 | $aliasMap = $routing['Alias'][env_name]; |
||
127 | } |
||
128 | |||
129 | if (Obj::isArray($aliasMap) && array_key_exists($pathway, $aliasMap)) { |
||
130 | $pathway = $aliasMap[$pathway]; |
||
131 | $this->aliasPathTarget = $pathway; |
||
132 | } |
||
133 | |||
134 | // check if pathway is the same with target and redirect to source from static routing |
||
135 | if (Obj::isArray($aliasMap) && Arr::in($this->getPathInfo(), $aliasMap)) { |
||
136 | $source = array_search($this->getPathInfo(), $aliasMap); |
||
137 | $targetUri = $this->getSchemeAndHttpHost() . $this->getBasePath() . '/'; |
||
138 | if (App::$Properties->get('multiLanguage') === true) { |
||
139 | $targetUri .= $this->language . '/'; |
||
140 | } |
||
141 | $targetUri .= ltrim($source, '/'); |
||
142 | $response = new Redirect($targetUri); |
||
143 | $response->send(); |
||
144 | exit(); |
||
145 | } |
||
146 | |||
147 | // define data from pathway |
||
148 | $this->setPathdata(explode('/', trim($pathway, '/'))); |
||
149 | |||
150 | if ($this->action == null) { // can be null or string(0)"" |
||
151 | $this->action = 'Index'; |
||
152 | } |
||
153 | |||
154 | // empty or contains backslashes? set to main |
||
155 | if ($this->controller == null || Str::contains('\\', $this->controller)) { |
||
156 | $this->controller = 'Main'; |
||
157 | } |
||
158 | |||
159 | $callbackMap = false; |
||
160 | View Code Duplication | if (isset($routing['Callback']) && isset($routing['Callback'][env_name])) { |
|
161 | $callbackMap = $routing['Callback'][env_name]; |
||
162 | } |
||
163 | |||
164 | // check is dynamic callback map exist |
||
165 | if (isset($callbackMap[$this->controller])) { |
||
166 | $callbackClass = $callbackMap[$this->controller]; |
||
167 | // check if rule for current controller is exist |
||
168 | if ($callbackClass !== null) { |
||
169 | $this->callbackClass = $callbackClass; |
||
170 | } |
||
171 | } |
||
172 | } |
||
173 | |||
323 | } |