Conditions | 13 |
Paths | 385 |
Total Lines | 122 |
Code Lines | 69 |
Lines | 0 |
Ratio | 0 % |
Changes | 14 | ||
Bugs | 2 | Features | 4 |
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 |
||
60 | public function handle_tpl_metaheader_output(Doku_Event $event, $param) { |
||
61 | global $ID, $conf, $INFO; |
||
62 | |||
63 | if (!page_exists($ID)) { return; } |
||
64 | |||
65 | // twitter card, see https://dev.twitter.com/cards/markup |
||
66 | // creat a summary card, see https://dev.twitter.com/cards/types/summary |
||
67 | $event->data['meta'][] = array('name' => 'twitter:card', |
||
68 | 'content' => "summary",); |
||
69 | |||
70 | $event->data['meta'][] = array('name' => 'twitter:site', |
||
71 | 'content' => $this->getConf('twitterName'),); |
||
72 | |||
73 | $event->data['meta'][] = array('name' => 'twitter:title', |
||
74 | 'content' => p_get_metadata($ID, 'title', true),); |
||
75 | |||
76 | $desc = p_get_metadata($ID, 'description', true); |
||
77 | if (!empty($desc)) { |
||
78 | $desc = str_replace("\n", " ", $desc['abstract']); |
||
79 | $event->data['meta'][] = array('name' => 'twitter:description', |
||
80 | 'content' => $desc,); |
||
81 | } |
||
82 | |||
83 | if ($this->getConf('twitterUserName') != '') { |
||
84 | $event->data['meta'][] = array('name' => 'twitter:creator', |
||
85 | 'content' => $this->getConf('twitterUserName'),); |
||
86 | } |
||
87 | |||
88 | $event->data['meta'][] = array('name' => 'twitter:image', |
||
89 | 'content' => $this->getImage(),); |
||
90 | $event->data['meta'][] = array('name' => 'twitter:image:alt', |
||
91 | 'content' => $this->getImageAlt(),); |
||
92 | |||
93 | // opengraph, see http://ogp.me/ |
||
94 | // |
||
95 | // to make this work properly the template should be modified adding the |
||
96 | // namespaces for a (x)html 4 template make html tag: |
||
97 | // |
||
98 | // <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="nl" lang="nl" |
||
99 | // xmlns:og="http://ogp.me/ns#" xmlns:fb="http://ogp.me/ns/fb#" |
||
100 | // xmlns:article="http://ogp.me/ns/article#" xmlns:place="http://ogp.me/ns/place#"> |
||
101 | // |
||
102 | // and for a (x)html 5 template make head tag: |
||
103 | // |
||
104 | // <head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# article: http://ogp.me/ns/article# place: http://ogp.me/ns/place#"> |
||
105 | |||
106 | // og namespace http://ogp.me/ns# |
||
107 | $event->data['meta'][] = array('property' => 'og:locale', |
||
108 | 'content' => $this->getConf('languageTerritory'),); |
||
109 | $event->data['meta'][] = array('property' => 'og:site_name', |
||
110 | 'content' => $conf['title'],); |
||
111 | $event->data['meta'][] = array('property' => 'og:url', |
||
112 | 'content' => wl($ID, '', true),); |
||
113 | $event->data['meta'][] = array('property' => 'og:title', |
||
114 | 'content' => p_get_metadata($ID, 'title', true),); |
||
115 | if (!empty($desc)) { |
||
116 | $event->data['meta'][] = array('property' => 'og:description', |
||
117 | 'content' => $desc,); |
||
118 | } |
||
119 | $event->data['meta'][] = array('property' => 'og:type', |
||
120 | 'content' => "article",); |
||
121 | $ogImage = $this->getImage(); |
||
122 | $secure = substr($ogImage, 0, 5) === 'https' ? ':secure_url' : ''; |
||
123 | $event->data['meta'][] = array('property' => 'og:image' . $secure, |
||
124 | 'content' => $ogImage,); |
||
125 | |||
126 | // article namespace http://ogp.me/ns/article# |
||
127 | $_dates = p_get_metadata($ID, 'date', true); |
||
128 | $event->data['meta'][] = array('property' => 'article:published_time', |
||
129 | 'content' => dformat($_dates['created']),); |
||
130 | $event->data['meta'][] = array('property' => 'article:modified_time', |
||
131 | 'content' => dformat($_dates['modified']),); |
||
132 | $event->data['meta'][] = array('property' => 'article:author', |
||
133 | 'content' => $INFO['editor'],); |
||
134 | // $event->data['meta'][] = array('property' => 'article:author','content' => p_get_metadata($ID,'creator',true),); |
||
1 ignored issue
–
show
|
|||
135 | // $event->data['meta'][] = array('property' => 'article:author','content' => p_get_metadata($ID,'user',true),); |
||
1 ignored issue
–
show
|
|||
136 | $_subject = p_get_metadata($ID, 'subject', true); |
||
137 | if (!empty($_subject)) { |
||
138 | if (!is_array($_subject)) { |
||
139 | $_subject = array($_subject); |
||
140 | } |
||
141 | foreach ($_subject as $tag) { |
||
142 | $event->data['meta'][] = array('property' => 'article:tag', |
||
143 | 'content' => $tag,); |
||
144 | } |
||
145 | } |
||
146 | |||
147 | // place namespace http://ogp.me/ns/place# |
||
148 | $geotags = p_get_metadata($ID, 'geo', true); |
||
149 | $lat = $geotags['lat']; |
||
150 | $lon = $geotags['lon']; |
||
151 | if (!(empty($lat) && empty($lon))) { |
||
152 | $event->data['meta'][] = array('property' => 'place:location:latitude', |
||
153 | 'content' => $lat,); |
||
154 | $event->data['meta'][] = array('property' => 'place:location:longitude', |
||
155 | 'content' => $lon,); |
||
156 | } |
||
157 | // see https://developers.facebook.com/docs/opengraph/property-types/#geopoint |
||
158 | $alt = $geotags['alt']; |
||
159 | if (!empty($alt)) { |
||
160 | // facebook expects feet... |
||
161 | $alt = $alt * 3.2808; |
||
162 | $event->data['meta'][] = array('property' => 'place:location:altitude', |
||
163 | 'content' => $alt,); |
||
164 | } |
||
165 | |||
166 | /* these are not valid for the GeoPoint type.. |
||
1 ignored issue
–
show
|
|||
167 | $region=$geotags['region']; |
||
168 | $country=$geotags['country']; |
||
169 | $placename=$geotags['placename']; |
||
170 | if (!empty($region)) {$event->data['meta'][] = array('property' => 'place:location:region', 'content' => $region,);} |
||
171 | if (!empty($placename)) {$event->data['meta'][] = array('property' => 'place:location:locality', 'content' => $placename,);} |
||
172 | if (!empty($country)) {$event->data['meta'][] = array('property' => 'place:location:country-name','content' => $country,);} |
||
173 | */ |
||
174 | |||
175 | // optional facebook app ID |
||
176 | $appId = $this->getConf('fbAppId'); |
||
177 | if (!empty($appId)) { |
||
178 | $event->data['meta'][] = array('property' => 'fb:app_id', |
||
179 | 'content' => $appId,); |
||
180 | } |
||
181 | } |
||
182 | |||
234 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.