AbstractBillInterpreter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace BillingBoss;
4
5
use BillingBoss\BillContext;
6
use BillingBoss\BillInterpreter;
7
8
/**
9
 * An abstract class that implements BillInterpreter
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
abstract class AbstractBillInterpreter implements BillInterpreter
18
{
19
    protected $regex;
20
    protected $matches = [];
21
22
    public function __construct(string $regex)
23
    {
24
        $this->regex = $regex;
25
    }
26
27
28
    abstract public function interpret(BillContext $context): float;
29
30
    public function isValid(BillContext $context): bool
31
    {
32
        return preg_match($this->regex, $context->getStructure(), $this->matches) === 1;
33
    }
34
}
35