Completed
Pull Request — master (#236)
by
unknown
01:28
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
 * @description Insert the contents of a file into selected element.
4
 * @author      Chris Johnson <[email protected]>
5
 * @copyright   2020 Chris Johnson <[email protected]>
6
 * @license     http://www.opensource.org/licenses/bsd-license.php  BSD License
7
 * @version     1.0
8
 */
9
namespace Transphporm\TSSFunction;
10
11
class File implements \Transphporm\TSSFunction
12
{
13
    private $filePath;
14
15
    public function __construct(\Transphporm\FilePath $filePath)
16
    {
17
        $this->filePath = $filePath;
18
    }
19
20
    /**
21
     * @param array $args
22
     * @param \DomElement|null $element
23
     *
24
     * @return array
25
     * @throws \Exception
26
     */
27
    public function run(array $args, \DomElement $element = null)
28
    {
29
        $fileContents = $args[0];
30
31
        $path = $this->filePath->getFilePath($fileContents);
32
        if (!file_exists($path)) {
33
            throw new \Exception('File does not exist at: ' . $path);
34
        }
35
        $fileContents = file_get_contents($path);
36
37
        return $fileContents;
38
    }
39
}
40