Skip to content

Commit

Permalink
Fix PHPStorm findings
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu authored and greg0ire committed Dec 6, 2019
1 parent c07455e commit b9ac023
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 63 deletions.
5 changes: 0 additions & 5 deletions src/DependencyInjection/Compiler/StrictPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ public function process(ContainerBuilder $container)
*/
private function changeReference(Reference $reference, $serviceId)
{
// Stay compatible with Symfony 2
if (method_exists($reference, 'isStrict')) {
return new Reference($serviceId, $reference->getInvalidBehavior(), $reference->isStrict(false));
}

return new Reference($serviceId, $reference->getInvalidBehavior());
}
}
13 changes: 8 additions & 5 deletions src/DependencyInjection/SonataIntlExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,15 @@ protected function configureLocale(ContainerBuilder $container, array $config)
*/
private function validateTimezones(array $timezones)
{
try {
foreach ($timezones as $timezone) {
$tz = new \DateTimeZone($timezone);
foreach ($timezones as $timezone) {
try {
new \DateTimeZone($timezone);
} catch (\Exception $e) {
throw new \RuntimeException(sprintf(
'Unknown timezone "%s". Please check your sonata_intl configuration.',
$timezone
));
}
} catch (\Exception $e) {
throw new \RuntimeException(sprintf('Unknown timezone "%s". Please check your sonata_intl configuration.', $timezone));
}
}
}
2 changes: 1 addition & 1 deletion src/SonataIntlBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SonataIntlBundle extends Bundle
*
* @static
*
* @param $version
* @param string $version
*
* @return string
*/
Expand Down
3 changes: 1 addition & 2 deletions src/Templating/Helper/BaseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ public static function getICUDataVersion()

ob_start();
phpinfo();
$content = ob_get_contents();
ob_end_clean();
$content = ob_get_clean();

$info = explode("\n", $content);

Expand Down
10 changes: 5 additions & 5 deletions src/Templating/Helper/DateTimeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function formatDate($date, $locale = null, $timezone = null, $dateType =

$formatter = self::createInstance([
'locale' => $locale ?: $this->localeDetector->getLocale(),
'datetype' => null === $dateType ? \IntlDateFormatter::MEDIUM : $dateType,
'datetype' => $dateType ?? \IntlDateFormatter::MEDIUM,
'timetype' => \IntlDateFormatter::NONE,
'timezone' => $timezone ?: $this->timezoneDetector->getTimezone(),
'calendar' => \IntlDateFormatter::GREGORIAN,
Expand All @@ -85,8 +85,8 @@ public function formatDateTime($datetime, $locale = null, $timezone = null, $dat

$formatter = self::createInstance([
'locale' => $locale ?: $this->localeDetector->getLocale(),
'datetype' => null === $dateType ? \IntlDateFormatter::MEDIUM : $dateType,
'timetype' => null === $timeType ? \IntlDateFormatter::MEDIUM : $timeType,
'datetype' => $dateType ?? \IntlDateFormatter::MEDIUM,
'timetype' => $timeType ?? \IntlDateFormatter::MEDIUM,
'timezone' => $timezone ?: $this->timezoneDetector->getTimezone(),
'calendar' => \IntlDateFormatter::GREGORIAN,
]);
Expand All @@ -109,7 +109,7 @@ public function formatTime($time, $locale = null, $timezone = null, $timeType =
$formatter = self::createInstance([
'locale' => $locale ?: $this->localeDetector->getLocale(),
'datetype' => \IntlDateFormatter::NONE,
'timetype' => null === $timeType ? \IntlDateFormatter::MEDIUM : $timeType,
'timetype' => $timeType ?? \IntlDateFormatter::MEDIUM,
'timezone' => $timezone ?: $this->timezoneDetector->getTimezone(),
'calendar' => \IntlDateFormatter::GREGORIAN,
]);
Expand All @@ -119,7 +119,7 @@ public function formatTime($time, $locale = null, $timezone = null, $timeType =

/**
* @param \DateTime|\DateTimeInterface|string|int $datetime
* @param $pattern
* @param string $pattern
* @param string|null $locale
* @param string|null $timezone
*
Expand Down
4 changes: 2 additions & 2 deletions src/Templating/Helper/LocaleHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function country($code, $locale = null)
return $name ? $this->fixCharset($name) : '';
}

return Countries::getName($code, $locale ?: $this->localeDetector->getLocale());
return $this->fixCharset(Countries::getName($code, $locale ?: $this->localeDetector->getLocale()));
}

/**
Expand Down Expand Up @@ -82,7 +82,7 @@ public function locale($code, $locale = null)
return $name ? $this->fixCharset($name) : '';
}

return Locales::getName($code, $locale ?: $this->localeDetector->getLocale());
return $this->fixCharset(Locales::getName($code, $locale ?: $this->localeDetector->getLocale()));
}

/**
Expand Down
18 changes: 9 additions & 9 deletions src/Templating/Helper/NumberHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function formatPercent($number, array $attributes = [], array $textAttrib
{
$methodArgs = array_pad(\func_get_args(), 5, null);

list($locale, $symbols) = $this->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);
[$locale, $symbols] = $this->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);

return $this->format($number, \NumberFormatter::PERCENT, $attributes, $textAttributes, $symbols, $locale);
}
Expand All @@ -89,7 +89,7 @@ public function formatDuration($number, array $attributes = [], array $textAttri
{
$methodArgs = array_pad(\func_get_args(), 5, null);

list($locale, $symbols) = $this->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);
[$locale, $symbols] = $this->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);

return $this->format($number, \NumberFormatter::DURATION, $attributes, $textAttributes, $symbols, $locale);
}
Expand All @@ -109,7 +109,7 @@ public function formatDecimal($number, array $attributes = [], array $textAttrib
{
$methodArgs = array_pad(\func_get_args(), 5, null);

list($locale, $symbols) = $this->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);
[$locale, $symbols] = $this->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);

return $this->format($number, \NumberFormatter::DECIMAL, $attributes, $textAttributes, $symbols, $locale);
}
Expand All @@ -129,7 +129,7 @@ public function formatSpellout($number, array $attributes = [], array $textAttri
{
$methodArgs = array_pad(\func_get_args(), 5, null);

list($locale, $symbols) = $this->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);
[$locale, $symbols] = $this->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);

return $this->format($number, \NumberFormatter::SPELLOUT, $attributes, $textAttributes, $symbols, $locale);
}
Expand All @@ -155,7 +155,7 @@ public function formatCurrency($number, $currency, array $attributes = [], array

$methodArgs = array_pad(\func_get_args(), 6, null);

list($locale, $symbols) = $this->normalizeMethodSignature($methodArgs[4], $methodArgs[5]);
[$locale, $symbols] = $this->normalizeMethodSignature($methodArgs[4], $methodArgs[5]);

$formatter = $this->getFormatter($locale ?: $this->localeDetector->getLocale(), \NumberFormatter::CURRENCY, $attributes, $textAttributes, $symbols);

Expand All @@ -177,7 +177,7 @@ public function formatScientific($number, array $attributes = [], array $textAtt
{
$methodArgs = array_pad(\func_get_args(), 5, null);

list($locale, $symbols) = $this->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);
[$locale, $symbols] = $this->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);

return $this->format($number, \NumberFormatter::SCIENTIFIC, $attributes, $textAttributes, $symbols, $locale);
}
Expand All @@ -197,7 +197,7 @@ public function formatOrdinal($number, array $attributes = [], array $textAttrib
{
$methodArgs = array_pad(\func_get_args(), 5, null);

list($locale, $symbols) = $this->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);
[$locale, $symbols] = $this->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);

return $this->format($number, \NumberFormatter::ORDINAL, $attributes, $textAttributes, $symbols, $locale);
}
Expand All @@ -207,7 +207,7 @@ public function formatOrdinal($number, array $attributes = [], array $textAttrib
* attributes.
*
* @param string|float|int $number The number to format
* @param $style
* @param string $style
* @param array $attributes The attributes used by the formatter
* @param array $textAttributes The text attributes used by the formatter
* @param string|null $locale The locale used to format the number
Expand All @@ -218,7 +218,7 @@ public function format($number, $style, array $attributes = [], array $textAttri
{
$methodArgs = array_pad(\func_get_args(), 6, null);

list($locale, $symbols) = $this->normalizeMethodSignature($methodArgs[4], $methodArgs[5]);
[$locale, $symbols] = $this->normalizeMethodSignature($methodArgs[4], $methodArgs[5]);

$formatter = $this->getFormatter($locale ?: $this->localeDetector->getLocale(), $style, $attributes, $textAttributes, $symbols);

Expand Down
2 changes: 1 addition & 1 deletion src/Timezone/LocaleBasedTimezoneDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public function getTimezone()
{
$locale = $this->localeDetector->getLocale();

return isset($this->timezoneMap[$locale]) ? $this->timezoneMap[$locale] : null;
return $this->timezoneMap[$locale] ?? null;
}
}
6 changes: 3 additions & 3 deletions src/Twig/Extension/DateTimeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function getFilters()
}

/**
* @param \Datetime|string|int $date
* @param \DateTime|string|int $date
* @param string|null $pattern
* @param string|null $locale
* @param string|null $timezone
Expand All @@ -65,7 +65,7 @@ public function formatDate($date, $pattern = null, $locale = null, $timezone = n
}

/**
* @param \Datetime|string|int $time
* @param \DateTime|string|int $time
* @param string|null $pattern
* @param string|null $locale
* @param string|null $timezone
Expand All @@ -83,7 +83,7 @@ public function formatTime($time, $pattern = null, $locale = null, $timezone = n
}

/**
* @param \Datetime|string|int $time
* @param \DateTime|string|int $time
* @param string|null $pattern
* @param string|null $locale
* @param string|null $timezone
Expand Down
14 changes: 7 additions & 7 deletions src/Twig/Extension/NumberExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function formatCurrency($number, $currency, array $attributes = [], array
{
$methodArgs = array_pad(\func_get_args(), 6, null);

list($locale, $symbols) = $this->helper->normalizeMethodSignature($methodArgs[4], $methodArgs[5]);
[$locale, $symbols] = $this->helper->normalizeMethodSignature($methodArgs[4], $methodArgs[5]);

return $this->helper->formatCurrency($number, $currency, $attributes, $textAttributes, $symbols, $locale);
}
Expand All @@ -101,7 +101,7 @@ public function formatDecimal($number, array $attributes = [], array $textAttrib
{
$methodArgs = array_pad(\func_get_args(), 5, null);

list($locale, $symbols) = $this->helper->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);
[$locale, $symbols] = $this->helper->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);

return $this->helper->formatDecimal($number, $attributes, $textAttributes, $symbols, $locale);
}
Expand All @@ -121,7 +121,7 @@ public function formatScientific($number, array $attributes = [], array $textAtt
{
$methodArgs = array_pad(\func_get_args(), 5, null);

list($locale, $symbols) = $this->helper->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);
[$locale, $symbols] = $this->helper->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);

return $this->helper->formatScientific($number, $attributes, $textAttributes, $symbols, $locale);
}
Expand All @@ -141,7 +141,7 @@ public function formatSpellout($number, array $attributes = [], array $textAttri
{
$methodArgs = array_pad(\func_get_args(), 5, null);

list($locale, $symbols) = $this->helper->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);
[$locale, $symbols] = $this->helper->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);

return $this->helper->formatSpellout($number, $attributes, $textAttributes, $symbols, $locale);
}
Expand All @@ -161,7 +161,7 @@ public function formatPercent($number, array $attributes = [], array $textAttrib
{
$methodArgs = array_pad(\func_get_args(), 5, null);

list($locale, $symbols) = $this->helper->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);
[$locale, $symbols] = $this->helper->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);

return $this->helper->formatPercent($number, $attributes, $textAttributes, $symbols, $locale);
}
Expand All @@ -181,7 +181,7 @@ public function formatDuration($number, array $attributes = [], array $textAttri
{
$methodArgs = array_pad(\func_get_args(), 5, null);

list($locale, $symbols) = $this->helper->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);
[$locale, $symbols] = $this->helper->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);

return $this->helper->formatDuration($number, $attributes, $textAttributes, $symbols, $locale);
}
Expand All @@ -201,7 +201,7 @@ public function formatOrdinal($number, array $attributes = [], array $textAttrib
{
$methodArgs = array_pad(\func_get_args(), 5, null);

list($locale, $symbols) = $this->helper->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);
[$locale, $symbols] = $this->helper->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);

return $this->helper->formatOrdinal($number, $attributes, $textAttributes, $symbols, $locale);
}
Expand Down
14 changes: 7 additions & 7 deletions tests/Helper/DateTimeHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ protected function setUp(): void
public function testLocale()
{
$localeDetector = $this->createMock(LocaleDetectorInterface::class);
$localeDetector->expects($this->any())
$localeDetector
->method('getLocale')->willReturn('en');

$timezoneDetector = $this->createMock(TimezoneDetectorInterface::class);
$timezoneDetector->expects($this->any())
$timezoneDetector
->method('getTimezone')->willReturn('Europe/Paris');

$helper = new DateTimeHelper($timezoneDetector, 'UTF-8', $localeDetector);
Expand Down Expand Up @@ -79,15 +79,15 @@ public function testLocale()
public function testLocaleTimezones()
{
$localeDetector = $this->createMock(LocaleDetectorInterface::class);
$localeDetector->expects($this->any())
$localeDetector
->method('getLocale')->willReturn('en');

$timezoneDetector = $this->createMock(TimezoneDetectorInterface::class);
$timezoneDetector->expects($this->any())
$timezoneDetector
->method('getTimezone')->willReturn('Europe/London');

$timezoneDetectorWithMapping = $this->createMock(TimezoneDetectorInterface::class);
$timezoneDetectorWithMapping->expects($this->any())
$timezoneDetectorWithMapping
->method('getTimezone')->willReturn('Europe/Paris');

$this->assertSame('Europe/London', $timezoneDetector->getTimezone());
Expand Down Expand Up @@ -118,11 +118,11 @@ public function testLocaleTimezones()
public function testImmutable()
{
$localeDetector = $this->createMock(LocaleDetectorInterface::class);
$localeDetector->expects($this->any())
$localeDetector
->method('getLocale')->willReturn('en');

$timezoneDetector = $this->createMock(TimezoneDetectorInterface::class);
$timezoneDetector->expects($this->any())
$timezoneDetector
->method('getTimezone')->willReturn('Europe/Paris');

$helper = new DateTimeHelper($timezoneDetector, 'UTF-8', $localeDetector);
Expand Down
2 changes: 1 addition & 1 deletion tests/Helper/LocaleHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class LocaleHelperTest extends TestCase
public function getHelper()
{
$localeDetector = $this->createMock(LocaleDetectorInterface::class);
$localeDetector->expects($this->any())
$localeDetector
->method('getLocale')->willReturn('fr');

return new LocaleHelper('UTF-8', $localeDetector);
Expand Down
3 changes: 1 addition & 2 deletions tests/Helper/NumberHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function testExceptionOnInvalidParams()
$this->assertNull($formatter);

$localeDetector = $this->createMock(LocaleDetectorInterface::class);
$localeDetector->expects($this->any())
$localeDetector
->method('getLocale')->willReturn('en');

$helper = new NumberHelper('UTF-8', $localeDetector, ['fraction_digits' => 2], ['negative_prefix' => 'MINUS']);
Expand Down Expand Up @@ -236,7 +236,6 @@ private function createLocaleDetectorMock()
{
$localeDetector = $this->createMock(LocaleDetectorInterface::class);
$localeDetector
->expects($this->any())
->method('getLocale')->willReturn('en')
;

Expand Down
2 changes: 0 additions & 2 deletions tests/Locale/RequestStackDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ public function testGetLocale()
$request = $this->createMock(Request::class);

$requestStack
->expects($this->any())
->method('getCurrentRequest')
->willReturn($request)
;

$request
->expects($this->any())
->method('getLocale')
->willReturn('en')
;
Expand Down
1 change: 0 additions & 1 deletion tests/Timezone/ChainTimezoneDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public function testDetectsTimezoneForUser($detectorsTimezones, $expectedTimezon
foreach ($detectorsTimezones as $timezone) {
$timezoneDetector = $this->createMock(TimezoneDetectorInterface::class);
$timezoneDetector
->expects($this->any())
->method('getTimezone')
->willReturn($timezone)
;
Expand Down
2 changes: 0 additions & 2 deletions tests/Timezone/LocaleBasedTimezoneDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public function testDetectsTimezoneForLocale()
{
$localeDetector = $this->createMock(LocaleDetectorInterface::class);
$localeDetector
->expects($this->any())
->method('getLocale')
->willReturn('fr')
;
Expand All @@ -39,7 +38,6 @@ public function testTimezoneNotDetected()
{
$localeDetector = $this->createMock(LocaleDetectorInterface::class);
$localeDetector
->expects($this->any())
->method('getLocale')
->willReturn('de')
;
Expand Down

0 comments on commit b9ac023

Please sign in to comment.