Complex classes like SocialIntegrationControllerBaseClass often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use SocialIntegrationControllerBaseClass, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
4 | abstract class SocialIntegrationControllerBaseClass extends Controller |
||
|
|||
5 | { |
||
6 | |||
7 | /** |
||
8 | * default profile pic in case none is available |
||
9 | * @var String |
||
10 | */ |
||
11 | private static $default_avatar = "http://placeholder.it/32x32"; |
||
12 | public static function get_default_avatar() |
||
20 | |||
21 | /** |
||
22 | * tells us if a class is a Social Integration API class (e.g. Facebook, Twiiter, etc....) |
||
23 | * @param String $className |
||
24 | * @return Boolean |
||
25 | */ |
||
26 | public static function is_social_integration_api_class($className) |
||
36 | |||
37 | |||
38 | /** |
||
39 | * one stop shop button |
||
40 | * @return Object ( |
||
41 | * IsConnected, |
||
42 | * IsLoggedIn, |
||
43 | * Link, |
||
44 | * ConnectedName, |
||
45 | * ConnectedImageURL |
||
46 | * ) |
||
47 | */ |
||
48 | public static function get_login_button($backURL = "", $member) |
||
110 | |||
111 | |||
112 | /** |
||
113 | * @param String $returnURL |
||
114 | * @return String |
||
115 | */ |
||
116 | public static function login_url($returnURL = "") |
||
124 | |||
125 | /** |
||
126 | * Link to login form |
||
127 | * @param String $returnURL |
||
128 | * @return String |
||
129 | */ |
||
130 | public static function connect_url($returnURL = "", $existingMember = false) |
||
140 | |||
141 | |||
142 | /** |
||
143 | * redirects to login prompt, lets the user log in and returns to |
||
144 | * the returnURL specified. |
||
145 | * @param String $returnURL |
||
146 | * @return REDIRECTS! |
||
147 | */ |
||
148 | public static function redirect_to_login_prompt($returnURL = "") |
||
153 | |||
154 | /** |
||
155 | * The class being called |
||
156 | * (e.g. FacebookCallback::my_class_name should return FacebookCallback) |
||
157 | * @return String |
||
158 | */ |
||
159 | protected static function my_class_name() |
||
163 | |||
164 | /** |
||
165 | * The current ClassName without the "Callback" portion. |
||
166 | * @return String |
||
167 | */ |
||
168 | protected static function my_service_name() |
||
172 | |||
173 | /** |
||
174 | * The name of the security form. |
||
175 | * @return String |
||
176 | */ |
||
177 | protected function my_security_form() |
||
181 | |||
182 | /** |
||
183 | * returns Absolute URL to a link within this controller, |
||
184 | * by default it is the "Connect" link, because this controller |
||
185 | * always needs an action. |
||
186 | * @return String |
||
187 | */ |
||
188 | public function Title() |
||
192 | |||
193 | /** |
||
194 | * returns Absolute URL to a link within this controller, |
||
195 | * by default it is the "Connect" link, because this controller |
||
196 | * always needs an action. |
||
197 | * @return String |
||
198 | */ |
||
199 | public function AbsoluteLink($action = "") |
||
206 | |||
207 | /** |
||
208 | * returns relative URL to a link within this controller, |
||
209 | * by default it is the "Connect" link, because this controller |
||
210 | * always needs an action. |
||
211 | * @return String |
||
212 | */ |
||
213 | public function Link($action = "") |
||
221 | |||
222 | public static function is_valid_user($screen_name) |
||
226 | |||
227 | |||
228 | //========================================== HELPER METHODS ===================================== |
||
229 | |||
230 | public function __construct() |
||
234 | |||
235 | /** |
||
236 | * you need to add an action |
||
237 | */ |
||
238 | public function index() |
||
246 | |||
247 | /** |
||
248 | * works out best Return URL |
||
249 | * @param Boolean $hasAbsoluteBaseURL - should it include the Base URL (e.g. http://www.mysite.com) |
||
250 | * @return String |
||
251 | */ |
||
252 | protected function returnURL($hasAbsoluteBaseURL = false) |
||
268 | |||
269 | public function Tests() |
||
299 | |||
300 | |||
301 | public function menondatabase() |
||
305 | |||
306 | public function test($request) |
||
385 | } |
||
386 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.