Skip to content

Commit

Permalink
Formatting the code.
Browse files Browse the repository at this point in the history
  • Loading branch information
jurchiks committed Oct 26, 2020
1 parent 176e584 commit 5a005b9
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 274 deletions.
14 changes: 8 additions & 6 deletions src/Speller.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* This class offers a number spelling in various languages.
* It is a work-in-progress and more languages are to be added in future.
* The main and only two public methods are spellNumber() and spellCurrency().
*
* @author Juris Sudmalis
*/
abstract class Speller
Expand All @@ -27,25 +28,25 @@ abstract class Speller
const CURRENCY_US_DOLLAR = 'USD';
const CURRENCY_PL_ZLOTY = 'PLN';

private static $languages = array(
private static $languages = [
self::LANGUAGE_ENGLISH => languages\English::class,
self::LANGUAGE_ESTONIAN => languages\Estonian::class,
self::LANGUAGE_LATVIAN => languages\Latvian::class,
self::LANGUAGE_LITHUANIAN => languages\Lithuanian::class,
self::LANGUAGE_RUSSIAN => languages\Russian::class,
self::LANGUAGE_SPANISH => languages\Spanish::class,
self::LANGUAGE_POLISH => languages\Polish::class,
);
];

private static $currencies = array(
private static $currencies = [
self::CURRENCY_EURO,
self::CURRENCY_BRITISH_POUND,
self::CURRENCY_LATVIAN_LAT,
self::CURRENCY_LITHUANIAN_LIT,
self::CURRENCY_RUSSIAN_ROUBLE,
self::CURRENCY_US_DOLLAR,
self::CURRENCY_PL_ZLOTY,
);
];

