| Conditions | 39 |
| Paths | > 20000 |
| Total Lines | 183 |
| 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 |
||
| 42 | function triggerBeforeDisplay(&$output_content) |
||
| 43 | { |
||
| 44 | if (Context::getResponseMethod() != 'HTML') return; |
||
| 45 | if (Context::get('module') == 'admin') return; |
||
| 46 | |||
| 47 | require_once(_XE_PATH_ . 'libs/idna_convert/idna_convert.class.php'); |
||
| 48 | |||
| 49 | $oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE); |
||
| 50 | |||
| 51 | $locales = array( |
||
| 52 | 'de' => 'de_DE', |
||
| 53 | 'en' => 'en_US', |
||
| 54 | 'es' => 'es_ES', |
||
| 55 | 'fr' => 'fr_FR', |
||
| 56 | 'ja' => 'ja_JP', |
||
| 57 | 'jp' => 'ja_JP', |
||
| 58 | 'ko' => 'ko_KR', |
||
| 59 | 'mn' => 'mn_MN', |
||
| 60 | 'ru' => 'ru_RU', |
||
| 61 | 'tr' => 'tr_TR', |
||
| 62 | 'vi' => 'vi_VN', |
||
| 63 | 'zh-CN' => 'zh_CN', |
||
| 64 | 'zh-TW' => 'zh_TW', |
||
| 65 | ); |
||
| 66 | |||
| 67 | $oModuleModel = getModel('module'); |
||
| 68 | $config = $this->getConfig(); |
||
| 69 | $IDN = new idna_convert(array('idn_version' => 2008)); |
||
| 70 | $request_uri = $IDN->encode(Context::get('request_uri')); |
||
| 71 | |||
| 72 | $logged_info = Context::get('logged_info'); |
||
| 73 | $current_module_info = Context::get('current_module_info'); |
||
| 74 | $site_module_info = Context::get('site_module_info'); |
||
| 75 | $document_srl = Context::get('document_srl'); |
||
| 76 | $is_article = false; |
||
| 77 | $single_image = false; |
||
| 78 | $is_index = ($current_module_info->module_srl == $site_module_info->module_srl) ? true : false; |
||
| 79 | |||
| 80 | $piece = new stdClass; |
||
| 81 | $piece->document_title = null; |
||
| 82 | $piece->type = 'website'; |
||
| 83 | $piece->url = getFullUrl(''); |
||
| 84 | $piece->title = Context::getBrowserTitle(); |
||
| 85 | $piece->description = $config->site_description; |
||
| 86 | $piece->keywords = $config->site_keywords; |
||
| 87 | $piece->tags = array(); |
||
| 88 | $piece->image = array(); |
||
| 89 | $piece->author = null; |
||
| 90 | |||
| 91 | if(stristr($_SERVER['HTTP_USER_AGENT'], 'facebookexternalhit') != FALSE) { |
||
| 92 | $single_image = true; |
||
| 93 | } |
||
| 94 | |||
| 95 | |||
| 96 | if($current_module_info->module_srl !== $site_module_info->module_srl) { |
||
| 97 | $mdoulePartConfig = $oModuleModel->getModulePartConfig('seo', $current_module_info->module_srl); |
||
| 98 | if($mdoulePartConfig && isset($mdoulePartConfig->meta_description) && trim($mdoulePartConfig->meta_description)) { |
||
| 99 | $piece->description = trim($mdoulePartConfig->meta_description); |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | if ($document_srl) { |
||
| 104 | $oDocument = Context::get('oDocument'); |
||
| 105 | if (!is_a($oDocument, 'documentItem')) { |
||
| 106 | $oDocumentModel = getModel('document'); |
||
| 107 | $oDocument = $oDocumentModel->getDocument($document_srl); |
||
| 108 | } |
||
| 109 | |||
| 110 | if (is_a($oDocument, 'documentItem') && $document_srl == $oDocument->document_srl) { |
||
| 111 | $is_article = true; |
||
| 112 | } |
||
| 113 | } |
||
| 114 | |||
| 115 | // 문서 데이터 수집 |
||
| 116 | if ($is_article) { |
||
| 117 | if (!$oDocument->isSecret()) { |
||
| 118 | $piece->document_title = $oDocument->getTitleText(); |
||
| 119 | $piece->url = getFullUrl('', 'mid', $current_module_info->mid, 'document_srl',$document_srl); |
||
| 120 | $piece->type = 'article'; |
||
| 121 | $piece->description = trim(str_replace(' ', ' ', $oDocument->getContentText(400))); |
||
| 122 | $piece->author = $oDocument->getNickName(); |
||
| 123 | $tags = $oDocument->get('tag_list'); |
||
| 124 | if (count($tags)) $piece->tags = $tags; |
||
| 125 | |||
| 126 | $document_images = false; |
||
| 127 | if($oCacheHandler->isSupport()) { |
||
| 128 | $cache_key_document_images = 'seo:document_images:' . $document_srl; |
||
| 129 | $document_images = $oCacheHandler->get($cache_key_document_images); |
||
| 130 | } |
||
| 131 | |||
| 132 | if($document_images === false && $oDocument->hasUploadedFiles()) { |
||
| 133 | $image_ext = array('bmp', 'gif', 'jpg', 'jpeg', 'png'); |
||
| 134 | $document_images = array(); |
||
| 135 | |||
| 136 | foreach ($oDocument->getUploadedFiles() as $file) { |
||
| 137 | if ($file->isvalid != 'Y') continue; |
||
| 138 | |||
| 139 | $ext = array_pop(explode('.', $file->uploaded_filename)); |
||
| 140 | |||
| 141 | if (!in_array(strtolower($ext), $image_ext)) continue; |
||
| 142 | list($width, $height) = @getimagesize($file->uploaded_filename); |
||
| 143 | if($width < 100 && $height < 100) continue; |
||
| 144 | |||
| 145 | $image = array( |
||
| 146 | 'filepath' => $file->uploaded_filename, |
||
| 147 | 'width' => $width, |
||
| 148 | 'height' => $height |
||
| 149 | ); |
||
| 150 | |||
| 151 | if($file->cover_image === 'Y') { |
||
| 152 | array_unshift($document_images, $image); |
||
| 153 | } else { |
||
| 154 | $document_images[] = $image; |
||
| 155 | } |
||
| 156 | } |
||
| 157 | |||
| 158 | if($oCacheHandler->isSupport()) { |
||
| 159 | $oCacheHandler->put($cache_key_document_images, $document_images); |
||
| 160 | } |
||
| 161 | } |
||
| 162 | |||
| 163 | if($document_images) $piece->image = $document_images; |
||
| 164 | } else { |
||
| 165 | $piece->url = getFullUrl('', 'mid', $current_module_info->mid); |
||
| 166 | } |
||
| 167 | } else { |
||
| 168 | if (!$is_index) { |
||
| 169 | $page = (Context::get('page') > 1) ? Context::get('page') : null; |
||
| 170 | $piece->url = getNotEncodedFullUrl('mid', $current_module_info->mid, 'page',$page); |
||
| 171 | } |
||
| 172 | } |
||
| 173 | |||
| 174 | $piece->title = $this->getBrowserTitle($piece->document_title); |
||
| 175 | |||
| 176 | if($oCacheHandler->isSupport()) { |
||
| 177 | $cache_key = 'seo:site_image'; |
||
| 178 | $site_image = $oCacheHandler->get($cache_key); |
||
| 179 | if($site_image) { |
||
| 180 | $site_image['url'] = $config->site_image_url; |
||
| 181 | } |
||
| 182 | $piece->image[] = $site_image; |
||
| 183 | } |
||
| 184 | |||
| 185 | $this->addLink('canonical', $piece->url); |
||
| 186 | $this->addMeta('keywords', $piece->keywords, 'name'); |
||
| 187 | $this->addMeta('description', $piece->description, 'name'); |
||
| 188 | |||
| 189 | // Open Graph |
||
| 190 | $this->addMeta('og:locale', $locales[Context::getLangType()]); |
||
| 191 | $this->addMeta('og:type', $piece->type); |
||
| 192 | $this->addMeta('og:url', $piece->url); |
||
| 193 | $this->addMeta('og:site_name', $config->site_name); |
||
| 194 | $this->addMeta('og:title', $piece->title); |
||
| 195 | $this->addMeta('og:description', $piece->description); |
||
| 196 | if($is_article) { |
||
| 197 | if(Context::getLangType() !== $oDocument->getLangCode()) { |
||
| 198 | $this->addMeta('og:locale:alternate', $locales[$oDocument->getLangCode()]); |
||
| 199 | } |
||
| 200 | $this->addMeta('article:published_time', $oDocument->getRegdate('c')); |
||
| 201 | $this->addMeta('article:modified_time', $oDocument->getUpdate('c')); |
||
| 202 | foreach ($piece->tags as $tag) { |
||
| 203 | $this->addMeta('article:tag', $tag); |
||
| 204 | } |
||
| 205 | } |
||
| 206 | |||
| 207 | foreach ($piece->image as $img) { |
||
| 208 | if(!$img['url']) { |
||
| 209 | if(!$img['filepath']) continue; |
||
| 210 | $img['url'] = $request_uri . $img['filepath']; |
||
| 211 | } |
||
| 212 | |||
| 213 | $this->addMeta('og:image', $img['url']); |
||
| 214 | $this->addMeta('og:image:width', $img['width']); |
||
| 215 | $this->addMeta('og:image:height', $img['height']); |
||
| 216 | if($single_image) break; |
||
| 217 | } |
||
| 218 | |||
| 219 | $this->canonical_url = $piece->url; |
||
| 220 | |||
| 221 | $this->applySEO(); |
||
| 222 | |||
| 223 | if ($config->use_optimize_title == 'Y') Context::setBrowserTitle($piece->title); |
||
| 224 | } |
||
| 225 | |||
| 256 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: