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.

ProgressiveBillInterpreter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 44
ccs 27
cts 27
cp 1
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A interpret() 0 35 5
A __construct() 0 4 1
1
<?php
2
3
namespace BillingBoss\Interpreter;
4
5
use BillingBoss\BillContext;
6
use BillingBoss\AbstractBillInterpreter;
7
8
/**
9
 * Progressive bill interpreter
10
 *
11
 * @package   BillingBoss
12
 * @link      https://github.com/ranskills/billing-boss-php
13
 * @copyright Copyright (c) 2018 Ransford Ako Okpoti
14
 * @license   Refer to the LICENSE distributed with this library
15
 * @since     1.0.0
16
 */
17
final class ProgressiveBillInterpreter extends AbstractBillInterpreter
18
{
19
20 5
    public function __construct()
21
    {
22 5
        parent::__construct('/^(-?\d*\.?\d+)%,\s*(\d*\.?\d+)' .
23 5
        '(\s*>\s*(-?\d*\.?\d+)%,\s*(\d*\.?\d+))*(\s*>\s*(-?\d*\.?\d+)%,\s*(\*))$/');
24 5
    }
25
26 2
    public function interpret(BillContext $context): float
27
    {
28 2
        if (!$this->isValid($context)) {
29 1
            return 0.0;
30
        }
31
32 1
        $parts = preg_split('/\s*>\s*/', $context->getStructure());
33 1
        $billableAmount = $context->getAmount();
34 1
        $percentageBillInterpreter = new PercentageBillInterpreter();
35 1
        $percentageCtxt = new BillContext(0, '0%');
36 1
        $bill = 0;
37
38 1
        foreach ($parts as $part) {
39 1
            if ($billableAmount === 0.0) {
40 1
                break;
41
            }
42 1
            $matches = [];
43
44 1
            \preg_match('/^((-?\d*\.?\d+)%),\s*(\d*\.?\d+|\*)$/', $part, $matches);
45
            // print_r($matches);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
46 1
            $amount = $matches[3];
47
            
48 1
            if ($amount === '*') {
49 1
                $percentageCtxt->setAmount(floatval($billableAmount))
50 1
                               ->setStructure($matches[1] . ', 1 - * ');
51 1
                $bill += $percentageBillInterpreter->interpret($percentageCtxt);
52
            } else {
53 1
                $billableAmount -= $amount;
54 1
                $percentageCtxt->setAmount($amount)
55 1
                               ->setStructure($matches[1] . ', 1 - * ');
56 1
                $bill += $percentageBillInterpreter->interpret($percentageCtxt);
57
            }
58
        }
59
60 1
        return $bill;
61
    }
62
}
63