Conditions | 18 |
Paths | 26 |
Total Lines | 62 |
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 |
||
93 | public function TwitterFeed($username, $count = 5) |
||
94 | { |
||
95 | if (!$username) { |
||
96 | user_error("No username provided"); |
||
97 | } |
||
98 | Config::inst()->update(MyTwitterData::class, "username", $username); |
||
99 | //check settings are available |
||
100 | $requiredSettings = array("twitter_consumer_key", "twitter_consumer_secret", "titter_oauth_token", "titter_oauth_token"); |
||
101 | foreach ($requiredSettings as $setting) { |
||
102 | if (!Config::inst()->get(MyTwitter::class, $setting)) { |
||
103 | user_error(" you must set MyTwitter::$setting", E_USER_NOTICE); |
||
104 | return null; |
||
105 | } |
||
106 | } |
||
107 | require_once(Director::baseFolder().'/'.SS_SHARETHIS_DIR.'/third_party/twitter_oauth/TwitterOAuthConsumer.php'); |
||
108 | $connection = new TwitterOAuth( |
||
109 | Config::inst()->get(MyTwitter::class, "twitter_consumer_key"), |
||
110 | Config::inst()->get(MyTwitter::class, "twitter_consumer_secret"), |
||
111 | Config::inst()->get(MyTwitter::class, "titter_oauth_token"), |
||
112 | Config::inst()->get(MyTwitter::class, "titter_oauth_token_secret") |
||
113 | ); |
||
114 | $config = Config::inst()->get(MyTwitter::class, "twitter_config"); |
||
115 | $config['screen_name'] = $username; |
||
116 | $tweets = $connection->get('statuses/user_timeline', $config); |
||
117 | $tweetList = new ArrayList(); |
||
118 | if (count($tweets) > 0 && !isset($tweets->error)) { |
||
119 | $i = 0; |
||
120 | foreach ($tweets as $tweet) { |
||
121 | if (Config::inst()->get(MyTwitter::class, "favourites_only") && $tweet->favorite_count == 0) { |
||
122 | break; |
||
123 | } |
||
124 | if (Config::inst()->get(MyTwitter::class, "non_replies_only") && $tweet->in_reply_to_status_id) { |
||
125 | break; |
||
126 | } |
||
127 | if (Config::inst()->get(MyTwitter::class, "debug")) { |
||
128 | print_r($tweet); |
||
129 | } |
||
130 | if (++$i > $count) { |
||
131 | break; |
||
132 | } |
||
133 | |||
134 | $date = new DBDatetime(); |
||
135 | $date->setValue(strtotime($tweet->created_at)); |
||
136 | $text = htmlentities($tweet->text, ENT_NOQUOTES, $encoding = "UTF-8", $doubleEncode = false); |
||
137 | if (!empty($tweet->entities) && !empty($tweet->entities->urls)) { |
||
138 | foreach ($tweet->entities->urls as $url) { |
||
139 | if (!empty($url->url) && !empty($url->display_url)) { |
||
140 | $text = str_replace($url->url, '<a href="'.$url->url.'" class="external">'.$url->display_url.'</a>', $text); |
||
141 | } |
||
142 | } |
||
143 | } |
||
144 | $tweetList->push( |
||
145 | new ArrayData(array( |
||
146 | 'ID' => $tweet->id_str, |
||
147 | 'Title' => $text, |
||
148 | 'Date' => $date |
||
149 | )) |
||
150 | ); |
||
151 | } |
||
152 | } |
||
153 | return $tweetList; |
||
154 | } |
||
155 | } |
||
156 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.