| Conditions | 35 | 
| Paths | > 20000 | 
| Total Lines | 175 | 
| Code Lines | 122 | 
| 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 | 		if ($document_srl) { | 
            ||
| 96 | 			$oDocument = Context::get('oDocument'); | 
            ||
| 97 | 			if (!is_a($oDocument, 'documentItem')) { | 
            ||
| 98 | 				$oDocumentModel = getModel('document'); | 
            ||
| 99 | $oDocument = $oDocumentModel->getDocument($document_srl);  | 
            ||
| 100 | }  | 
            ||
| 101 | |||
| 102 | 			if (is_a($oDocument, 'documentItem') && $document_srl == $oDocument->document_srl) { | 
            ||
| 103 | $is_article = true;  | 
            ||
| 104 | }  | 
            ||
| 105 | }  | 
            ||
| 106 | |||
| 107 | // 문서 데이터 수집  | 
            ||
| 108 | 		if ($is_article) { | 
            ||
| 109 | 			if (!$oDocument->isSecret()) { | 
            ||
| 110 | $piece->document_title = $oDocument->getTitleText();  | 
            ||
| 111 | 				$piece->url = getFullUrl('', 'mid', $current_module_info->mid, 'document_srl',$document_srl); | 
            ||
| 112 | $piece->type = 'article';  | 
            ||
| 113 | 				$piece->description = trim(str_replace(' ', ' ', $oDocument->getContentText(400))); | 
            ||
| 114 | $piece->author = $oDocument->getNickName();  | 
            ||
| 115 | 				$tags = $oDocument->get('tag_list'); | 
            ||
| 116 | if (count($tags)) $piece->tags = $tags;  | 
            ||
| 117 | |||
| 118 | $document_images = false;  | 
            ||
| 119 | 				if($oCacheHandler->isSupport()) { | 
            ||
| 120 | $cache_key_document_images = 'seo:document_images:' . $document_srl;  | 
            ||
| 121 | $document_images = $oCacheHandler->get($cache_key_document_images);  | 
            ||
| 122 | }  | 
            ||
| 123 | |||
| 124 | 				if($document_images === false && $oDocument->hasUploadedFiles()) { | 
            ||
| 125 | 					$image_ext = array('bmp', 'gif', 'jpg', 'jpeg', 'png'); | 
            ||
| 126 | $document_images = array();  | 
            ||
| 127 | |||
| 128 | 					foreach ($oDocument->getUploadedFiles() as $file) { | 
            ||
| 129 | if ($file->isvalid != 'Y') continue;  | 
            ||
| 130 | |||
| 131 | 						$ext = array_pop(explode('.', $file->uploaded_filename)); | 
            ||
| 132 | |||
| 133 | if (!in_array(strtolower($ext), $image_ext)) continue;  | 
            ||
| 134 | list($width, $height) = @getimagesize($file->uploaded_filename);  | 
            ||
| 135 | if($width < 100 && $height < 100) continue;  | 
            ||
| 136 | |||
| 137 | $image = array(  | 
            ||
| 138 | 'filepath' => $file->uploaded_filename,  | 
            ||
| 139 | 'width' => $width,  | 
            ||
| 140 | 'height' => $height  | 
            ||
| 141 | );  | 
            ||
| 142 | |||
| 143 | 						if($file->cover_image === 'Y') { | 
            ||
| 144 | array_unshift($document_images, $image);  | 
            ||
| 145 | 						} else { | 
            ||
| 146 | $document_images[] = $image;  | 
            ||
| 147 | }  | 
            ||
| 148 | }  | 
            ||
| 149 | |||
| 150 | 					if($oCacheHandler->isSupport()) { | 
            ||
| 151 | $oCacheHandler->put($cache_key_document_images, $document_images);  | 
            ||
| 152 | }  | 
            ||
| 153 | }  | 
            ||
| 154 | |||
| 155 | if($document_images) $piece->image = $document_images;  | 
            ||
| 156 | 			} else { | 
            ||
| 157 | 				$piece->url = getFullUrl('', 'mid', $current_module_info->mid); | 
            ||
| 158 | }  | 
            ||
| 159 | 		} else { | 
            ||
| 160 | 			if (!$is_index) { | 
            ||
| 161 | 				$page = (Context::get('page') > 1) ? Context::get('page') : null; | 
            ||
| 162 | 				$piece->url = getNotEncodedFullUrl('mid', $current_module_info->mid, 'page',$page); | 
            ||
| 163 | }  | 
            ||
| 164 | }  | 
            ||