protected $minus;
protected $decimalSeparator;
Expand All @@ -60,7 +61,7 @@ private final function __construct()
*/
private static function get($language)
{
static $spellers = array();
static $spellers = [];

$language = strtolower(trim($language));

Expand Down Expand Up @@ -97,7 +98,8 @@ public static function getAcceptedCurrencies()
*
* @param int $number : the number to spell in the specified language
* @param string $language : a two-letter, ISO 639-1 code of the language to spell the number in
* @return string : the whole part as written in words in the specified language plus ISO 639-1 code and decimal part in ##/100 format
* @return string : the whole part as written in words in the specified language plus ISO 639-1 code
* and decimal part in ##/100 format
* @throws InvalidArgumentException if any parameter is invalid
*/
public static function spellNumber($number, $language)
Expand Down
72 changes: 36 additions & 36 deletions src/languages/English.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class English extends Speller

protected function spellHundred($number, $groupOfThrees, $isDecimalPart, $currency)
{
static $tens = array(
static $tens = [
1 => 'ten',
2 => 'twenty',
3 => 'thirty',
Expand All @@ -21,8 +21,8 @@ protected function spellHundred($number, $groupOfThrees, $isDecimalPart, $curren
7 => 'seventy',
8 => 'eighty',
9 => 'ninety',
);
static $teens = array(
];
static $teens = [
11 => 'eleven',
12 => 'twelve',
13 => 'thirteen',
Expand All @@ -32,8 +32,8 @@ protected function spellHundred($number, $groupOfThrees, $isDecimalPart, $curren
17 => 'seventeen',
18 => 'eighteen',
19 => 'nineteen',
);
static $singles = array(
];
static $singles = [
0 => 'zero',
1 => 'one',
2 => 'two',
Expand All @@ -44,7 +44,7 @@ protected function spellHundred($number, $groupOfThrees, $isDecimalPart, $curren
7 => 'seven',
8 => 'eight',
9 => 'nine',
);
];

$text = '';

Expand Down Expand Up @@ -99,36 +99,36 @@ protected function spellExponent($type, $number, $currency)

protected function getCurrencyName($type, $number, $currency)
{
static $names = array(
self::CURRENCY_EURO => array(
'whole' => array('euro', 'euro'),
'decimal' => array('cent', 'cents'),
),
self::CURRENCY_BRITISH_POUND => array(
'whole' => array('pound', 'pounds'),
'decimal' => array('penny', 'pennies'),
),
self::CURRENCY_LATVIAN_LAT => array(
'whole' => array('lat', 'lats'),
'decimal' => array('santim', 'santims'),
),
self::CURRENCY_LITHUANIAN_LIT => array(
'whole' => array('litas', 'litai'),
'decimal' => array('centas', 'centai'),
),
self::CURRENCY_RUSSIAN_ROUBLE => array(
'whole' => array('ruble', 'rubles'),
'decimal' => array('kopek', 'kopeks'),
),
self::CURRENCY_US_DOLLAR => array(
'whole' => array('dollar', 'dollars'),
'decimal' => array('cent', 'cents'),
),
self::CURRENCY_PL_ZLOTY => array(
'whole' => array('zloty', 'zlote'),
'decimal' => array('grosz', 'grosze'),
),
);
static $names = [
self::CURRENCY_EURO => [
'whole' => ['euro', 'euro'],
'decimal' => ['cent', 'cents'],
],
self::CURRENCY_BRITISH_POUND => [
'whole' => ['pound', 'pounds'],
'decimal' => ['penny', 'pennies'],
],
self::CURRENCY_LATVIAN_LAT => [
'whole' => ['lat', 'lats'],
'decimal' => ['santim', 'santims'],
],
self::CURRENCY_LITHUANIAN_LIT => [
'whole' => ['litas', 'litai'],
'decimal' => ['centas', 'centai'],
],
self::CURRENCY_RUSSIAN_ROUBLE => [
'whole' => ['ruble', 'rubles'],
'decimal' => ['kopek', 'kopeks'],
],
self::CURRENCY_US_DOLLAR => [
'whole' => ['dollar', 'dollars'],
'decimal' => ['cent', 'cents'],
],
self::CURRENCY_PL_ZLOTY => [
'whole' => ['zloty', 'zlote'],
'decimal' => ['grosz', 'grosze'],
],
];

if (!isset($names[$currency]))
{
Expand Down
76 changes: 38 additions & 38 deletions src/languages/Estonian.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Estonian extends Speller

protected function spellHundred($number, $groupOfThrees, $isDecimalPart, $currency)
{
static $hundreds = array(
static $hundreds = [
1 => 'ükssada',
2 => 'kakssada',
3 => 'kolmsada',
Expand All @@ -21,8 +21,8 @@ protected function spellHundred($number, $groupOfThrees, $isDecimalPart, $curren
7 => 'seitsesada',
8 => 'kaheksasada',
9 => 'üheksasada',
);
static $tens = array(
];
static $tens = [
1 => 'kümme',
2 => 'kakskümmend',
3 => 'kolmkümmend',
Expand All @@ -32,8 +32,8 @@ protected function spellHundred($number, $groupOfThrees, $isDecimalPart, $curren
7 => 'seitsekümmend',
8 => 'kaheksakümmend',
9 => 'üheksakümmend',
);
static $teens = array(
];
static $teens = [
11 => 'üksteist',
12 => 'kaksteist',
13 => 'kolmteist',
Expand All @@ -43,8 +43,8 @@ protected function spellHundred($number, $groupOfThrees, $isDecimalPart, $curren
17 => 'seitseteist',
18 => 'kaheksateist',
19 => 'üheksateist',
);
static $singles = array(
];
static $singles = [
0 => 'null',
1 => 'üks',
2 => 'kaks',
Expand All @@ -55,7 +55,7 @@ protected function spellHundred($number, $groupOfThrees, $isDecimalPart, $curren
7 => 'seitse',
8 => 'kaheksa',
9 => 'üheksa',
);
];

$text = '';

Expand Down Expand Up @@ -116,36 +116,36 @@ protected function spellExponent($type, $number, $currency)

protected function getCurrencyName($type, $number, $currency)
{
static $names = array(
self::CURRENCY_EURO => array(
'whole' => array('euro', 'eurot'),
'decimal' => array('sent', 'senti'),
),
self::CURRENCY_BRITISH_POUND => array(
'whole' => array('nael', 'naela'),
'decimal' => array('penn', 'penni'),
),
self::CURRENCY_LATVIAN_LAT => array(
'whole' => array('latt', 'latti'),
'decimal' => array('santiim', 'santiimi'),
),
self::CURRENCY_LITHUANIAN_LIT => array(
'whole' => array('litt', 'litti'),
'decimal' => array('sent', 'senti'),
),
self::CURRENCY_RUSSIAN_ROUBLE => array(
'whole' => array('rubla', 'rubla'),
'decimal' => array('kopikas', 'kopikat'),
),
self::CURRENCY_US_DOLLAR => array(
'whole' => array('dollar', 'dollarit'),
'decimal' => array('sent', 'senti'),
),
self::CURRENCY_PL_ZLOTY => array(
'whole' => array('zloty', 'zlote'),
'decimal' => array('grosz', 'grosze'),
),
);
static $names = [
self::CURRENCY_EURO => [
'whole' => ['euro', 'eurot'],
'decimal' => ['sent', 'senti'],
],
self::CURRENCY_BRITISH_POUND => [
'whole' => ['nael', 'naela'],
'decimal' => ['penn', 'penni'],
],
self::CURRENCY_LATVIAN_LAT => [
'whole' => ['latt', 'latti'],
'decimal' => ['santiim', 'santiimi'],
],
self::CURRENCY_LITHUANIAN_LIT => [
'whole' => ['litt', 'litti'],
'decimal' => ['sent', 'senti'],
],
self::CURRENCY_RUSSIAN_ROUBLE => [
'whole' => ['rubla', 'rubla'],
'decimal' => ['kopikas', 'kopikat'],
],
self::CURRENCY_US_DOLLAR => [
'whole' => ['dollar', 'dollarit'],
'decimal' => ['sent', 'senti'],
],
self::CURRENCY_PL_ZLOTY => [
'whole' => ['zloty', 'zlote'],
'decimal' => ['grosz', 'grosze'],
],
];

if (!isset($names[$currency]))
{
Expand Down
Loading

0 comments on commit 5a005b9

Please sign in to comment.