Conditions | 12 |
Paths | 128 |
Total Lines | 60 |
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 |
||
41 | public function handle() |
||
42 | { |
||
43 | |||
44 | /* ⣠⣾⣿⣿⣷⣄ Simple PHP Wiki Info Box ⣠⣾⣿⣿⣷⣄ */ |
||
45 | /* https://github.com/gaffling/PHP-Wiki-API */ |
||
46 | // Get the Parameter from the URL |
||
47 | if (isset($_GET['language']) ) { |
||
48 | $language = $_GET['language']; |
||
49 | } else { |
||
50 | $language = 'de'; |
||
51 | } |
||
52 | if (isset($_GET['userAgent']) ) { |
||
53 | $userAgent = $_GET['userAgent']; |
||
54 | } else { |
||
55 | $userAgent = 'WikiBot/1.0 (+http://'.$_SERVER['SERVER_NAME'].'/)'; |
||
56 | } |
||
57 | if (isset($_GET['betterResults']) |
||
58 | and ($_GET['betterResults'] == 'false' or $_GET['betterResults'] == 0) |
||
59 | ) { |
||
60 | $betterResults = false; |
||
61 | } else { |
||
62 | $betterResults = true; |
||
63 | } |
||
64 | if (isset($_GET['proxy']) ) { |
||
65 | $proxy = $_GET['proxy']; |
||
66 | } else { |
||
67 | $proxy = null; |
||
68 | } |
||
69 | if (isset($_GET['imageProxy']) |
||
70 | and ($_GET['imageProxy'] == 'false' or $_GET['imageProxy']== 0) |
||
71 | ) { |
||
72 | $imageProxy = false; |
||
73 | } else { |
||
74 | $imageProxy = true; |
||
75 | } |
||
76 | if (isset($_GET['DEBUG']) ) { |
||
77 | $DEBUG = $_GET['DEBUG']; |
||
78 | } else { |
||
79 | $DEBUG = null; |
||
80 | } |
||
81 | // Set the Parameter |
||
82 | $options = array( |
||
83 | 'language' => $language, |
||
84 | 'userAgent' => $userAgent, |
||
85 | 'betterResults' => $betterResults, |
||
86 | 'proxy' => $proxy, |
||
87 | 'imageProxy' => $imageProxy, |
||
88 | 'DEBUG' => $DEBUG, |
||
89 | ); |
||
90 | // Include the Wikipedia API Class |
||
91 | include_once __DIR__.'/wiki2api.php'; |
||
92 | // Start the Wikipedia API Class |
||
93 | $wiki = new wiki($options); |
||
94 | // Output the API Response |
||
95 | echo $wiki->api($_GET['q']); |
||
96 | // Print the Script Runtime in DEBUG Mode |
||
97 | if (isset($DEBUG) ) { |
||
98 | echo "<pre>\n\n\tRuntime: ".number_format((microtime(true)-$_SERVER['REQUEST_TIME_FLOAT']), 3); |
||
99 | } |
||
100 | } |
||
101 | |||
108 |