mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-18 01:45:07 +02:00
Applied rector with PHP8.1 migration rules
This commit is contained in:
parent
dc6a67c2f0
commit
7ee01d9a05
303 changed files with 1228 additions and 3465 deletions
|
@ -32,25 +32,20 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
|||
*/
|
||||
class AmountFormatter
|
||||
{
|
||||
protected SIFormatter $siFormatter;
|
||||
|
||||
public function __construct(SIFormatter $siFormatter)
|
||||
public function __construct(protected SIFormatter $siFormatter)
|
||||
{
|
||||
$this->siFormatter = $siFormatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the given value using the measurement unit and options.
|
||||
*
|
||||
* @param float|string|int $value
|
||||
* @param MeasurementUnit|null $unit The measurement unit, whose unit symbol should be used for formatting.
|
||||
* If set to null, it is assumed that the part amount is measured in pieces.
|
||||
*
|
||||
* @return string The formatted string
|
||||
*
|
||||
* @throws InvalidArgumentException thrown if $value is not numeric
|
||||
*/
|
||||
public function format($value, ?MeasurementUnit $unit = null, array $options = []): string
|
||||
public function format(float|string|int $value, ?MeasurementUnit $unit = null, array $options = []): string
|
||||
{
|
||||
if (!is_numeric($value)) {
|
||||
throw new InvalidArgumentException('$value must be an numeric value!');
|
||||
|
|
|
@ -29,11 +29,8 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||
*/
|
||||
class MarkdownParser
|
||||
{
|
||||
protected TranslatorInterface $translator;
|
||||
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
public function __construct(protected TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,12 +28,10 @@ use NumberFormatter;
|
|||
|
||||
class MoneyFormatter
|
||||
{
|
||||
protected string $base_currency;
|
||||
protected string $locale;
|
||||
|
||||
public function __construct(string $base_currency)
|
||||
public function __construct(protected string $base_currency)
|
||||
{
|
||||
$this->base_currency = $base_currency;
|
||||
$this->locale = Locale::getDefault();
|
||||
}
|
||||
|
||||
|
@ -45,10 +43,10 @@ class MoneyFormatter
|
|||
* @param int $decimals the number of decimals that should be shown
|
||||
* @param bool $show_all_digits if set to true, all digits are shown, even if they are null
|
||||
*/
|
||||
public function format($value, ?Currency $currency = null, int $decimals = 5, bool $show_all_digits = false): string
|
||||
public function format(string|float $value, ?Currency $currency = null, int $decimals = 5, bool $show_all_digits = false): string
|
||||
{
|
||||
$iso_code = $this->base_currency;
|
||||
if (null !== $currency && !empty($currency->getIsoCode())) {
|
||||
if ($currency instanceof \App\Entity\PriceInformations\Currency && !empty($currency->getIsoCode())) {
|
||||
$iso_code = $currency->getIsoCode();
|
||||
}
|
||||
|
||||
|
|
|
@ -93,11 +93,7 @@ class SIFormatter
|
|||
[$divisor, $symbol] = $this->getPrefixByMagnitude($this->getMagnitude($value));
|
||||
$value /= $divisor;
|
||||
//Build the format string, e.g.: %.2d km
|
||||
if ('' !== $unit || '' !== $symbol) {
|
||||
$format_string = '%.'.$decimals.'f '.$symbol.$unit;
|
||||
} else {
|
||||
$format_string = '%.'.$decimals.'f';
|
||||
}
|
||||
$format_string = '' !== $unit || '' !== $symbol ? '%.'.$decimals.'f '.$symbol.$unit : '%.'.$decimals.'f';
|
||||
|
||||
return sprintf($format_string, $value);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue