From 4ca09bd76f19614464414b692b8f57ac8b7f5495 Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Wed, 18 Jan 2017 11:01:26 -0800 Subject: [PATCH] Make most of DateFormatter private As discussed in https://gerrit.wikimedia.org/r/#/c/332702/ , these methods and fields shouldn't have been marked public in the first place. No outside users. Also, declare a couple of fields and remove unused ones. Change-Id: I7775978c87d983784a484ee2ad901d25c42499b3 --- includes/parser/DateFormatter.php | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/includes/parser/DateFormatter.php b/includes/parser/DateFormatter.php index 0653725863..08e3c77158 100644 --- a/includes/parser/DateFormatter.php +++ b/includes/parser/DateFormatter.php @@ -27,13 +27,19 @@ * @ingroup Parser */ class DateFormatter { - public $mSource, $mTarget; - public $monthNames = '', $rxDM, $rxMD, $rxDMY, $rxYDM, $rxMDY, $rxYMD; + private $mSource, $mTarget; + private $monthNames = ''; - public $regexes, $pDays, $pMonths, $pYears; - public $rules, $xMonths, $preferences; + private $regexes; + private $rules, $xMonths, $preferences; - protected $lang, $mLinked; + private $lang, $mLinked; + + /** @var string[] */ + private $keys; + + /** @var string[] */ + private $targets; const ALL = -1; const NONE = 0; @@ -198,10 +204,12 @@ class DateFormatter { } /** + * Regexp replacement callback + * * @param array $matches * @return string */ - public function replace( $matches ) { + private function replace( $matches ) { # Extract information from $matches $linked = true; if ( isset( $this->mLinked ) ) { @@ -326,7 +334,7 @@ class DateFormatter { * Return a regex that can be used to find month names in string * @return string regex to find the months with */ - public function getMonthRegex() { + private function getMonthRegex() { $names = []; for ( $i = 1; $i <= 12; $i++ ) { $names[] = $this->lang->getMonthName( $i ); @@ -340,7 +348,7 @@ class DateFormatter { * @param string $monthName Month name * @return string ISO month name */ - public function makeIsoMonth( $monthName ) { + private function makeIsoMonth( $monthName ) { $n = $this->xMonths[$this->lang->lc( $monthName )]; return sprintf( '%02d', $n ); } @@ -350,7 +358,7 @@ class DateFormatter { * @param string $year Year name * @return string ISO year name */ - public function makeIsoYear( $year ) { + private function makeIsoYear( $year ) { # Assumes the year is in a nice format, as enforced by the regex if ( substr( $year, -2 ) == 'BC' ) { $num = intval( substr( $year, 0, -3 ) ) - 1; @@ -369,7 +377,7 @@ class DateFormatter { * @return int|string int representing year number in case of AD dates, or string containing * year number and 'BC' at the end otherwise. */ - public function makeNormalYear( $iso ) { + private function makeNormalYear( $iso ) { if ( $iso[0] == '-' ) { $text = ( intval( substr( $iso, 1 ) ) + 1 ) . ' BC'; } else { -- 2.20.1