Completed
Push — master ( 9fea99...819409 )
by Carlos C
9s
created

Resolver   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 67
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getDirectory() 0 4 1
A setDirectory() 0 4 1
A getExtension() 0 4 1
A setExtension() 0 4 1
A resolve() 0 7 3
1
<?php
2
namespace EngineWorks\Templates;
3
4
class Resolver
5
{
6
    /** @var string */
7
    private $directory;
8
9
    /** @var string */
10
    private $extension;
11
12
    /**
13
     * Templates constructor.
14
     *
15
     * @param string $directory Locations where templates are
16
     * @param string $extension Templates extension
17
     */
18 24
    public function __construct($directory = '', $extension = 'php')
19
    {
20 24
        $this->setDirectory($directory);
21 24
        $this->setExtension($extension);
22 24
    }
23
24
    /**
25
     * @return string
26
     */
27 3
    public function getDirectory()
28
    {
29 3
        return $this->directory;
30
    }
31
32
    /**
33
     * @param string $directory
34
     */
35 24
    public function setDirectory($directory)
36
    {
37 24
        $this->directory = $directory;
38 24
    }
39
40
    /**
41
     * @return string
42
     */
43 3
    public function getExtension()
44
    {
45 3
        return $this->extension;
46
    }
47
48
    /**
49
     * @param string $extension
50
     */
51 24
    public function setExtension($extension)
52
    {
53 24
        $this->extension = $extension;
54 24
    }
55
56
    /**
57
     * Resolve a filename by its friendly name, the real name will be
58
     * directory + template + extension
59
     *
60
     * @param string $template
61
     * @return string
62
     */
63 12
    public function resolve($template)
64
    {
65 12
        if (0 === strpos($template, '../') || false !== strpos($template, '/../')) {
66 3
            throw new \InvalidArgumentException('The filename try to escape the current path');
67
        }
68 9
        return $this->directory . '/' . $template . '.' . $this->extension;
69
    }
70
}
71