[Locale][Stub] Fixed CS

This commit is contained in:
Joseph Bielawski 2011-12-15 12:27:16 +01:00
parent 75dfc7945a
commit ed353da164
11 changed files with 37 additions and 66 deletions

View File

@ -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.'}';
}
/**

View File

@ -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);

View File

@ -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);
}

View File

@ -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;

View File

@ -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;

View File

@ -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.'}';
}
/**

View File

@ -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 substr($dateTime->format('M'), 0, 1);
} else {
return $this->padLeft($dateTime->format('m'), $length);
return $dateTime->format($matchLengthMap[$length]);
}
if (5 === $length) {
return substr($dateTime->format('M'), 0, 1);
}
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;
}

View File

@ -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.'}';
}
/**

View File

@ -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}';
}
/**

View File

@ -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;
}
}

View File

@ -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})) {