8000 merged branch stloyd/local_stub_cs (PR #2890) · symfony/symfony@62e37dd · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 62e37dd

Browse files
committed
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.
2 parents f03692a + ed353da commit 62e37dd

11 files changed

+36
-65
lines changed

src/Symfony/Component/Locale/Stub/DateFormat/DayTransformer.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,7 @@ public function format(\DateTime $dateTime, $length)
3131
*/
3232
public function getReverseMatchingRegExp($length)
3333
{
34-
if (1 == $length) {
35-
$regExp = '\d{1,2}';
36-
} else {
37-
$regExp = '\d{'.$length.'}';
38-
}
39-
40-
return $regExp;
34+
return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
4135
}
4236

4337
/**

src/Symfony/Component/Locale/Stub/DateFormat/FullTransformer.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ public function formatReplace($dateChars, $dateTime)
116116
$transformer = $this->transformers[$dateChars[0]];
117117

118118
return $transformer->format($dateTime, $length);
119-
} else {
120-
// handle unimplemented characters
121-
if (false !== strpos($this->notImplementedChars, $dateChars[0])) {
122-
throw new NotImplementedException(sprintf("Unimplemented date character '%s' in format '%s'", $dateChars[0], $this->pattern));
123-
}
119+
}
120+
121+
// handle unimplemented characters
122+
if (false !== strpos($this->notImplementedChars, $dateChars[0])) {
123+
throw new NotImplementedException(sprintf("Unimplemented date character '%s' in format '%s'", $dateChars[0], $this->pattern));
124124
}
125125
}
126126

@@ -181,7 +181,6 @@ public function getReverseMatchingRegExp($pattern)
181181
}
182182

183183
$transformers = $that->getTransformers();
184-
185184
if (isset($transformers[$transformerIndex])) {
186185
$transformer = $transformers[$transformerIndex];
187186
$captureName = str_repeat($transformerIndex, $length);

src/Symfony/Component/Locale/Stub/DateFormat/Hour1200Transformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Hour1200Transformer extends HourTransformer
2424
public function format(\DateTime $dateTime, $length)
2525
{
2626
$hourOfDay = $dateTime->format('g');
27-
$hourOfDay = ('12' == $hourOfDay) ? '0' : $hourOfDay;
27+
$hourOfDay = '12' == $hourOfDay ? '0' : $hourOfDay;
2828

2929
return $this->padLeft($hourOfDay, $length);
3030
}

src/Symfony/Component/Locale/Stub/DateFormat/Hour1201Transformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function normalizeHour($hour, $marker = null)
3535
$hour = 0;
3636
} elseif ('PM' === $marker && 12 !== $hour) {
3737
// If PM and hour is not 12 (1-12), sum 12 hour
38-
$hour = $hour + 12;
38+
$hour += 12;
3939
}
4040

4141
return $hour;

src/Symfony/Component/Locale/Stub/DateFormat/Hour2401Transformer.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ public function format(\DateTime $dateTime, $length)
3434
*/
3535
public function normalizeHour($hour, $marker = null)
3636
{
37-
if (null === $marker && 24 === $hour) {
38-
$hour = 0;
39-
} else if ('AM' == $marker) {
37+
if ((null === $marker && 24 === $hour) || 'AM' == $marker) {
4038
$hour = 0;
4139
} else if ('PM' == $marker) {
4240
$hour = 12;

src/Symfony/Component/Locale/Stub/DateFormat/MinuteTransformer.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,7 @@ public function format(\DateTime $dateTime, $length)
3333
*/
3434
public function getReverseMatchingRegExp($length)
3535
{
36-
if (1 == $length) {
37-
$regExp = '\d{1,2}';
38-
} else {
39-
$regExp = '\d{'.$length.'}';
40-
}
41-
42-
return $regExp;
36+
return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
4337
}
4438

4539
/**

src/Symfony/Component/Locale/Stub/DateFormat/MonthTransformer.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class MonthTransformer extends Transformer
6060
*/
6161
public function __construct()
6262
{
63-
if (0 == count(self::$shortMonths)) {
63+
if (0 === count(self::$shortMonths)) {
6464
self::$shortMonths = array_map(function($month) {
6565
return substr($month, 0, 3);
6666
}, self::$months);
@@ -76,19 +76,21 @@ public function __construct()
7676
public function format(\DateTime $dateTime, $length)
7777
{
7878
$matchLengthMap = array(
79-
1 => 'n',
80-
2 => 'm',
81-
3 => 'M',
82-
4 => 'F',
79+
1 => 'n',
80+
2 => 'm',
81+
3 => 'M',
82+
4 => 'F',
8383
);
8484

8585
if (isset($matchLengthMap[$length])) {
86-
return $dateTime->format($matchLengthMap[$length]);
87-
} else if (5 == $length) {
86+
return $dateTime->format($matchLengthMap[$length]);
87+
}
88+
89+
if (5 === $length) {
8890
return substr($dateTime->format('M'), 0, 1);
89-
} else {
90-
return $this->padLeft($dateTime->format('m'), $length);
9191
}
92+
93+
return $this->padLeft($dateTime->format('m'), $length);
9294
}
9395

9496
/**
@@ -123,18 +125,15 @@ public function getReverseMatchingRegExp($length)
123125
public function extractDateOptions($matched, $length)
124126
{
125127
if (!is_numeric($matched)) {
126-
if (3 == $length) {
128+
if (3 === $length) {
127129
$matched = self::$flippedShortMonths[$matched] + 1;
128-
}
129-
elseif (4 == $length) {
130+
} elseif (4 === $length) {
130131
$matched = self::$flippedMonths[$matched] + 1;
131-
}
132-
elseif (5 == $length) {
132+
} elseif (5 === $length) {
133133
// IntlDateFormatter::parse() always returns false for MMMMM or LLLLL
134134
$matched = false;
135135
}
136-
}
137-
else {
136+
} else {
138137
$matched = (int) $matched;
139138
}
140139

src/Symfony/Component/Locale/Stub/DateFormat/SecondTransformer.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,7 @@ public function format(\DateTime $dateTime, $length)
3333
*/
3434
public function getReverseMatchingRegExp($length)
3535
{
36-
if (1 == $length) {
37-
$regExp = '\d{1,2}';
38-
} else {
39-
$regExp = '\d{'.$length.'}';
40-
}
41-
42-
return $regExp;
36+
return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
4337
}
4438

4539
/**

src/Symfony/Component/Locale/Stub/DateFormat/YearTransformer.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,19 @@ class YearTransformer extends Transformer
2323
*/
2424
public function format(\DateTime $dateTime, $length)
2525
{
26-
if (2 == $length) {
26+
if (2 === $length) {
2727
return $dateTime->format('y');
28-
} else {
29-
return $this->padLeft($dateTime->format('Y'), $length);
3028
}
29+
30+
return $this->padLeft($dateTime->format('Y'), $length);
3131
}
3232

3333
/**
3434
* {@inheritDoc}
3535
*/
3636
public function getReverseMatchingRegExp($length)
3737
{
38-
if (2 == $length) {
39-
$regExp = '\d{2}';
40-
} else {
41-
$regExp = '\d{4}';
42-
}
43-
44-
return $regExp;
38+
return 2 === $length ? '\d{2}' : '\d{4}';
4539
}
4640

4741
/**

src/Symfony/Component/Locale/Stub/StubIntl.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ abstract class StubIntl
7777
*/
7878
static public function isFailure($errorCode)
7979
{
80-
return in_array($errorCode, static::$errorCodes, true)
80+
return in_array($errorCode, self::$errorCodes, true)
8181
&& $errorCode !== self::U_ZERO_ERROR;
8282
}
8383

@@ -90,7 +90,7 @@ static public function isFailure($errorCode)
9090
*/
9191
static public function getErrorCode()
9292
{
93-
return static::$errorCode;
93+
return self::$errorCode;
9494
}
9595

9696
/**
@@ -102,7 +102,7 @@ static public function getErrorCode()
102102
*/
103103
static public function getErrorMessage()
104104
{
105-
return static::$errorMessages[static::$errorCode];
105+
return self::$errorMessages[self::$errorCode];
106106
}
107107

108108
/**
@@ -114,10 +114,10 @@ static public function getErrorMessage()
114114
*/
115115
static public function setErrorCode($code)
116116
{
117-
if (!isset(static::$errorMessages[$code])) {
117+
if (!isset(self::$errorMessages[$code])) {
118118
throw new \InvalidArgumentException(sprintf('No such error code: "%s"', $code));
119119
}
120120

121-
static::$errorCode = $code;
121+
self::$errorCode = $code;
122122
}
123123
}

src/Symfony/Component/Locale/Stub/StubLocale.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,7 @@ static public function setDefault($locale)
481481
static private function getStubData($locale, $cacheVariable, $stubDataDir)
482482
{
483483
if ('en' != $locale) {
484-
$message = 'Only the \'en\' locale is supported. '.NotImplementedException::INTL_INSTALL_MESSAGE;
485-
throw new \InvalidArgumentException($message);
484+
throw new \InvalidArgumentException(sprintf('Only the \'en\' locale is supported. %s', NotImplementedException::INTL_INSTALL_MESSAGE));
486485
}
487486

488487
if (empty(self::${$cacheVariable})) {

0 commit comments

Comments
 (0)
0