N2WHelper::toCurrency()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
/**
3
 * @link https://github.com/phpviet/yii-number-to-words
4
 *
5
 * @copyright (c) PHP Viet
6
 * @license [MIT](https://opensource.org/licenses/MIT)
7
 */
8
9
namespace phpviet\yii\numberToWords;
10
11
use yii\di\Instance;
12
13
/**
14
 * @author Vuong Minh <[email protected]>
15
 * @since 1.0.0
16
 */
17
class N2WHelper
18
{
19
    /**
20
     * Component hổ trợ việc chuyển đổi số sang chữ số.
21
     *
22
     * @var array|string|callable|N2W
23
     */
24
    protected static $n2w = 'n2w';
25
26
    /**
27
     * Chuyển đổi số sang chữ số.
28
     *
29
     * @param $number
30
     * @param string $dictionary
31
     * @return string
32
     */
33 View Code Duplication
    public static function toWords($number, string $dictionary = N2W::STANDARD_DICTIONARY): string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
    {
35
        $n2w = Instance::ensure(static::$n2w, N2W::class);
0 ignored issues
show
Documentation introduced by
static::$n2w is of type callable, but the function expects a object|string|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
36
        $currentDictionary = $n2w->dictionary;
37
        $n2w->dictionary = $dictionary;
38
        $result = $n2w->toWords($number);
39
        $n2w->dictionary = $currentDictionary;
40
41
        return $result;
42
    }
43
44
    /**
45
     * Chuyển đổi số sang tiền tệ.
46
     *
47
     * @param $number
48
     * @param string $unit
49
     * @param string $dictionary
50
     * @return string
51
     */
52 View Code Duplication
    public static function toCurrency($number, $unit = 'đồng', string $dictionary = N2W::STANDARD_DICTIONARY): string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
    {
54
        $n2w = Instance::ensure(static::$n2w, N2W::class);
0 ignored issues
show
Documentation introduced by
static::$n2w is of type callable, but the function expects a object|string|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
55
        $currentDictionary = $n2w->dictionary;
56
        $n2w->dictionary = $dictionary;
57
        $result = $n2w->toCurrency($number, $unit);
58
        $n2w->dictionary = $currentDictionary;
59
60
        return $result;
61
    }
62
}
63