Make most of DateFormatter private
authorMax Semenik <maxsem.wiki@gmail.com>
Wed, 18 Jan 2017 19:01:26 +0000 (11:01 -0800)
committerMax Semenik <maxsem.wiki@gmail.com>
Thu, 19 Jan 2017 21:39:18 +0000 (13:39 -0800)
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

index 0653725..08e3c77 100644 (file)
  * @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 {