FileInput::parseName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 2
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