FileInfo::getRelativePathname()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Openl10n\Cli\File;
4
5
class FileInfo
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $rootDirectory;
11
12
    /**
13
     * @var Pattern
14
     */
15
    protected $pattern;
16
17
    /**
18
     * @var array
19
     */
20
    protected $attributes;
21
22
    public function __construct($rootDirectory, Pattern $pattern, array $attributes)
23
    {
24
        $this->rootDirectory = $rootDirectory;
25
        $this->pattern = $pattern;
26
        $this->attributes = $attributes;
27
    }
28
29
    public function getAbsolutePathname()
30
    {
31
        return realpath($this->rootDirectory.DIRECTORY_SEPARATOR.$this->getPathname());
32
    }
33
34
    public function getRelativePathname()
35
    {
36
        return $this->getPathname();
37
    }
38
39
    public function getPathname(array $usingAttributes = array())
40
    {
41
        $attributes = array_merge($this->attributes, $usingAttributes);
42
43
        return $this->pattern->toString($attributes);
44
    }
45
46
    public function getAttribute($name)
47
    {
48
        if (!isset($this->attributes[$name])) {
49
            throw new \InvalidArgumentException(sprintf('Attribute %s does not exist', $name));
50
        }
51
52
        return $this->attributes[$name];
53
    }
54
}
55