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