ParserTrait::maskStubVariables()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Apiato\Core\Generator\Traits;
4
5
/**
6
 * Trait ParserTrait
7
 *
8
 * @author  Johannes Schobel    <[email protected]>
9
 */
10
trait ParserTrait
11
{
12
    /**
13
     * replaces the variables in the path structure with defined values
14
     *
15
     * @param $path
16
     * @param $data
17
     *
18
     * @return mixed
19
     */
20
    public function parsePathStructure($path, $data)
21
    {
22
        $path = str_replace(array_map([$this, 'maskPathVariables'], array_keys($data)), array_values($data), $path);
23
        $path = str_replace('*', $this->parsedFileName, $path);
0 ignored issues
show
Bug introduced by Johannes Schobel
The property parsedFileName does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
24
25
        return $path;
26
    }
27
28
    /**
29
     * replaces the variables in the file structure with defined values
30
     *
31
     * @param $filename
32
     * @param $data
33
     *
34
     * @return mixed
35
     */
36
    public function parseFileStructure($filename, $data)
37
    {
38
        $filename = str_replace(array_map([$this, 'maskFileVariables'], array_keys($data)), array_values($data), $filename);
39
        return $filename;
40
    }
41
42
    /**
43
     * replaces the variables in the stub file with defined values
44
     *
45
     * @param $stub
46
     * @param $data
47
     *
48
     * @return mixed
49
     */
50
    public function parseStubContent($stub, $data)
51
    {
52
        $stub = str_replace(array_map([$this, 'maskStubVariables'], array_keys($data)), array_values($data), $stub);
53
        return $stub;
54
    }
55
56
    private function maskPathVariables($key) {
57
        return '{' . $key . '}';
58
    }
59
60
    private function maskFileVariables($key) {
61
        return '{' . $key . '}';
62
    }
63
64
    private function maskStubVariables($key) {
65
        return '{{' . $key . '}}';
66
    }
67
}
68