AbstractBillInterpreter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
c 2
b 0
f 0
dl 0
loc 16
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A isValid() 0 3 1
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