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.

SteppedBillInterpreter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 30
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A interpret() 0 18 3
1
<?php
2
/**
3
 * Billing Boss
4
 *
5
 * @link      https://github.com/ranskills/billing-boss-php
6
 * @copyright Copyright (c) 2018 Ransford Ako Okpoti
7
 * @license   Refer to the LICENSE distributed with this library
8
 * @since     1.0
9
 */
10
namespace BillingBoss\Interpreter;
11
12
use BillingBoss\Expr;
13
use BillingBoss\BillContext;
14
use BillingBoss\AbstractBillInterpreter;
15
16
/**
17
 * Step bill interpreter.
18
 *
19
 * @package   BillingBoss
20
 * @link      https://github.com/ranskills/billing-boss-php
21
 * @copyright Copyright (c) 2018 Ransford Ako Okpoti
22
 * @license   Refer to the LICENSE distributed with this library
23
 * @since     1.0.0
24
 */
25
final class SteppedBillInterpreter extends AbstractBillInterpreter
26
{
27
    private const EXPRESSION =  Expr::POSITIVE_NUMBER .
28
                                Expr::COMMA .
29
                                Expr::POSITIVE_NUMBER .
30
                                '\+';
31
32 4
    public function __construct()
33
    {
34 4
        parent::__construct(sprintf('/^%s$/', self::EXPRESSION));
35 4
    }
36
37 2
    public function interpret(BillContext $context): float
38
    {
39 2
        if (!$this->isValid($context)) {
40 1
            return 0.0;
41
        }
42 1
        $bill = 0;
43 1
        \preg_match(sprintf('/^%s$/', self::EXPRESSION), $context->getStructure(), $matches);
44
45 1
        $amount = $context->getAmount();
46 1
        $billPerStep = $matches[1];
47 1
        $step = $matches[2];
48
49 1
        while ($amount > 0) {
50 1
            $bill += $billPerStep;
51 1
            $amount -= $step;
52
        }
53
54 1
        return $bill;
55
    }
56
}
57