Completed
Push — nln-php7 ( 6680df...1a6b54 )
by Nicolas
02:06
created

FilePrefixTranslator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 50
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Karma\Generator\NameTranslators;
6
7
use Karma\Generator\NameTranslator;
8
use Karma\Application;
9
use Karma\Generator\ConfigurationFileGenerator;
10
11
class FilePrefixTranslator implements NameTranslator
12
{
13
    private string
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
14
        $masterFilename;
15
    private ?string
16
        $prefixForMasterFile;
17
18 49
    public function __construct()
19
    {
20 49
        $this->masterFilename = Application::DEFAULT_MASTER_FILE;
21 49
        $this->prefixForMasterFile = null;
22 49
    }
23
24 48
    public function translate($file, $variable)
25
    {
26 48
        $prefix = $this->computePrefix($file);
27
28 48
        if($prefix !== null)
29
        {
30 40
            $variable = $prefix . ConfigurationFileGenerator::DELIMITER . $variable;
31
        }
32
33 48
        return $variable;
34
    }
35
36 48
    private function computePrefix($file): ?string
37
    {
38 48
        $prefix = $this->prefixForMasterFile;
39
40 48
        if($file !== $this->masterFilename)
41
        {
42 35
            $prefix = pathinfo($file, PATHINFO_FILENAME);
43
        }
44
45 48
        return $prefix;
46
    }
47
48 15
    public function changeMasterFile(string $masterFilename): void
49
    {
50 15
        $this->masterFilename = $masterFilename;
51 15
    }
52
53 13
    public function setPrefixForMasterFile(string $prefix): void
54
    {
55 13
        $this->prefixForMasterFile = $prefix;
56 13
    }
57
}
58