| Conditions | 6 |
| Paths | 32 |
| Total Lines | 77 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 12 | public function allTests() |
||
| 13 | { |
||
| 14 | /* $_GET */ |
||
| 15 | if (self::chkGet("q")) { |
||
| 16 | echo '$_GET["q"] is set'; |
||
| 17 | } |
||
| 18 | |||
| 19 | echo self::assignFromGet("q"); // "" or $_GET["q"] |
||
| 20 | |||
| 21 | if (self::chkGetAll(array("q", "search"))) { |
||
| 22 | echo '$_GET["q"] and $_GET["search"] is set'; |
||
| 23 | } |
||
| 24 | |||
| 25 | /* $_POST */ |
||
| 26 | if (self::chkPost("q")) { |
||
| 27 | echo '$_POST["q"] is set'; |
||
| 28 | } |
||
| 29 | |||
| 30 | echo self::assignFromPost("q"); // "" or $_POST["q"] |
||
| 31 | |||
| 32 | if (self::chkPostAll(array("q", "search"))) { |
||
| 33 | echo '$_POST["q"] and $_POST["search"] is set'; |
||
| 34 | } |
||
| 35 | |||
| 36 | /* Sessions */ |
||
| 37 | self::sessionSet("example_session_name", "content of session", 86400); |
||
| 38 | |||
| 39 | if (self::sessionIsset("example_session_name")) { |
||
| 40 | echo 'Session example_session_name is set and not expired'; |
||
| 41 | } |
||
| 42 | |||
| 43 | echo self::sessionRead("example_session_name"); // content of session |
||
| 44 | |||
| 45 | self::sessionDelete("example_session_name"); // Deletes session |
||
| 46 | |||
| 47 | /* Time */ |
||
| 48 | echo self::timestampToHttpDate("1980-01-01 17:15:00"); // Tue, 01 Jan 1980 16:15:00 GMT |
||
| 49 | |||
| 50 | echo self::timeElapsed("1980-01-01 17:15:00"); // 13173 days |
||
| 51 | |||
| 52 | /* Browser */ |
||
| 53 | echo self::getClientIpAddress(); // 127.0.0.1 |
||
| 54 | |||
| 55 | echo self::getClientOperatingSystem(); // linux |
||
| 56 | |||
| 57 | echo self::getClientBrowser(); // Firefox |
||
| 58 | |||
| 59 | /* Convert */ |
||
| 60 | echo self::rgbhex(array(255, 0, 0)); // ff0000 |
||
| 61 | |||
| 62 | print_r(self::hexrgb("#FF0000")); // Array([0] => 255, [1] => 0, [2] => 0) |
||
| 63 | |||
| 64 | /* Strings */ |
||
| 65 | echo self::textareaEncode('<textarea id="tex1"></textarea> <p> asdasd </p>'); // [textarea id="tex1"][/textarea] <p> asdasd </p> |
||
| 66 | |||
| 67 | echo self::textareaDecode('[textarea id="tex1"][/textarea] <p> asdasd </p>'); // <textarea id="tex1"></textarea> <p> asdasd </p> |
||
| 68 | |||
| 69 | echo self::obfuscateString("Hi, I'm a ninja!"); // 49574671626d6c75494745676253644a4943787053413d3d |
||
| 70 | |||
| 71 | echo self::deobfuscateString("49574671626d6c75494745676253644a4943787053413d3d"); // Hi, I'm a ninja! |
||
| 72 | |||
| 73 | echo self::replaceString("Hi my name is [@foo] and i like [@bar]", array("foo" => "sven", "bar" => "beer")); // Hi my name is sven and i like beer |
||
| 74 | |||
| 75 | echo self::rainbowText("Hallo world"); // <span style="color: #ff0000;">H</span><span style="color: #ff3300;">a</span>... |
||
| 76 | |||
| 77 | echo self::kbdSymbol("enter"); // ⏎ |
||
| 78 | |||
| 79 | echo self::kbdShortcut(array("Ctrl", "Alt", "Delete"), "auto"); // <kbd class="holt45-kbd"><span class="holt45-kbd__symbol">✲</span>Ctrl</kbd> + <kbd class="holt45-kbd"><span class="holt45-kbd__symbol">⎇</span>Alt</kbd> + <kbd class="holt45-kbd"><span class="holt45-kbd__symbol">⌫</span>Delete</kbd> |
||
| 80 | |||
| 81 | /* Math */ |
||
| 82 | print_r(self::generatePaginationRange(106, 15, 7)); // Array([0] => 1, [1] => 13, [2] => 14, [3] => 15, [4] => 16, [5] => 17, [6] => 106) |
||
| 83 | |||
| 84 | /* Misc */ |
||
| 85 | print_r(self::urlParser("htt://w.google..com/")); // Array([url] => http://www.google.com/, [url_display] => www.google.com) |
||
| 86 | |||
| 87 | echo self::generatePassword(10); // 2k%=cbot:w |
||
| 88 | |||
| 89 | echo self::generatePassword(10, "simple"); // m9b7gfkmhc |
||
| 99 |