helpers.php ➔ n2w()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 9
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
use PHPViet\Laravel\NumberToWords\N2WFacade;
4
5 View Code Duplication
if (! function_exists('n2w')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
6
7
    /**
8
     * Hàm hổ trợ chuyển đổi số sang chữ số.
9
     *
10
     * @param int|float $number
11
     * @param string|null $dictionary
12
     * @return string
13
     */
14
    function n2w($number, string $dictionary = null): string
15
    {
16
        $currentDictionary = N2WFacade::$dictionary;
17
        N2WFacade::$dictionary = $dictionary;
0 ignored issues
show
Documentation Bug introduced by
It seems like $dictionary can also be of type string. However, the property $dictionary is declared as type null|object<PHPViet\Numb...ds\DictionaryInterface>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
18
        $result = N2WFacade::toWords($number);
19
        N2WFacade::$dictionary = $currentDictionary;
20
21
        return $result;
22
    }
23
}
24
25 View Code Duplication
if (! function_exists('n2c')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
26
27
    /**
28
     * Hàm hổ trợ chuyển đổi số sang tiền tệ.
29
     *
30
     * @param $number
31
     * @param string|null $dictionary
32
     * @param null|string|array $unit
33
     * @return string
34
     */
35
    function n2c($number, $unit = 'đồng', string $dictionary = null): string
36
    {
37
        $currentDictionary = N2WFacade::$dictionary;
38
        N2WFacade::$dictionary = $dictionary;
0 ignored issues
show
Documentation Bug introduced by
It seems like $dictionary can also be of type string. However, the property $dictionary is declared as type null|object<PHPViet\Numb...ds\DictionaryInterface>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
39
        $result = N2WFacade::toCurrency($number, $unit);
40
        N2WFacade::$dictionary = $currentDictionary;
41
42
        return $result;
43
    }
44
}
45