Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CS fix and check #36

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ language: php
dist: trusty

php:
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- hhvm

install:
- composer self-update
Expand All @@ -19,3 +17,4 @@ script:

after_script:
- vendor/bin/test-reporter
- vendor/bin/php-cs-fixer fix -v --dry-run --stop-on-violation --using-cache=no src/ --rules=@Symfony
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
}
],
"require": {
"php": ">=5.5"
"php": ">=5.6"
},
"require-dev": {
"phpunit/phpunit": "~4.8.0",
"phpmd/phpmd": "~2.6.0",
"codeclimate/php-test-reporter": "~0.4.0",
"squizlabs/php_codesniffer": "~2.9.0"
"squizlabs/php_codesniffer": "~2.9.0",
"friendsofphp/php-cs-fixer": "^2.10"
},
"autoload": {
"psr-4": {
Expand Down
21 changes: 11 additions & 10 deletions src/CurrencyTransformer/EnglishCurrencyTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class EnglishCurrencyTransformer implements CurrencyTransformer
* @param string $currency
*
* @throws NumberToWordsException
*
* @return string
*/
public function toWords($amount, $currency)
Expand All @@ -35,7 +36,7 @@ public function toWords($amount, $currency)
$decimal = (int) ($amount / 100);
$fraction = $amount % 100;

if ($fraction === 0) {
if (0 === $fraction) {
$fraction = null;
}

Expand All @@ -50,31 +51,31 @@ public function toWords($amount, $currency)
$currencyNames = EnglishDictionary::$currencyNames[$currency];

$return = trim($numberTransformer->toWords($decimal));
$level = ($decimal === 1) ? 0 : 1;
$level = (1 === $decimal) ? 0 : 1;

if ($level > 0) {
if (count($currencyNames[0]) > 1) {
$return .= ' ' . $currencyNames[0][$level];
$return .= ' '.$currencyNames[0][$level];
} else {
$return .= ' ' . $currencyNames[0][0] . 's';
$return .= ' '.$currencyNames[0][0].'s';
}
} else {
$return .= ' ' . $currencyNames[0][0];
$return .= ' '.$currencyNames[0][0];
}

if (null !== $fraction) {
$return .= ' ' . trim($numberTransformer->toWords($fraction));
$return .= ' '.trim($numberTransformer->toWords($fraction));

$level = $fraction === 1 ? 0 : 1;
$level = 1 === $fraction ? 0 : 1;

if ($level > 0) {
if (count($currencyNames[1]) > 1) {
$return .= ' ' . $currencyNames[1][$level];
$return .= ' '.$currencyNames[1][$level];
} else {
$return .= ' ' . $currencyNames[1][0] . 's';
$return .= ' '.$currencyNames[1][0].'s';
}
} else {
$return .= ' ' . $currencyNames[1][0];
$return .= ' '.$currencyNames[1][0];
}
}

Expand Down
23 changes: 11 additions & 12 deletions src/CurrencyTransformer/GermanCurrencyTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use NumberToWords\Exception\NumberToWordsException;
use NumberToWords\Language\German\GermanDictionary;
use NumberToWords\Language\German\GermanExponentGetter;
use NumberToWords\Language\German\GermanTripletTransformer;
use NumberToWords\NumberTransformer\NumberTransformerBuilder;
use NumberToWords\Service\NumberToTripletsConverter;
Expand All @@ -17,6 +16,7 @@ class GermanCurrencyTransformer implements CurrencyTransformer
* @param string $currency
*
* @throws NumberToWordsException
*
* @return string
*/
public function toWords($amount, $currency)
Expand All @@ -26,7 +26,6 @@ public function toWords($amount, $currency)
$tripletTransformer = new GermanTripletTransformer($dictionary);
$exponentInflector = new GermanExponentInflector();


$numberTransformer = (new NumberTransformerBuilder())
->withDictionary($dictionary)
->withWordsSeparatedBy(' ')
Expand All @@ -37,7 +36,7 @@ public function toWords($amount, $currency)
$decimal = (int) ($amount / 100);
$fraction = $amount % 100;

if ($fraction === 0) {
if (0 === $fraction) {
$fraction = null;
}

Expand All @@ -52,35 +51,35 @@ public function toWords($amount, $currency)
$currencyNames = GermanDictionary::$currencyNames[$currency];

$return = trim($numberTransformer->toWords($decimal));
$level = ($decimal === 1) ? 0 : 1;
$level = (1 === $decimal) ? 0 : 1;

if ($level > 0) {
if (count($currencyNames[0]) > 1) {
$return .= ' ' . $currencyNames[0][$level];
$return .= ' '.$currencyNames[0][$level];
} else {
$return .= ' ' . $currencyNames[0][0];
$return .= ' '.$currencyNames[0][0];
// $return .= ' ' . $currencyNames[0][0] . 's';
}
} else {
$return .= ' ' . $currencyNames[0][0];
$return .= ' '.$currencyNames[0][0];
}

if (null !== $fraction) {
$return .= ' '.$dictionary::$and.' ';

$return .= ' ' . trim($numberTransformer->toWords($fraction));
$return .= ' '.trim($numberTransformer->toWords($fraction));

$level = $fraction === 1 ? 0 : 1;
$level = 1 === $fraction ? 0 : 1;

if ($level > 0) {
if (count($currencyNames[1]) > 1) {
$return .= ' ' . $currencyNames[1][$level];
$return .= ' '.$currencyNames[1][$level];
} else {
// $return .= ' ' . $currencyNames[1][0] . 's';
$return .= ' ' . $currencyNames[1][0];
$return .= ' '.$currencyNames[1][0];
}
} else {
$return .= ' ' . $currencyNames[1][0];
$return .= ' '.$currencyNames[1][0];
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/CurrencyTransformer/PolishCurrencyTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class PolishCurrencyTransformer implements CurrencyTransformer
* @param string $currency
*
* @throws NumberToWordsException
*
* @return string
*/
public function toWords($amount, $currency)
Expand All @@ -37,7 +38,7 @@ public function toWords($amount, $currency)
$decimal = (int) ($amount / 100);
$fraction = $amount % 100;

if ($fraction === 0) {
if (0 === $fraction) {
$fraction = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class PortugueseBrazilianCurrencyTransformer implements CurrencyTransformer
{
/**
* @inheritdoc
* {@inheritdoc}
*/
public function toWords($amount, $currency)
{
Expand Down
4 changes: 3 additions & 1 deletion src/CurrencyTransformer/UkrainianCurrencyTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
class UkrainianCurrencyTransformer implements CurrencyTransformer
{
/**
* @param int $amount
* @param int $amount
* @param string $currency
*
* @return string
*
* @throws \NumberToWords\Exception\NumberToWordsException
*/
public function toWords($amount, $currency)
Expand Down
8 changes: 4 additions & 4 deletions src/Language/English/EnglishDictionary.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class EnglishDictionary implements Dictionary
'sixteen',
'seventeen',
'eighteen',
'nineteen'
'nineteen',
];

private static $tens = [
Expand All @@ -35,7 +35,7 @@ class EnglishDictionary implements Dictionary
'sixty',
'seventy',
'eighty',
'ninety'
'ninety',
];

private static $hundred = 'hundred';
Expand Down Expand Up @@ -76,7 +76,7 @@ class EnglishDictionary implements Dictionary
'UAH' => [['hryvna'], ['cent']],
'USD' => [['dollar'], ['cent']],
'YUM' => [['dinars'], ['para']],
'ZAR' => [['rand'], ['cent']]
'ZAR' => [['rand'], ['cent']],
];

/**
Expand Down Expand Up @@ -132,6 +132,6 @@ public function getCorrespondingTeen($teen)
*/
public function getCorrespondingHundred($hundred)
{
return self::$units[$hundred] . ' ' . self::$hundred;
return self::$units[$hundred].' '.self::$hundred;
}
}
4 changes: 2 additions & 2 deletions src/Language/English/EnglishTripletTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function transformToWords($number)
$words[] = $this->dictionary->getCorrespondingHundred($hundreds);
}

if ($tens !== 0 || $units !== 0) {
if (0 !== $tens || 0 !== $units) {
$words[] = $this->getSubHundred($tens, $units);
}

Expand All @@ -52,7 +52,7 @@ private function getSubHundred($tens, $units)
{
$words = [];

if ($tens === 1) {
if (1 === $tens) {
$words[] = $this->dictionary->getCorrespondingTeen($units);
} else {
if ($tens > 0) {
Expand Down
94 changes: 47 additions & 47 deletions src/Language/French/BelgianDictionary.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ class BelgianDictionary
const LANGUAGE_NAME_NATIVE = 'Français';

public static $miscNumbers = [
10 => 'dix',
11 => 'onze',
12 => 'douze',
13 => 'treize',
14 => 'quatorze',
15 => 'quinze',
16 => 'seize',
20 => 'vingt',
30 => 'trente',
40 => 'quarante',
50 => 'cinquante',
60 => 'soixante',
70 => 'septante',
90 => 'nonante',
100 => 'cent'
10 => 'dix',
11 => 'onze',
12 => 'douze',
13 => 'treize',
14 => 'quatorze',
15 => 'quinze',
16 => 'seize',
20 => 'vingt',
30 => 'trente',
40 => 'quarante',
50 => 'cinquante',
60 => 'soixante',
70 => 'septante',
90 => 'nonante',
100 => 'cent',
];

public static $digits = [
Expand All @@ -35,7 +35,7 @@ class BelgianDictionary
6 => 'six',
7 => 'sept',
8 => 'huit',
9 => 'neuf'
9 => 'neuf',
];

public static $zero = 'zéro';
Expand All @@ -46,36 +46,36 @@ class BelgianDictionary
public static $pluralSuffix = 's';

public static $exponent = [
0 => '',
3 => 'mille',
6 => 'million',
9 => 'milliard',
12 => 'trillion',
15 => 'quadrillion',
18 => 'quintillion',
21 => 'sextillion',
24 => 'septillion',
27 => 'octillion',
30 => 'nonillion',
33 => 'decillion',
36 => 'undecillion',
39 => 'duodecillion',
42 => 'tredecillion',
45 => 'quattuordecillion',
48 => 'quindecillion',
51 => 'sexdecillion',
54 => 'septendecillion',
57 => 'octodecillion',
60 => 'novemdecillion',
63 => 'vigintillion',
66 => 'unvigintillion',
69 => 'duovigintillion',
72 => 'trevigintillion',
75 => 'quattuorvigintillion',
78 => 'quinvigintillion',
81 => 'sexvigintillion',
84 => 'septenvigintillion',
87 => 'octovigintillion',
90 => 'novemvigintillion',
0 => '',
3 => 'mille',
6 => 'million',
9 => 'milliard',
12 => 'trillion',
15 => 'quadrillion',
18 => 'quintillion',
21 => 'sextillion',
24 => 'septillion',
27 => 'octillion',
30 => 'nonillion',
33 => 'decillion',
36 => 'undecillion',
39 => 'duodecillion',
42 => 'tredecillion',
45 => 'quattuordecillion',
48 => 'quindecillion',
51 => 'sexdecillion',
54 => 'septendecillion',
57 => 'octodecillion',
60 => 'novemdecillion',
63 => 'vigintillion',
66 => 'unvigintillion',
69 => 'duovigintillion',
72 => 'trevigintillion',
75 => 'quattuorvigintillion',
78 => 'quinvigintillion',
81 => 'sexvigintillion',
84 => 'septenvigintillion',
87 => 'octovigintillion',
90 => 'novemvigintillion',
];
}
Loading