Completed
Pull Request — master (#40)
by Бабичев
07:33 queued 03:37
created

WalletService::fee()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Bavix\Wallet\Services;
4
5
use Bavix\Wallet\Exceptions\AmountInvalid;
6
use Bavix\Wallet\Interfaces\Taxing;
7
use Bavix\Wallet\Interfaces\Wallet;
8
9
class WalletService
10
{
11
12
    /**
13
     * Consider the fee that the system will receive.
14
     *
15
     * @param Wallet $wallet
16
     * @param int $amount
17
     * @return int
18
     */
19 16
    public function fee(Wallet $wallet, int $amount): int
20
    {
21 16
        if ($wallet instanceof Taxing) {
22 1
            return (int)($amount * $wallet->getFeePercent() / 100);
23
        }
24
25 16
        return 0;
26
    }
27
28
    /**
29
     * The amount of checks for errors
30
     *
31
     * @param int $amount
32
     * @throws
33
     */
34 30
    public function checkAmount(int $amount): void
35
    {
36 30
        if ($amount < 0) {
37 3
            throw new AmountInvalid(trans('wallet::errors.price_positive'));
0 ignored issues
show
Bug introduced by
It seems like trans('wallet::errors.price_positive') can also be of type array; however, parameter $message of Bavix\Wallet\Exceptions\...tInvalid::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

37
            throw new AmountInvalid(/** @scrutinizer ignore-type */ trans('wallet::errors.price_positive'));
Loading history...
38
        }
39 27
    }
40
41
}
42