License   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 95.83%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 21
c 1
b 0
f 0
dl 0
loc 55
ccs 23
cts 24
cp 0.9583
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A toFile() 0 7 1
A __construct() 0 8 1
A getPeriod() 0 3 1
A __toString() 0 13 2
A getHolder() 0 3 1
A getTemplate() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace loophp\GrumphpLicenseTask\Entity;
6
7
use Ergebnis\License\File;
8
use Ergebnis\License\Holder;
9
use Ergebnis\License\Period;
10
use Ergebnis\License\Template;
11
use Exception;
12
13
final class License implements LicenseInterface
14
{
15
    private Holder $holder;
16
17
    private Period $period;
18
19
    private Template $template;
20
21 8
    public function __construct(
22
        Template $fileTemplate,
23
        Period $period,
24
        Holder $holder
25
    ) {
26 8
        $this->template = $fileTemplate;
27 8
        $this->period = $period;
28 8
        $this->holder = $holder;
29 8
    }
30
31 1
    public function __toString(): string
32
    {
33 1
        $file = tmpfile();
34
35 1
        if (false === $file) {
36
            throw new Exception('Unable to generate temporary tmp file.');
37
        }
38
39 1
        $path = stream_get_meta_data($file)['uri'];
40
41 1
        $this->toFile($path)->save();
42
43 1
        return (string) file_get_contents($path);
44
    }
45
46 1
    public function getHolder(): Holder
47
    {
48 1
        return $this->holder;
49
    }
50
51 1
    public function getPeriod(): Period
52
    {
53 1
        return $this->period;
54
    }
55
56 1
    public function getTemplate(): Template
57
    {
58 1
        return $this->template;
59
    }
60
61 2
    public function toFile(string $filepath): File
62
    {
63 2
        return File::create(
64 2
            $filepath,
65 2
            $this->template,
66 2
            $this->period,
67 2
            $this->holder
68
        );
69
    }
70
}
71