Completed
Pull Request — master (#233)
by
unknown
03:23
created

File::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * @file File.php
4
 * Replace with one line description.
5
 */
6
namespace Transphporm\TSSFunction;
7
8
class File implements \Transphporm\TSSFunction
9
{
10
    private $filePath;
11
12
    public function __construct(\Transphporm\FilePath $filePath)
13
    {
14
        $this->filePath = $filePath;
15
    }
16
17
    /**
18
     * @param array $args
19
     * @param \DomElement|null $element
20
     *
21
     * @return array
22
     * @throws \Exception
23
     */
24
    public function run(array $args, \DomElement $element = null)
25
    {
26
        $fileContents = $args[0];
27
28
        $path = $this->filePath->getFilePath($fileContents);
29
        if (!file_exists($path)) {
30
            throw new \Exception('File does not exist at: ' . $path);
31
        }
32
        $fileContents = file_get_contents($path);
33
34
        return $fileContents;
35
    }
36
}
37