| 165 | |||
| 166 | $piece->title = $this->getBrowserTitle($piece->document_title);  | 
            ||
| 167 | |||
| 168 | 		if($oCacheHandler->isSupport()) { | 
            ||
| 169 | $cache_key = 'seo:site_image';  | 
            ||
| 170 | $site_image = $oCacheHandler->get($cache_key);  | 
            ||
| 171 | 			if($site_image) { | 
            ||
| 172 | $site_image['url'] = $config->site_image_url;  | 
            ||
| 173 | }  | 
            ||
| 174 | $piece->image[] = $site_image;  | 
            ||
| 175 | }  | 
            ||
| 176 | |||
| 177 | 		$this->addLink('canonical', $piece->url); | 
            ||
| 178 | 		$this->addMeta('keywords', $piece->keywords, 'name'); | 
            ||
| 179 | 		$this->addMeta('description', $piece->description, 'name'); | 
            ||
| 180 | |||
| 181 | // Open Graph  | 
            ||
| 182 | 		$this->addMeta('og:locale', $locales[Context::getLangType()]); | 
            ||
| 183 | 		$this->addMeta('og:type', $piece->type); | 
            ||
| 184 | 		$this->addMeta('og:url', $piece->url); | 
            ||
| 185 | 		$this->addMeta('og:site_name', $config->site_name); | 
            ||
| 186 | 		$this->addMeta('og:title', $piece->title); | 
            ||
| 187 | 		$this->addMeta('og:description', $piece->description); | 
            ||
| 188 | 		if($is_article) { | 
            ||
| 189 | 			if(Context::getLangType() !== $oDocument->getLangCode()) { | 
            ||
| 190 | 				$this->addMeta('og:locale:alternate', $locales[$oDocument->getLangCode()]); | 
            ||
| 191 | }  | 
            ||
| 192 | 			$this->addMeta('article:published_time', $oDocument->getRegdate('c')); | 
            ||
| 193 | 			$this->addMeta('article:modified_time', $oDocument->getUpdate('c')); | 
            ||
| 194 | 			foreach ($piece->tags as $tag) { | 
            ||
| 195 | 				$this->addMeta('article:tag', $tag); | 
            ||
| 196 | }  | 
            ||
| 197 | }  | 
            ||
| 198 | |||
| 199 | 		foreach ($piece->image as $img) { | 
            ||
| 200 | 			if(!$img['url']) { | 
            ||
| 201 | if(!$img['filepath']) continue;  | 
            ||
| 202 | $img['url'] = $request_uri . $img['filepath'];  | 
            ||
| 203 | }  | 
            ||
| 204 | |||
| 205 | 			$this->addMeta('og:image', $img['url']); | 
            ||
| 206 | 			$this->addMeta('og:image:width', $img['width']); | 
            ||
| 207 | 			$this->addMeta('og:image:height', $img['height']); | 
            ||
| 208 | if($single_image) break;  | 
            ||
| 209 | }  | 
            ||
| 210 | |||
| 211 | $this->canonical_url = $piece->url;  | 
            ||
| 212 | |||
| 213 | $this->applySEO();  | 
            ||
| 214 | |||
| 215 | if ($config->use_optimize_title == 'Y') Context::setBrowserTitle($piece->title);  | 
            ||
| 216 | }  | 
            ||
| 217 | |||
| 248 | 
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: