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.
Completed
Push — master ( 3a3beb...943a46 )
by Ransford
04:49 queued 11s
created

FlatRateBillInterpreter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace BillingBoss\Interpreter;
4
5
use BillingBoss\Exception\RangeException;
6
use BillingBoss\Expr;
7
use BillingBoss\BillContext;
8
use BillingBoss\AbstractBillInterpreter;
9
use BillingBoss\RangeHelper;
10
use BillingBoss\Traits\RangeValidityCheck;
11
12
/**
13
 * Flat rate bill interpreter
14
 *
15
 * @package   BillingBoss
16
 * @link      https://github.com/ranskills/billing-boss-php
17
 * @copyright Copyright (c) 2018 Ransford Ako Okpoti
18
 * @license   Refer to the LICENSE distributed with this library
19
 * @since     1.0.0
20
 */
21
final class FlatRateBillInterpreter extends AbstractBillInterpreter
22
{
23
    use RangeValidityCheck;
24
25
    private const EXPRESSION = Expr::POSITIVE_NUMBER .
26
                               Expr::COMMA .
27
                               Expr::RANGE;
28
29 5
    public function __construct()
30
    {
31 5
        parent::__construct(sprintf('/^(%1$s)(%2$s%1$s)*$/', self::EXPRESSION, Expr::PIPE));
32 5
    }
33
34
    /**
35
     * @param BillContext $context
36
     * @return float
37
     * @throws RangeException
38
     */
39 4
    public function interpret(BillContext $context): float
40
    {
41 4
        if (!$this->isValid($context)) {
42 1
            return 0;
43
        }
44 2
        $bill = 0.0;
45
46 2
        $parts = preg_split(sprintf('/%s/', Expr::PIPE), $context->getStructure());
47 2
        $len = $parts === false ? 0 : count($parts);
48
49 2
        for ($i = 0; $i < $len; $i++) {
50 2
            $range = $this->ranges[$i];
51 2
            $matches = [];
52
53 2
            \preg_match(sprintf('/^%s$/', self::EXPRESSION), $parts[$i], $matches);
54
55 2
            $amount = $context->getAmount();
56 2
            if (RangeHelper::isInRange($range, $amount)) {
57 2
                $bill = $matches[1];
58 2
                break;
59
            }
60
        }
61
62 2
        return $bill;
63
    }
64
}
65