Passed
Push — master ( 90b3af...835a3e )
by Gabriel
14:13
created

AbstractObject   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 12
dl 0
loc 33
rs 10
c 1
b 0
f 1
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromField() 0 7 1
A populateFromField() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace ByTIC\DocumentGenerator\PdfLetters\Writer;
5
6
use ByTIC\DocumentGenerator\PdfLetters\Models\Fields\FieldTrait;
7
use setasign\Fpdi\Tcpdf\Fpdi;
8
9
abstract class AbstractObject
10
{
11
    protected Fpdi $pdf;
12
13
    protected $value;
14
15
    protected $x;
16
    protected $y;
17
18
    /**
19
     * @param FieldTrait $field
20
     * @param Fpdi $pdf
21
     */
22
    public static function fromField($field, $value, $pdf)
23
    {
24
        $instance = new static();
25
        $instance->pdf = $pdf;
26
        $instance->value = $value;
27
        $instance->populateFromField($field);
28
        return $instance;
29
    }
30
31
    /**
32
     * @param FieldTrait $field
33
     * @return void
34
     */
35
    protected function populateFromField($field): void
36
    {
37
        $this->x = $field->x;
38
        $this->y = $field->y;
39
    }
40
41
    abstract public function write();
42
43
}