Sfoglia il codice sorgente

merged branch stloyd/local_stub_cs (PR #2890)

Commits
-------

ed353da [Locale][Stub] Fixed CS

Discussion
----------

[Locale][Stub] Fixed CS

Bug fix: no
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes

Just fixed code according to Symfony2 CS.
Fabien Potencier 13 anni fa
parent
commit
62e37dd807

+ 1 - 7
src/Symfony/Component/Locale/Stub/DateFormat/DayTransformer.php

@@ -31,13 +31,7 @@ class DayTransformer extends Transformer
      */
     public function getReverseMatchingRegExp($length)
     {
-        if (1 == $length) {
-            $regExp = '\d{1,2}';
-        } else {
-            $regExp = '\d{'.$length.'}';
-        }
-
-        return $regExp;
+        return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
     }
 
     /**

+ 5 - 6
src/Symfony/Component/Locale/Stub/DateFormat/FullTransformer.php

@@ -116,11 +116,11 @@ class FullTransformer
             $transformer = $this->transformers[$dateChars[0]];
 
             return $transformer->format($dateTime, $length);
-        } else {
-            // handle unimplemented characters
-            if (false !== strpos($this->notImplementedChars, $dateChars[0])) {
-                throw new NotImplementedException(sprintf("Unimplemented date character '%s' in format '%s'", $dateChars[0], $this->pattern));
-            }
+        }
+
+        // handle unimplemented characters
+        if (false !== strpos($this->notImplementedChars, $dateChars[0])) {
+            throw new NotImplementedException(sprintf("Unimplemented date character '%s' in format '%s'", $dateChars[0], $this->pattern));
         }
     }
 
@@ -181,7 +181,6 @@ class FullTransformer
             }
 
             $transformers = $that->getTransformers();
-
             if (isset($transformers[$transformerIndex])) {
                 $transformer = $transformers[$transformerIndex];
                 $captureName = str_repeat($transformerIndex, $length);

+ 1 - 1
src/Symfony/Component/Locale/Stub/DateFormat/Hour1200Transformer.php

@@ -24,7 +24,7 @@ class Hour1200Transformer extends HourTransformer
     public function format(\DateTime $dateTime, $length)
     {
         $hourOfDay = $dateTime->format('g');
-        $hourOfDay = ('12' == $hourOfDay) ? '0' : $hourOfDay;
+        $hourOfDay = '12' == $hourOfDay ? '0' : $hourOfDay;
 
         return $this->padLeft($hourOfDay, $length);
     }

+ 1 - 1
src/Symfony/Component/Locale/Stub/DateFormat/Hour1201Transformer.php

@@ -35,7 +35,7 @@ class Hour1201Transformer extends HourTransformer
             $hour = 0;
         } elseif ('PM' === $marker && 12 !== $hour) {
             // If PM and hour is not 12 (1-12), sum 12 hour
-            $hour = $hour + 12;
+            $hour += 12;
         }
 
         return $hour;

+ 1 - 3
src/Symfony/Component/Locale/Stub/DateFormat/Hour2401Transformer.php

@@ -34,9 +34,7 @@ class Hour2401Transformer extends HourTransformer
      */
     public function normalizeHour($hour, $marker = null)
     {
-        if (null === $marker && 24 === $hour) {
-            $hour = 0;
-        } else if ('AM' == $marker) {
+        if ((null === $marker && 24 === $hour) || 'AM' == $marker) {
             $hour = 0;
         } else if ('PM' == $marker) {
             $hour = 12;

+ 1 - 7
src/Symfony/Component/Locale/Stub/DateFormat/MinuteTransformer.php

@@ -33,13 +33,7 @@ class MinuteTransformer extends Transformer
      */
     public function getReverseMatchingRegExp($length)
     {
-        if (1 == $length) {
-            $regExp = '\d{1,2}';
-        } else {
-            $regExp = '\d{'.$length.'}';
-        }
-
-        return $regExp;
+        return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
     }
 
     /**

+ 15 - 16
src/Symfony/Component/Locale/Stub/DateFormat/MonthTransformer.php

@@ -60,7 +60,7 @@ class MonthTransformer extends Transformer
      */
     public function __construct()
     {
-        if (0 == count(self::$shortMonths)) {
+        if (0 === count(self::$shortMonths)) {
             self::$shortMonths = array_map(function($month) {
                 return substr($month, 0, 3);
             }, self::$months);
@@ -76,19 +76,21 @@ class MonthTransformer extends Transformer
     public function format(\DateTime $dateTime, $length)
     {
         $matchLengthMap = array(
-            1   => 'n',
-            2   => 'm',
-            3   => 'M',
-            4   => 'F',
+            1 => 'n',
+            2 => 'm',
+            3 => 'M',
+            4 => 'F',
         );
 
         if (isset($matchLengthMap[$length])) {
-           return $dateTime->format($matchLengthMap[$length]);
-        } else if (5 == $length) {
+            return $dateTime->format($matchLengthMap[$length]);
+        }
+
+        if (5 === $length) {
             return substr($dateTime->format('M'), 0, 1);
-        } else {
-            return $this->padLeft($dateTime->format('m'), $length);
         }
+
+        return $this->padLeft($dateTime->format('m'), $length);
     }
 
     /**
@@ -123,18 +125,15 @@ class MonthTransformer extends Transformer
     public function extractDateOptions($matched, $length)
     {
         if (!is_numeric($matched)) {
-            if (3 == $length) {
+            if (3 === $length) {
                 $matched = self::$flippedShortMonths[$matched] + 1;
-            }
-            elseif (4 == $length) {
+            } elseif (4 === $length) {
                 $matched = self::$flippedMonths[$matched] + 1;
-            }
-            elseif (5 == $length) {
+            } elseif (5 === $length) {
                 // IntlDateFormatter::parse() always returns false for MMMMM or LLLLL
                 $matched = false;
             }
-        }
-        else {
+        } else {
             $matched = (int) $matched;
         }
 

+ 1 - 7
src/Symfony/Component/Locale/Stub/DateFormat/SecondTransformer.php

@@ -33,13 +33,7 @@ class SecondTransformer extends Transformer
      */
     public function getReverseMatchingRegExp($length)
     {
-        if (1 == $length) {
-            $regExp = '\d{1,2}';
-        } else {
-            $regExp = '\d{'.$length.'}';
-        }
-
-        return $regExp;
+        return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
     }
 
     /**

+ 4 - 10
src/Symfony/Component/Locale/Stub/DateFormat/YearTransformer.php

@@ -23,11 +23,11 @@ class YearTransformer extends Transformer
      */
     public function format(\DateTime $dateTime, $length)
     {
-        if (2 == $length) {
+        if (2 === $length) {
             return $dateTime->format('y');
-        } else {
-            return $this->padLeft($dateTime->format('Y'), $length);
         }
+
+        return $this->padLeft($dateTime->format('Y'), $length);
     }
 
     /**
@@ -35,13 +35,7 @@ class YearTransformer extends Transformer
      */
     public function getReverseMatchingRegExp($length)
     {
-        if (2 == $length) {
-            $regExp = '\d{2}';
-        } else {
-            $regExp = '\d{4}';
-        }
-
-        return $regExp;
+        return 2 === $length ? '\d{2}' : '\d{4}';
     }
 
     /**

+ 5 - 5
src/Symfony/Component/Locale/Stub/StubIntl.php

@@ -77,7 +77,7 @@ abstract class StubIntl
      */
     static public function isFailure($errorCode)
     {
-        return in_array($errorCode, static::$errorCodes, true)
+        return in_array($errorCode, self::$errorCodes, true)
             && $errorCode !== self::U_ZERO_ERROR;
     }
 
@@ -90,7 +90,7 @@ abstract class StubIntl
      */
     static public function getErrorCode()
     {
-        return static::$errorCode;
+        return self::$errorCode;
     }
 
     /**
@@ -102,7 +102,7 @@ abstract class StubIntl
      */
     static public function getErrorMessage()
     {
-        return static::$errorMessages[static::$errorCode];
+        return self::$errorMessages[self::$errorCode];
     }
 
     /**
@@ -114,10 +114,10 @@ abstract class StubIntl
      */
     static public function setErrorCode($code)
     {
-        if (!isset(static::$errorMessages[$code])) {
+        if (!isset(self::$errorMessages[$code])) {
             throw new \InvalidArgumentException(sprintf('No such error code: "%s"', $code));
         }
 
-        static::$errorCode = $code;
+        self::$errorCode = $code;
     }
 }

+ 1 - 2
src/Symfony/Component/Locale/Stub/StubLocale.php

@@ -481,8 +481,7 @@ class StubLocale
     static private function getStubData($locale, $cacheVariable, $stubDataDir)
     {
         if ('en' != $locale) {
-            $message = 'Only the \'en\' locale is supported. '.NotImplementedException::INTL_INSTALL_MESSAGE;
-            throw new \InvalidArgumentException($message);
+            throw new \InvalidArgumentException(sprintf('Only the \'en\' locale is supported. %s', NotImplementedException::INTL_INSTALL_MESSAGE));
         }
 
         if (empty(self::${$cacheVariable})) {