Test Setup Failed
Pull Request — master (#1)
by Claudson
09:10 queued 02:23
created

Bill   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 11
eloc 21
c 2
b 0
f 0
dl 0
loc 88
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setBarcode() 0 5 1
A isWritableLineValid() 0 3 1
A isBarcodeValid() 0 3 1
A barcodeToWritableLine() 0 3 1
A __construct() 0 4 1
A setWritableLine() 0 5 1
A getWritableLine() 0 7 2
A writableLineToBarcode() 0 3 1
A getBarcode() 0 7 2
1
<?php
2
3
namespace Claudsonm\BoletoWinner;
4
5
use Claudsonm\BoletoWinner\Converters\Converter;
6
use Claudsonm\BoletoWinner\Validators\Validator;
7
8
abstract class Bill
9
{
10
    protected string $writableLine;
11
    protected string $barcode;
12
    protected Validator $validator;
13
    protected Converter $converter;
14
15
    public function __construct()
16
    {
17
        $this->converter = $this->useConverter();
18
        $this->validator = $this->useValidator();
19
    }
20
21
    public function setBarcode(string $barcode): self
22
    {
23
        $this->barcode = $barcode;
24
25
        return $this;
26
    }
27
28
    public function setWritableLine(string $writableLine): self
29
    {
30
        $this->writableLine = $writableLine;
31
32
        return $this;
33
    }
34
35
    public function getWritableLine(): string
36
    {
37
        if (empty($this->writableLine)) {
38
            $this->barcodeToWritableLine();
39
        }
40
41
        return $this->writableLine;
42
    }
43
44
    public function getBarcode(): string
45
    {
46
        if (empty($this->barcode)) {
47
            $this->writableLineToBarcode();
48
        }
49
50
        return $this->barcode;
51
    }
52
53
    /**
54
     * Determines via the delegated validator if the writable line is valid.
55
     */
56
    public function isWritableLineValid(): bool
57
    {
58
        return $this->validator->verifyWritableLine($this->writableLine);
59
    }
60
61
    /**
62
     * Determines via the delegated validator if the barcode is valid.
63
     */
64
    public function isBarcodeValid(): bool
65
    {
66
        return $this->validator->verifyBarcode($this->barcode);
67
    }
68
69
    /**
70
     * Fills the writable line property with the output of the delegated
71
     * converter strategy class.
72
     */
73
    protected function barcodeToWritableLine(): void
74
    {
75
        $this->setWritableLine($this->converter->toWritableLine($this));
76
    }
77
78
    /**
79
     * Fills the barcode property with the output of the delegated converter
80
     * strategy class.
81
     */
82
    protected function writableLineToBarcode(): void
83
    {
84
        $this->setBarcode($this->converter->toBarcode($this));
85
    }
86
87
    /**
88
     * Defines which converter strategy class is used with the bill instance.
89
     */
90
    abstract protected function useConverter(): Converter;
91
92
    /**
93
     * Defines which validator strategy class is used with the bill instance.
94
     */
95
    abstract protected function useValidator(): Validator;
96
}
97