Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like WebRequest 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 WebRequest, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 35 | class WebRequest { |
||
| 36 | protected $data, $headers = []; |
||
|
|
|||
| 37 | |||
| 38 | /** |
||
| 39 | * Flag to make WebRequest::getHeader return an array of values. |
||
| 40 | * @since 1.26 |
||
| 41 | */ |
||
| 42 | const GETHEADER_LIST = 1; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Lazy-init response object |
||
| 46 | * @var WebResponse |
||
| 47 | */ |
||
| 48 | private $response; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Cached client IP address |
||
| 52 | * @var string |
||
| 53 | */ |
||
| 54 | private $ip; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * The timestamp of the start of the request, with microsecond precision. |
||
| 58 | * @var float |
||
| 59 | */ |
||
| 60 | protected $requestTime; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Cached URL protocol |
||
| 64 | * @var string |
||
| 65 | */ |
||
| 66 | protected $protocol; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @var \\MediaWiki\\Session\\SessionId|null Session ID to use for this |
||
| 70 | * request. We can't save the session directly due to reference cycles not |
||
| 71 | * working too well (slow GC in Zend and never collected in HHVM). |
||
| 72 | */ |
||
| 73 | protected $sessionId = null; |
||
| 74 | |||
| 75 | public function __construct() { |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Extract relevant query arguments from the http request uri's path |
||
| 86 | * to be merged with the normal php provided query arguments. |
||
| 87 | * Tries to use the REQUEST_URI data if available and parses it |
||
| 88 | * according to the wiki's configuration looking for any known pattern. |
||
| 89 | * |
||
| 90 | * If the REQUEST_URI is not provided we'll fall back on the PATH_INFO |
||
| 91 | * provided by the server if any and use that to set a 'title' parameter. |
||
| 92 | * |
||
| 93 | * @param string $want If this is not 'all', then the function |
||
| 94 | * will return an empty array if it determines that the URL is |
||
| 95 | * inside a rewrite path. |
||
| 96 | * |
||
| 97 | * @return array Any query arguments found in path matches. |
||
| 98 | */ |
||
| 99 | public static function getPathInfo( $want = 'all' ) { |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Work out an appropriate URL prefix containing scheme and host, based on |
||
| 178 | * information detected from $_SERVER |
||
| 179 | * |
||
| 180 | * @return string |
||
| 181 | */ |
||
| 182 | public static function detectServer() { |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Detect the protocol from $_SERVER. |
||
| 223 | * This is for use prior to Setup.php, when no WebRequest object is available. |
||
| 224 | * At other times, use the non-static function getProtocol(). |
||
| 225 | * |
||
| 226 | * @return array |
||
| 227 | */ |
||
| 228 | public static function detectProtocol() { |
||
| 237 | |||
| 238 | /** |
||
| 239 | * Get the number of seconds to have elapsed since request start, |
||
| 240 | * in fractional seconds, with microsecond resolution. |
||
| 241 | * |
||
| 242 | * @return float |
||
| 243 | * @since 1.25 |
||
| 244 | */ |
||
| 245 | public function getElapsedTime() { |
||
| 248 | |||
| 249 | /** |
||
| 250 | * Get the current URL protocol (http or https) |
||
| 251 | * @return string |
||
| 252 | */ |
||
| 253 | public function getProtocol() { |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Check for title, action, and/or variant data in the URL |
||
| 262 | * and interpolate it into the GET variables. |
||
| 263 | * This should only be run after $wgContLang is available, |
||
| 264 | * as we may need the list of language variants to determine |
||
| 265 | * available variant URLs. |
||
| 266 | */ |
||
| 267 | public function interpolateTitle() { |
||
| 278 | |||
| 279 | /** |
||
| 280 | * URL rewriting function; tries to extract page title and, |
||
| 281 | * optionally, one other fixed parameter value from a URL path. |
||
| 282 | * |
||
| 283 | * @param string $path The URL path given from the client |
||
| 284 | * @param array $bases One or more URLs, optionally with $1 at the end |
||
| 285 | * @param string $key If provided, the matching key in $bases will be |
||
| 286 | * passed on as the value of this URL parameter |
||
| 287 | * @return array Array of URL variables to interpolate; empty if no match |
||
| 288 | */ |
||
| 289 | static function extractTitle( $path, $bases, $key = false ) { |
||
| 307 | |||
| 308 | /** |
||
| 309 | * Recursively normalizes UTF-8 strings in the given array. |
||
| 310 | * |
||
| 311 | * @param string|array $data |
||
| 312 | * @return array|string Cleaned-up version of the given |
||
| 313 | * @private |
||
| 314 | */ |
||
| 315 | function normalizeUnicode( $data ) { |
||
| 328 | |||
| 329 | /** |
||
| 330 | * Fetch a value from the given array or return $default if it's not set. |
||
| 331 | * |
||
| 332 | * @param array $arr |
||
| 333 | * @param string $name |
||
| 334 | * @param mixed $default |
||
| 335 | * @return mixed |
||
| 336 | */ |
||
| 337 | private function getGPCVal( $arr, $name, $default ) { |
||
| 357 | |||
| 358 | /** |
||
| 359 | * Fetch a scalar from the input or return $default if it's not set. |
||
| 360 | * Returns a string. Arrays are discarded. Useful for |
||
| 361 | * non-freeform text inputs (e.g. predefined internal text keys |
||
| 362 | * selected by a drop-down menu). For freeform input, see getText(). |
||
| 363 | * |
||
| 364 | * @param string $name |
||
| 365 | * @param string $default Optional default (or null) |
||
| 366 | * @return string |
||
| 367 | */ |
||
| 368 | public function getVal( $name, $default = null ) { |
||
| 379 | |||
| 380 | /** |
||
| 381 | * Set an arbitrary value into our get/post data. |
||
| 382 | * |
||
| 383 | * @param string $key Key name to use |
||
| 384 | * @param mixed $value Value to set |
||
| 385 | * @return mixed Old value if one was present, null otherwise |
||
| 386 | */ |
||
| 387 | public function setVal( $key, $value ) { |
||
| 392 | |||
| 393 | /** |
||
| 394 | * Unset an arbitrary value from our get/post data. |
||
| 395 | * |
||
| 396 | * @param string $key Key name to use |
||
| 397 | * @return mixed Old value if one was present, null otherwise |
||
| 398 | */ |
||
| 399 | public function unsetVal( $key ) { |
||
| 408 | |||
| 409 | /** |
||
| 410 | * Fetch an array from the input or return $default if it's not set. |
||
| 411 | * If source was scalar, will return an array with a single element. |
||
| 412 | * If no source and no default, returns null. |
||
| 413 | * |
||
| 414 | * @param string $name |
||
| 415 | * @param array $default Optional default (or null) |
||
| 416 | * @return array |
||
| 417 | */ |
||
| 418 | public function getArray( $name, $default = null ) { |
||
| 426 | |||
| 427 | /** |
||
| 428 | * Fetch an array of integers, or return $default if it's not set. |
||
| 429 | * If source was scalar, will return an array with a single element. |
||
| 430 | * If no source and no default, returns null. |
||
| 431 | * If an array is returned, contents are guaranteed to be integers. |
||
| 432 | * |
||
| 433 | * @param string $name |
||
| 434 | * @param array $default Option default (or null) |
||
| 435 | * @return array Array of ints |
||
| 436 | */ |
||
| 437 | public function getIntArray( $name, $default = null ) { |
||
| 444 | |||
| 445 | /** |
||
| 446 | * Fetch an integer value from the input or return $default if not set. |
||
| 447 | * Guaranteed to return an integer; non-numeric input will typically |
||
| 448 | * return 0. |
||
| 449 | * |
||
| 450 | * @param string $name |
||
| 451 | * @param int $default |
||
| 452 | * @return int |
||
| 453 | */ |
||
| 454 | public function getInt( $name, $default = 0 ) { |
||
| 457 | |||
| 458 | /** |
||
| 459 | * Fetch an integer value from the input or return null if empty. |
||
| 460 | * Guaranteed to return an integer or null; non-numeric input will |
||
| 461 | * typically return null. |
||
| 462 | * |
||
| 463 | * @param string $name |
||
| 464 | * @return int|null |
||
| 465 | */ |
||
| 466 | public function getIntOrNull( $name ) { |
||
| 472 | |||
| 473 | /** |
||
| 474 | * Fetch a floating point value from the input or return $default if not set. |
||
| 475 | * Guaranteed to return a float; non-numeric input will typically |
||
| 476 | * return 0. |
||
| 477 | * |
||
| 478 | * @since 1.23 |
||
| 479 | * @param string $name |
||
| 480 | * @param float $default |
||
| 481 | * @return float |
||
| 482 | */ |
||
| 483 | public function getFloat( $name, $default = 0.0 ) { |
||
| 486 | |||
| 487 | /** |
||
| 488 | * Fetch a boolean value from the input or return $default if not set. |
||
| 489 | * Guaranteed to return true or false, with normal PHP semantics for |
||
| 490 | * boolean interpretation of strings. |
||
| 491 | * |
||
| 492 | * @param string $name |
||
| 493 | * @param bool $default |
||
| 494 | * @return bool |
||
| 495 | */ |
||
| 496 | public function getBool( $name, $default = false ) { |
||
| 499 | |||
| 500 | /** |
||
| 501 | * Fetch a boolean value from the input or return $default if not set. |
||
| 502 | * Unlike getBool, the string "false" will result in boolean false, which is |
||
| 503 | * useful when interpreting information sent from JavaScript. |
||
| 504 | * |
||
| 505 | * @param string $name |
||
| 506 | * @param bool $default |
||
| 507 | * @return bool |
||
| 508 | */ |
||
| 509 | public function getFuzzyBool( $name, $default = false ) { |
||
| 512 | |||
| 513 | /** |
||
| 514 | * Return true if the named value is set in the input, whatever that |
||
| 515 | * value is (even "0"). Return false if the named value is not set. |
||
| 516 | * Example use is checking for the presence of check boxes in forms. |
||
| 517 | * |
||
| 518 | * @param string $name |
||
| 519 | * @return bool |
||
| 520 | */ |
||
| 521 | public function getCheck( $name ) { |
||
| 526 | |||
| 527 | /** |
||
| 528 | * Fetch a text string from the given array or return $default if it's not |
||
| 529 | * set. Carriage returns are stripped from the text, and with some language |
||
| 530 | * modules there is an input transliteration applied. This should generally |
||
| 531 | * be used for form "<textarea>" and "<input>" fields. Used for |
||
| 532 | * user-supplied freeform text input (for which input transformations may |
||
| 533 | * be required - e.g. Esperanto x-coding). |
||
| 534 | * |
||
| 535 | * @param string $name |
||
| 536 | * @param string $default Optional |
||
| 537 | * @return string |
||
| 538 | */ |
||
| 539 | public function getText( $name, $default = '' ) { |
||
| 545 | |||
| 546 | /** |
||
| 547 | * Extracts the given named values into an array. |
||
| 548 | * If no arguments are given, returns all input values. |
||
| 549 | * No transformation is performed on the values. |
||
| 550 | * |
||
| 551 | * @return array |
||
| 552 | */ |
||
| 553 | public function getValues() { |
||
| 568 | |||
| 569 | /** |
||
| 570 | * Returns the names of all input values excluding those in $exclude. |
||
| 571 | * |
||
| 572 | * @param array $exclude |
||
| 573 | * @return array |
||
| 574 | */ |
||
| 575 | public function getValueNames( $exclude = [] ) { |
||
| 578 | |||
| 579 | /** |
||
| 580 | * Get the values passed in the query string. |
||
| 581 | * No transformation is performed on the values. |
||
| 582 | * |
||
| 583 | * @return array |
||
| 584 | */ |
||
| 585 | public function getQueryValues() { |
||
| 588 | |||
| 589 | /** |
||
| 590 | * Return the contents of the Query with no decoding. Use when you need to |
||
| 591 | * know exactly what was sent, e.g. for an OAuth signature over the elements. |
||
| 592 | * |
||
| 593 | * @return string |
||
| 594 | */ |
||
| 595 | public function getRawQueryString() { |
||
| 598 | |||
| 599 | /** |
||
| 600 | * Return the contents of the POST with no decoding. Use when you need to |
||
| 601 | * know exactly what was sent, e.g. for an OAuth signature over the elements. |
||
| 602 | * |
||
| 603 | * @return string |
||
| 604 | */ |
||
| 605 | public function getRawPostString() { |
||
| 611 | |||
| 612 | /** |
||
| 613 | * Return the raw request body, with no processing. Cached since some methods |
||
| 614 | * disallow reading the stream more than once. As stated in the php docs, this |
||
| 615 | * does not work with enctype="multipart/form-data". |
||
| 616 | * |
||
| 617 | * @return string |
||
| 618 | */ |
||
| 619 | public function getRawInput() { |
||
| 626 | |||
| 627 | /** |
||
| 628 | * Get the HTTP method used for this request. |
||
| 629 | * |
||
| 630 | * @return string |
||
| 631 | */ |
||
| 632 | public function getMethod() { |
||
| 635 | |||
| 636 | /** |
||
| 637 | * Returns true if the present request was reached by a POST operation, |
||
| 638 | * false otherwise (GET, HEAD, or command-line). |
||
| 639 | * |
||
| 640 | * Note that values retrieved by the object may come from the |
||
| 641 | * GET URL etc even on a POST request. |
||
| 642 | * |
||
| 643 | * @return bool |
||
| 644 | */ |
||
| 645 | public function wasPosted() { |
||
| 648 | |||
| 649 | /** |
||
| 650 | * Return the session for this request |
||
| 651 | * @since 1.27 |
||
| 652 | * @note For performance, keep the session locally if you will be making |
||
| 653 | * much use of it instead of calling this method repeatedly. |
||
| 654 | * @return MediaWiki\\Session\\Session |
||
| 655 | */ |
||
| 656 | public function getSession() { |
||
| 668 | |||
| 669 | /** |
||
| 670 | * Set the session for this request |
||
| 671 | * @since 1.27 |
||
| 672 | * @private For use by MediaWiki\\Session classes only |
||
| 673 | * @param MediaWiki\\Session\\SessionId $sessionId |
||
| 674 | */ |
||
| 675 | public function setSessionId( MediaWiki\Session\SessionId $sessionId ) { |
||
| 678 | |||
| 679 | /** |
||
| 680 | * Get the session id for this request, if any |
||
| 681 | * @since 1.27 |
||
| 682 | * @private For use by MediaWiki\\Session classes only |
||
| 683 | * @return MediaWiki\\Session\\SessionId|null |
||
| 684 | */ |
||
| 685 | public function getSessionId() { |
||
| 686 | return $this->sessionId; |
||
| 687 | } |
||
| 688 | |||
| 689 | /** |
||
| 690 | * Returns true if the request has a persistent session. |
||
| 691 | * This does not necessarily mean that the user is logged in! |
||
| 692 | * |
||
| 693 | * @deprecated since 1.27, use |
||
| 694 | * \\MediaWiki\\Session\\SessionManager::singleton()->getPersistedSessionId() |
||
| 695 | * instead. |
||
| 696 | * @return bool |
||
| 697 | */ |
||
| 698 | public function checkSessionCookie() { |
||
| 704 | |||
| 705 | /** |
||
| 706 | * Get a cookie from the $_COOKIE jar |
||
| 707 | * |
||
| 708 | * @param string $key The name of the cookie |
||
| 709 | * @param string $prefix A prefix to use for the cookie name, if not $wgCookiePrefix |
||
| 710 | * @param mixed $default What to return if the value isn't found |
||
| 711 | * @return mixed Cookie value or $default if the cookie not set |
||
| 712 | */ |
||
| 713 | public function getCookie( $key, $prefix = null, $default = null ) { |
||
| 720 | |||
| 721 | /** |
||
| 722 | * Return the path and query string portion of the main request URI. |
||
| 723 | * This will be suitable for use as a relative link in HTML output. |
||
| 724 | * |
||
| 725 | * @throws MWException |
||
| 726 | * @return string |
||
| 727 | */ |
||
| 728 | public static function getGlobalRequestURL() { |
||
| 764 | |||
| 765 | /** |
||
| 766 | * Return the path and query string portion of the request URI. |
||
| 767 | * This will be suitable for use as a relative link in HTML output. |
||
| 768 | * |
||
| 769 | * @throws MWException |
||
| 770 | * @return string |
||
| 771 | */ |
||
| 772 | public function getRequestURL() { |
||
| 775 | |||
| 776 | /** |
||
| 777 | * Return the request URI with the canonical service and hostname, path, |
||
| 778 | * and query string. This will be suitable for use as an absolute link |
||
| 779 | * in HTML or other output. |
||
| 780 | * |
||
| 781 | * If $wgServer is protocol-relative, this will return a fully |
||
| 782 | * qualified URL with the protocol that was used for this request. |
||
| 783 | * |
||
| 784 | * @return string |
||
| 785 | */ |
||
| 786 | public function getFullRequestURL() { |
||
| 789 | |||
| 790 | /** |
||
| 791 | * @param string $key |
||
| 792 | * @param string $value |
||
| 793 | * @return string |
||
| 794 | */ |
||
| 795 | public function appendQueryValue( $key, $value ) { |
||
| 798 | |||
| 799 | /** |
||
| 800 | * Appends or replaces value of query variables. |
||
| 801 | * |
||
| 802 | * @param array $array Array of values to replace/add to query |
||
| 803 | * @return string |
||
| 804 | */ |
||
| 805 | public function appendQueryArray( $array ) { |
||
| 812 | |||
| 813 | /** |
||
| 814 | * Check for limit and offset parameters on the input, and return sensible |
||
| 815 | * defaults if not given. The limit must be positive and is capped at 5000. |
||
| 816 | * Offset must be positive but is not capped. |
||
| 817 | * |
||
| 818 | * @param int $deflimit Limit to use if no input and the user hasn't set the option. |
||
| 819 | * @param string $optionname To specify an option other than rclimit to pull from. |
||
| 820 | * @return int[] First element is limit, second is offset |
||
| 821 | */ |
||
| 822 | public function getLimitOffset( $deflimit = 50, $optionname = 'rclimit' ) { |
||
| 846 | |||
| 847 | /** |
||
| 848 | * Return the path to the temporary file where PHP has stored the upload. |
||
| 849 | * |
||
| 850 | * @param string $key |
||
| 851 | * @return string|null String or null if no such file. |
||
| 852 | */ |
||
| 853 | public function getFileTempname( $key ) { |
||
| 857 | |||
| 858 | /** |
||
| 859 | * Return the upload error or 0 |
||
| 860 | * |
||
| 861 | * @param string $key |
||
| 862 | * @return int |
||
| 863 | */ |
||
| 864 | public function getUploadError( $key ) { |
||
| 868 | |||
| 869 | /** |
||
| 870 | * Return the original filename of the uploaded file, as reported by |
||
| 871 | * the submitting user agent. HTML-style character entities are |
||
| 872 | * interpreted and normalized to Unicode normalization form C, in part |
||
| 873 | * to deal with weird input from Safari with non-ASCII filenames. |
||
| 874 | * |
||
| 875 | * Other than this the name is not verified for being a safe filename. |
||
| 876 | * |
||
| 877 | * @param string $key |
||
| 878 | * @return string|null String or null if no such file. |
||
| 879 | */ |
||
| 880 | public function getFileName( $key ) { |
||
| 884 | |||
| 885 | /** |
||
| 886 | * Return a WebRequestUpload object corresponding to the key |
||
| 887 | * |
||
| 888 | * @param string $key |
||
| 889 | * @return WebRequestUpload |
||
| 890 | */ |
||
| 891 | public function getUpload( $key ) { |
||
| 894 | |||
| 895 | /** |
||
| 896 | * Return a handle to WebResponse style object, for setting cookies, |
||
| 897 | * headers and other stuff, for Request being worked on. |
||
| 898 | * |
||
| 899 | * @return WebResponse |
||
| 900 | */ |
||
| 901 | public function response() { |
||
| 909 | |||
| 910 | /** |
||
| 911 | * Initialise the header list |
||
| 912 | */ |
||
| 913 | protected function initHeaders() { |
||
| 934 | |||
| 935 | /** |
||
| 936 | * Get an array containing all request headers |
||
| 937 | * |
||
| 938 | * @return array Mapping header name to its value |
||
| 939 | */ |
||
| 940 | public function getAllHeaders() { |
||
| 944 | |||
| 945 | /** |
||
| 946 | * Get a request header, or false if it isn't set. |
||
| 947 | * |
||
| 948 | * @param string $name Case-insensitive header name |
||
| 949 | * @param int $flags Bitwise combination of: |
||
| 950 | * WebRequest::GETHEADER_LIST Treat the header as a comma-separated list |
||
| 951 | * of values, as described in RFC 2616 § 4.2. |
||
| 952 | * (since 1.26). |
||
| 953 | * @return string|array|bool False if header is unset; otherwise the |
||
| 954 | * header value(s) as either a string (the default) or an array, if |
||
| 955 | * WebRequest::GETHEADER_LIST flag was set. |
||
| 956 | */ |
||
| 957 | public function getHeader( $name, $flags = 0 ) { |
||
| 969 | |||
| 970 | /** |
||
| 971 | * Get data from the session |
||
| 972 | * |
||
| 973 | * @note Prefer $this->getSession() instead if making multiple calls. |
||
| 974 | * @param string $key Name of key in the session |
||
| 975 | * @return mixed |
||
| 976 | */ |
||
| 977 | public function getSessionData( $key ) { |
||
| 980 | |||
| 981 | /** |
||
| 982 | * Set session data |
||
| 983 | * |
||
| 984 | * @note Prefer $this->getSession() instead if making multiple calls. |
||
| 985 | * @param string $key Name of key in the session |
||
| 986 | * @param mixed $data |
||
| 987 | */ |
||
| 988 | public function setSessionData( $key, $data ) { |
||
| 991 | |||
| 992 | /** |
||
| 993 | * Check if Internet Explorer will detect an incorrect cache extension in |
||
| 994 | * PATH_INFO or QUERY_STRING. If the request can't be allowed, show an error |
||
| 995 | * message or redirect to a safer URL. Returns true if the URL is OK, and |
||
| 996 | * false if an error message has been shown and the request should be aborted. |
||
| 997 | * |
||
| 998 | * @param array $extWhitelist |
||
| 999 | * @throws HttpError |
||
| 1000 | * @return bool |
||
| 1001 | */ |
||
| 1002 | public function checkUrlExtension( $extWhitelist = [] ) { |
||
| 1018 | |||
| 1019 | /** |
||
| 1020 | * Attempt to redirect to a URL with a QUERY_STRING that's not dangerous in |
||
| 1021 | * IE 6. Returns true if it was successful, false otherwise. |
||
| 1022 | * |
||
| 1023 | * @param string $url |
||
| 1024 | * @return bool |
||
| 1025 | */ |
||
| 1026 | protected function doSecurityRedirect( $url ) { |
||
| 1051 | |||
| 1052 | /** |
||
| 1053 | * Parse the Accept-Language header sent by the client into an array |
||
| 1054 | * |
||
| 1055 | * @return array Array( languageCode => q-value ) sorted by q-value in |
||
| 1056 | * descending order then appearing time in the header in ascending order. |
||
| 1057 | * May contain the "language" '*', which applies to languages other than those explicitly listed. |
||
| 1058 | * This is aligned with rfc2616 section 14.4 |
||
| 1059 | * Preference for earlier languages appears in rfc3282 as an extension to HTTP/1.1. |
||
| 1060 | */ |
||
| 1061 | public function getAcceptLang() { |
||
| 1105 | |||
| 1106 | /** |
||
| 1107 | * Fetch the raw IP from the request |
||
| 1108 | * |
||
| 1109 | * @since 1.19 |
||
| 1110 | * |
||
| 1111 | * @throws MWException |
||
| 1112 | * @return string |
||
| 1113 | */ |
||
| 1114 | protected function getRawIP() { |
||
| 1128 | |||
| 1129 | /** |
||
| 1130 | * Work out the IP address based on various globals |
||
| 1131 | * For trusted proxies, use the XFF client IP (first of the chain) |
||
| 1132 | * |
||
| 1133 | * @since 1.19 |
||
| 1134 | * |
||
| 1135 | * @throws MWException |
||
| 1136 | * @return string |
||
| 1137 | */ |
||
| 1138 | public function getIP() { |
||
| 1203 | |||
| 1204 | /** |
||
| 1205 | * @param string $ip |
||
| 1206 | * @return void |
||
| 1207 | * @since 1.21 |
||
| 1208 | */ |
||
| 1209 | public function setIP( $ip ) { |
||
| 1212 | } |
||
| 1213 |
Only declaring a single property per statement allows you to later on add doc comments more easily.
It is also recommended by PSR2, so it is a common style that many people expect.