Conditions | 16 |
Paths | 9 |
Total Lines | 65 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 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 |
||
34 | public static function get_all_repos_no_oauth($username = '', $getNamesWithPrefix = false) |
||
35 | { |
||
36 | $preSelected = Config::inst()->get('UpdateModules', 'modules_to_update'); |
||
37 | if (is_array($preSelected) && count($preSelected)) { |
||
38 | return $preSelected; |
||
39 | } else { |
||
40 | if (!$username) { |
||
41 | $username = Config::inst()->get('GitHubModule', "github_user_name"); |
||
42 | } |
||
43 | print "<li>Retrieving List of modules from GitHub for user $username ... </li>"; |
||
44 | if (! count(self::$_modules)) { |
||
|
|||
45 | for ($page = 0; $page < 10; $page++) { |
||
46 | $ch = curl_init(); |
||
47 | curl_setopt($ch, CURLOPT_URL, "https://api.github.com/users/".$username."/repos?per_page=100&page=$page"); |
||
48 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
||
49 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, true); |
||
50 | curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); |
||
51 | |||
52 | |||
53 | $string = curl_exec($ch); |
||
54 | // close curl resource to free up system resources |
||
55 | curl_close($ch); |
||
56 | $array = json_decode($string, true); |
||
57 | $count = count($array); |
||
58 | if ($count > 0) { |
||
59 | foreach ($array as $repo) { |
||
60 | //dont bother about forks |
||
61 | if (isset($repo["fork"]) && !$repo["fork"]) { |
||
62 | //make sure we are the owners |
||
63 | if ($repo["owner"]["login"] == $username) { |
||
64 | $isSSModule = (stripos($repo["name"], 'silverstripe-') !== false); |
||
65 | //check it is silverstripe module |
||
66 | if (!$getNamesWithPrefix) { |
||
67 | $name = $repo["name"]; |
||
68 | } else { |
||
69 | $name = preg_replace('/silverstripe/', "", $repo["name"], $limit = 1); |
||
70 | } |
||
71 | |||
72 | //if(strlen($name) < strlen($repo["name"])) { |
||
73 | if ($isSSModule) { |
||
74 | //is it listed yet? |
||
75 | if (!in_array($name, self::$_modules)) { |
||
76 | self::$_modules[] = $name; |
||
77 | } |
||
78 | } else { |
||
79 | DB::alteration_message("skipping ".$repo["name"]." as it does not appear to me a silverstripe module, you can add it manually to this task, using the configs ... "); |
||
80 | } |
||
81 | } else { |
||
82 | DB::alteration_message("skipping ".$repo["name"]." as it has a different owner"); |
||
83 | } |
||
84 | } elseif (isset($repo["name"])) { |
||
85 | DB::alteration_message("skipping ".$repo["name"]." as it is a fork"); |
||
86 | } |
||
87 | } |
||
88 | } else { |
||
89 | $page = 11; |
||
90 | } |
||
91 | } |
||
92 | } |
||
93 | print "<li>Found ".count(self::$_modules)." modules on GitHub ... </li>"; |
||
94 | if (count(self::$_modules)==0) { |
||
95 | user_error("No modules found on GitHub. This is possibly because the limit of 60 requests an hour has been exceeded."); |
||
96 | } |
||
97 | } |
||
98 | return self::$_modules; |
||
99 | } |
||
218 |