Skip to content
This repository was archived by the owner on Jul 1, 2019. It is now read-only.

Commit 00afdee

Browse files
author
Andrey Helldar
committed
Small optimized code
1 parent 3125c01 commit 00afdee

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"source": "https://github.com/andrey-helldar/DigitText"
2222
},
2323
"require": {
24-
"php": ">=7.0",
24+
"php": ">=7.1",
2525
"ext-intl": "*",
2626
"illuminate/http": "^5.5",
2727
"illuminate/pipeline": "^5.5",

src/DigitText.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class DigitText
5656
*
5757
* @return null|string
5858
*/
59-
public function get($digit = 0.0, string $lang = 'en', bool $is_currency = false)
59+
public function get($digit = 0.0, string $lang = 'en', bool $is_currency = false): ?string
6060
{
6161
$this->setLang($lang);
6262
$this->setCurrency($is_currency);
@@ -99,7 +99,7 @@ private function setCurrency(bool $is_currency = false)
9999
/**
100100
* @return string
101101
*/
102-
private function getResult()
102+
private function getResult(): string
103103
{
104104
$result = $this->getFractional();
105105
$divider = $this->lang === 'de' ? 'und' : ' ';
@@ -118,7 +118,7 @@ private function getResult()
118118
*
119119
* @return array
120120
*/
121-
private function getFractional()
121+
private function getFractional(): array
122122
{
123123
$this->fraction();
124124

@@ -164,7 +164,7 @@ private function fixDigit($digit = null)
164164
*
165165
* @return null|string
166166
*/
167-
private function intl()
167+
private function intl(): ?string
168168
{
169169
if ($this->is_currency && extension_loaded('php_intl')) {
170170
return (new \MessageFormatter($this->lang, '{n, spellout}'))
@@ -208,7 +208,7 @@ private function fraction()
208208
*
209209
* @return string
210210
*/
211-
private function digitReverse($digit = '0')
211+
private function digitReverse($digit = '0'): string
212212
{
213213
return strrev((string) $digit);
214214
}
@@ -221,7 +221,7 @@ private function digitReverse($digit = '0')
221221
*
222222
* @return string
223223
*/
224-
private function digits($digit = 0.0, $id = 0)
224+
private function digits($digit = 0.0, $id = 0): string
225225
{
226226
if ($digit == 0) {
227227
return $this->texts['zero'];
@@ -238,7 +238,7 @@ private function digits($digit = 0.0, $id = 0)
238238
*
239239
* @return string
240240
*/
241-
private function compactDigits($digit = 0.0, $id = 0)
241+
private function compactDigits($digit = 0.0, $id = 0): string
242242
{
243243
$array = str_split((string) $digit, 1);
244244
$result = [];
@@ -268,7 +268,7 @@ private function compactDigits($digit = 0.0, $id = 0)
268268
*
269269
* @return string
270270
*/
271-
private function decline($group = 0, $digit = 0.0)
271+
private function decline($group = 0, $digit = 0.0): string
272272
{
273273
$text = (string) ((int) $digit);
274274
$text = (int) $text[strlen($digit) - 1];
@@ -308,9 +308,9 @@ private function decline($group = 0, $digit = 0.0)
308308
*
309309
* @return string
310310
*/
311-
private function getCurrency(string $content = null)
311+
private function getCurrency(string $content = null): string
312312
{
313-
if (empty($content)) {
313+
if (!$content) {
314314
return '---';
315315
}
316316

@@ -327,10 +327,6 @@ private function getCurrency(string $content = null)
327327
$result = implode(' ', [
328328
trim($content),
329329
$this->texts['currency']['int'],
330-
]);
331-
332-
$result .= implode(' ', [
333-
'',
334330
str_pad((string) $this->surplus, $this->texts['currency']['precision'], '0', STR_PAD_RIGHT),
335331
$this->texts['currency']['fraction'],
336332
]);

tests/DigitTextTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class DigitTextTest extends TestCase
1414

1515
public function __construct()
1616
{
17-
$this->service = (new DigitText());
17+
$this->service = new DigitText;
1818

1919
parent::__construct();
2020
}

0 commit comments

Comments
 (0)