Skip to content

Commit

Permalink
Move deprecations to constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
phansys committed Jun 13, 2020
1 parent 30c68e2 commit e004e33
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 99 deletions.
37 changes: 10 additions & 27 deletions src/Templating/Helper/LocaleHelper.php
Expand Up @@ -41,6 +41,16 @@ public function __construct(string $charset, LocaleDetectorInterface $localeDete
parent::__construct($charset, $localeDetector);

$this->intlExtension = $intlExtension;

// NEXT_MAJOR: Remove the ability to allow null values at argument 3 and remove the following lines in this method.
if (null === $intlExtension) {
@trigger_error(sprintf(
'Not passing an instance of "%s" as argument 3 for "%s()" is deprecated since sonata-project/intl-bundle 2.x.'
.' and will throw an exception since version 3.x.',
IntlExtension::class,
__METHOD__
));
}
}

/**
Expand All @@ -55,15 +65,6 @@ public function country($code, $locale = null)
return $this->fixCharset($this->intlExtension->getCountryName($code, $locale ?: $this->localeDetector->getLocale()));
}

// NEXT_MAJOR: Execute the previous block unconditionally and remove following lines in this method.

@trigger_error(sprintf(
'Not passing an instance of "%s" as argument 3 for %s::__construct() is deprecated since sonata-project/intl-bundle 2.x.'
.' and will throw an exception since version 3.x.',
IntlExtension::class,
__CLASS__
));

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

Expand All @@ -79,15 +80,6 @@ public function language($code, $locale = null)
$this->fixCharset($this->intlExtension->getLanguageName($code, $locale));
}

// NEXT_MAJOR: Execute the previous block unconditionally and remove following lines in this method.

@trigger_error(sprintf(
'Not passing an instance of "%s" as argument 3 for %s::__construct() is deprecated since sonata-project/intl-bundle 2.x.'
.' and will throw an exception since version 3.x.',
IntlExtension::class,
__CLASS__
));

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

Expand All @@ -103,15 +95,6 @@ public function locale($code, $locale = null)
$this->fixCharset($this->intlExtension->getLocaleName($code, $locale));
}

// NEXT_MAJOR: Execute the previous block unconditionally and remove following lines in this method.

@trigger_error(sprintf(
'Not passing an instance of "%s" as argument 3 for %s::__construct() is deprecated since sonata-project/intl-bundle 2.x.'
.' and will throw an exception since version 3.x.',
IntlExtension::class,
__CLASS__
));

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

Expand Down
82 changes: 10 additions & 72 deletions src/Templating/Helper/NumberHelper.php
Expand Up @@ -61,6 +61,16 @@ public function __construct($charset, LocaleDetectorInterface $localeDetector, a
$this->textAttributes = $textAttributes;
$this->symbols = $symbols;
$this->intlExtension = $intlExtension;

// NEXT_MAJOR: Remove the ability to allow null values at argument 6 and remove the following lines in this method.
if (null === $intlExtension) {
@trigger_error(sprintf(
'Not passing an instance of "%s" as argument 6 for "%s()" is deprecated since sonata-project/intl-bundle 2.x.'
.' and will throw an exception in version 3.x.',
IntlExtension::class,
__METHOD__
));
}
}

/**
Expand All @@ -87,15 +97,6 @@ public function formatPercent($number, array $attributes = [], array $textAttrib
return $this->fixCharset($intlExtension->formatNumberStyle('percent', $number, $attributes, 'default', $locale ?: $this->localeDetector->getLocale()));
}

// NEXT_MAJOR: Execute the previous block unconditionally and remove following lines in this method.

@trigger_error(sprintf(
'Not passing an instance of "%s" as argument 6 for %s::__construct() is deprecated since sonata-project/intl-bundle 2.x.'
.' and will throw an exception in version 3.x.',
IntlExtension::class,
__CLASS__
));

return $this->format($number, \NumberFormatter::PERCENT, $attributes, $textAttributes, $symbols, $locale);
}

Expand Down Expand Up @@ -123,15 +124,6 @@ public function formatDuration($number, array $attributes = [], array $textAttri
return $this->fixCharset($intlExtension->formatNumberStyle('duration', $number, $attributes, 'default', $locale ?: $this->localeDetector->getLocale()));
}

// NEXT_MAJOR: Execute the previous block unconditionally and remove following lines in this method.

@trigger_error(sprintf(
'Not passing an instance of "%s" as argument 6 for %s::__construct() is deprecated since sonata-project/intl-bundle 2.x.'
.' and will throw an exception in version 3.x.',
IntlExtension::class,
__CLASS__
));

return $this->format($number, \NumberFormatter::DURATION, $attributes, $textAttributes, $symbols, $locale);
}

Expand Down Expand Up @@ -159,15 +151,6 @@ public function formatDecimal($number, array $attributes = [], array $textAttrib
return $this->fixCharset($intlExtension->formatNumberStyle('decimal', $number, $attributes, 'default', $locale ?: $this->localeDetector->getLocale()));
}

// NEXT_MAJOR: Execute the previous block unconditionally and remove following lines in this method.

@trigger_error(sprintf(
'Not passing an instance of "%s" as argument 6 for %s::__construct() is deprecated since sonata-project/intl-bundle 2.x.'
.' and will throw an exception in version 3.x.',
IntlExtension::class,
__CLASS__
));

return $this->format($number, \NumberFormatter::DECIMAL, $attributes, $textAttributes, $symbols, $locale);
}

Expand Down Expand Up @@ -195,15 +178,6 @@ public function formatSpellout($number, array $attributes = [], array $textAttri
return $this->fixCharset($intlExtension->formatNumberStyle('spellout', $number, $attributes, 'default', $locale ?: $this->localeDetector->getLocale()));
}

// NEXT_MAJOR: Execute the previous block unconditionally and remove following lines in this method.

@trigger_error(sprintf(
'Not passing an instance of "%s" as argument 6 for %s::__construct() is deprecated since sonata-project/intl-bundle 2.x.'
.' and will throw an exception in version 3.x.',
IntlExtension::class,
__CLASS__
));

return $this->format($number, \NumberFormatter::SPELLOUT, $attributes, $textAttributes, $symbols, $locale);
}

Expand Down Expand Up @@ -232,15 +206,6 @@ public function formatCurrency($number, $currency, array $attributes = [], array
return $this->fixCharset($intlExtension->formatCurrency($number, $currency, $attributes, $locale ?: $this->localeDetector->getLocale()));
}

// NEXT_MAJOR: Execute the previous block unconditionally and remove following lines in this method.

@trigger_error(sprintf(
'Not passing an instance of "%s" as argument 6 for %s::__construct() is deprecated since sonata-project/intl-bundle 2.x.'
.' and will throw an exception in version 3.x.',
IntlExtension::class,
__CLASS__
));

// convert Doctrine's decimal type (fixed-point number represented as string) to float for backward compatibility
if (\is_string($number) && is_numeric($number)) {
$number = (float) $number;
Expand Down Expand Up @@ -275,15 +240,6 @@ public function formatScientific($number, array $attributes = [], array $textAtt
return $this->fixCharset($intlExtension->formatNumberStyle('scientific', $number, $attributes, 'default', $locale ?: $this->localeDetector->getLocale()));
}

// NEXT_MAJOR: Execute the previous block unconditionally and remove following lines in this method.

@trigger_error(sprintf(
'Not passing an instance of "%s" as argument 6 for %s::__construct() is deprecated since sonata-project/intl-bundle 2.x.'
.' and will throw an exception in version 3.x.',
IntlExtension::class,
__CLASS__
));

return $this->format($number, \NumberFormatter::SCIENTIFIC, $attributes, $textAttributes, $symbols, $locale);
}

Expand Down Expand Up @@ -311,15 +267,6 @@ public function formatOrdinal($number, array $attributes = [], array $textAttrib
return $this->fixCharset($intlExtension->formatNumberStyle('ordinal', $number, $attributes, 'default', $locale ?: $this->localeDetector->getLocale()));
}

// NEXT_MAJOR: Execute the previous block unconditionally and remove following lines in this method.

@trigger_error(sprintf(
'Not passing an instance of "%s" as argument 6 for %s::__construct() is deprecated since sonata-project/intl-bundle 2.x.'
.' and will throw an exception in version 3.x.',
IntlExtension::class,
__CLASS__
));

return $this->format($number, \NumberFormatter::ORDINAL, $attributes, $textAttributes, $symbols, $locale);
}

Expand Down Expand Up @@ -348,15 +295,6 @@ public function format($number, $style, array $attributes = [], array $textAttri
return $this->fixCharset($intlExtension->formatNumberStyle($style, $number, $attributes, $locale ?: $this->localeDetector->getLocale()));
}

// NEXT_MAJOR: Execute the previous block unconditionally and remove following lines in this method.

@trigger_error(sprintf(
'Not passing an instance of "%s" as argument 6 for %s::__construct() is deprecated since sonata-project/intl-bundle 2.x.'
.' and will throw an exception in version 3.x.',
IntlExtension::class,
__CLASS__
));

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

return $this->fixCharset($formatter->format($number));
Expand Down

0 comments on commit e004e33

Please sign in to comment.