Conditions | 13 |
Paths | 12 |
Total Lines | 52 |
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 |
||
80 | protected function applySEO() |
||
81 | { |
||
82 | $config = $this->getConfig(); |
||
83 | $logged_info = Context::get('logged_info'); |
||
84 | |||
85 | foreach ($this->SEO as $type => $list) { |
||
86 | if (!$list || !count($list)) continue; |
||
87 | |||
88 | foreach ($list as $val) { |
||
89 | if ($type == 'meta') { |
||
90 | $attr_name = $val['attr_name']; |
||
91 | Context::addHtmlHeader('<meta ' . $attr_name . '="' . $val['property'] . '" content="' . $val['content'] . '" />'); |
||
92 | } elseif ($type == 'link') { |
||
93 | Context::addHtmlHeader('<link rel="' . $val['rel'] . '" href="' . $val['href'] . '" />'); |
||
94 | } |
||
95 | } |
||
96 | } |
||
97 | |||
98 | // Google Analytics |
||
99 | if ($config->ga_id && !($config->ga_except_admin == 'Y' && $logged_info->is_admin == 'Y')) { |
||
100 | $gaq_push = array(); |
||
101 | // $gaq_push[] = '_gaq.push([\'_setAccount\', \'' . $config->ga_id . '\']);'; |
||
102 | $gaq_push[] = "ga('create', '{$config->ga_id}', 'auto');"; |
||
103 | $canonical_url = str_replace(Context::get('request_uri'), '/', $this->canonical_url); |
||
104 | $gaq_push[] = "ga('send', 'pageview', '{$canonical_url}');"; |
||
105 | $gaq_push = implode(PHP_EOL, $gaq_push); |
||
106 | |||
107 | $ga_script = <<< GASCRIPT |
||
108 | <!-- Google Analytics --> |
||
109 | <script> |
||
110 | (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ |
||
111 | (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), |
||
112 | m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) |
||
113 | })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); |
||
114 | |||
115 | {$gaq_push} |
||
116 | </script> |
||
117 | GASCRIPT; |
||
118 | |||
119 | Context::addHtmlHeader($ga_script . PHP_EOL); |
||
120 | } |
||
121 | |||
122 | // Naver Analytics |
||
123 | if ($config->na_id && !($config->na_except_admin == 'Y' && $logged_info->is_admin == 'Y')) { |
||
124 | $na_script = <<< NASCRIPT |
||
125 | <!-- NAVER Analytics --> |
||
126 | <script src="//wcs.naver.net/wcslog.js"></script> |
||
127 | <script>if(!wcs_add){var wcs_add={};};wcs_add['wa']='{$config->na_id}';if(typeof wcs_do!="undefined"){wcs_do();}</script> |
||
128 | NASCRIPT; |
||
129 | Context::addHtmlFooter($na_script . PHP_EOL); |
||
130 | } |
||
131 | } |
||
132 | |||
188 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.