FileInput::getFullName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace kalanis\kw_afterload\Manage;
4
5
6
/**
7
 * Class FileInput
8
 * @package kalanis\kw_afterload\Manage
9
 */
10
class FileInput
11
{
12
    public string $fileName = '';
13
    public int $filePosition = 0;
14
    public string $targetDir = '';
15
    public bool $enabled = false;
16
17 5
    public function setData(string $targetDir, string $fileName, bool $enabled): self
18
    {
19 5
        $this->parseName($fileName);
20 5
        $this->targetDir = $targetDir;
21 5
        $this->enabled = $enabled;
22 5
        return $this;
23
    }
24
25 5
    protected function parseName(string $name): void
26
    {
27 5
        if (preg_match('#^(\d+)_(.*)$#', $name, $match)) {
28 1
            $this->filePosition = intval($match[1]);
29 1
            $this->fileName = $match[2];
30
        } else {
31 5
            $this->fileName = $name;
32
        }
33 5
    }
34
35 5
    public function getName(): string
36
    {
37 5
        return $this->filePosition ? sprintf('%03d_%s', intval($this->filePosition), $this->fileName) : $this->fileName ;
38
    }
39
40 5
    public function getFullName(): string
41
    {
42 5
        return $this->targetDir . DIRECTORY_SEPARATOR . $this->getName() ;
43
    }
44
}
45