GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Money   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 20
c 2
b 0
f 0
dl 0
loc 103
rs 10
wmc 11

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 5 1
A currencyFormat() 0 3 1
A shortFormat() 0 3 1
A isSufficient() 0 7 2
A numberFormat() 0 5 2
A __construct() 0 16 4
1
<?php
2
/**
3
 * This file is part of the O2System Reactor package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Reactor\DataStructures\Commons;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Spl\Patterns\Structural\Repository\AbstractRepository;
19
20
/**
21
 * Class Money
22
 * @package O2System\Reactor\DataStructures\Commons
23
 */
24
class Money extends AbstractRepository
25
{
26
    /**
27
     * Money::__construct
28
     *
29
     * @param int $amount
30
     */
31
    public function __construct($amount)
32
    {
33
        $money = [];
34
        if (is_numeric($amount)) {
0 ignored issues
show
introduced by
The condition is_numeric($amount) is always true.
Loading history...
35
            $money[ 'amount' ] = (int)$amount;
36
        } elseif (is_array($amount)) {
37
            $money = $amount;
38
        }
39
40
        (int)$storage[ 'amount' ] = 0;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$storage was never initialized. Although not strictly required by PHP, it is generally a good practice to add $storage = array(); before regardless.
Loading history...
41
        $storage[ 'currency' ] = config()->getItem('units')->currency;
0 ignored issues
show
Bug introduced by
The method getItem() does not exist on O2System\Kernel\DataStructures\Config. Did you maybe mean getIterator()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
        $storage[ 'currency' ] = config()->/** @scrutinizer ignore-call */ getItem('units')->currency;

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
42
43
        $storage = array_merge($storage, $money);
44
        (int)$storage[ 'amount' ] = empty($storage[ 'amount' ]) ? 0 : abs($storage[ 'amount' ]);
45
46
        $this->storage = $storage;
47
    }
48
49
    // ------------------------------------------------------------------------
50
51
    /**
52
     * Money::shortFormat
53
     *
54
     * @param int $decimals
55
     *
56
     * @return string
57
     */
58
    public function shortFormat($decimals = 0)
59
    {
60
        return short_format($this->amount, $decimals);
0 ignored issues
show
Bug Best Practice introduced by
The property amount does not exist on O2System\Reactor\DataStructures\Commons\Money. Since you implemented __get, consider adding a @property annotation.
Loading history...
61
    }
62
63
    // ------------------------------------------------------------------------
64
65
    /**
66
     * Money::numberFormat
67
     *
68
     * @param int    $decimals
69
     * @param string $thousandSeparator
70
     * @param string $decimalSeparator
71
     *
72
     * @return string
73
     */
74
    public function numberFormat($decimals = 0, $thousandSeparator = '.', $decimalSeparator = ',')
0 ignored issues
show
Unused Code introduced by
The parameter $decimalSeparator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

74
    public function numberFormat($decimals = 0, $thousandSeparator = '.', /** @scrutinizer ignore-unused */ $decimalSeparator = ',')

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
75
    {
76
        $decimalSeparator = $thousandSeparator === '.' ? ',' : '.';
77
78
        return number_format($this->amount, $decimals, $decimalSeparator, $thousandSeparator);
0 ignored issues
show
Bug Best Practice introduced by
The property amount does not exist on O2System\Reactor\DataStructures\Commons\Money. Since you implemented __get, consider adding a @property annotation.
Loading history...
79
    }
80
81
    // ------------------------------------------------------------------------
82
83
    /**
84
     * Money::isSufficient
85
     *
86
     * @param int $amount
87
     *
88
     * @return bool
89
     */
90
    public function isSufficient($amount)
91
    {
92
        if ($amount < $this->amount) {
0 ignored issues
show
Bug Best Practice introduced by
The property amount does not exist on O2System\Reactor\DataStructures\Commons\Money. Since you implemented __get, consider adding a @property annotation.
Loading history...
93
            return true;
94
        }
95
96
        return false;
97
    }
98
99
    // ------------------------------------------------------------------------
100
101
    /**
102
     * Money::__toString
103
     *
104
     * @return string
105
     */
106
    public function __toString()
107
    {
108
        loader()->loadHelper('number');
109
110
        return $this->currencyFormat();
111
    }
112
113
    // ------------------------------------------------------------------------
114
115
    /**
116
     * Money::currencyFormat
117
     *
118
     * @param string $locale
119
     * @param string $currency
120
     * @param bool   $addSpace
121
     *
122
     * @return string
123
     */
124
    public function currencyFormat($locale = 'id_ID', $currency = 'IDR', $addSpace = true)
125
    {
126
        return currency_format($this->amount, $locale, $currency, $addSpace);
0 ignored issues
show
Bug Best Practice introduced by
The property amount does not exist on O2System\Reactor\DataStructures\Commons\Money. Since you implemented __get, consider adding a @property annotation.
Loading history...
127
    }
128
}