Passed
Push — master ( 310acb...1a0150 )
by Scott
02:48
created

FileContents::expectFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
crap 1
1
<?php
2
namespace Desmond\functions\core;
3
use Desmond\exceptions\ArgumentException;
4
use Desmond\functions\DesmondFunction;
5
use Desmond\ArgumentHelper;
6
use Desmond\data_types\StringType;
7
8
class FileContents extends DesmondFunction
9
{
10
    use ArgumentHelper;
11
12 187
    public function id()
13
    {
14 187
        return 'file-contents';
15
    }
16
17 6
    public function run(array $args)
18
    {
19 6
        $this->expectFile($args);
20 5
        $path = $args[0];
21 5
        if (!file_exists($path)) {
22 2
            throw new ArgumentException('"file-contents": File not found.');
23
        }
24 3
        $contents = file_get_contents($path);
25 3
        return new StringType($contents, true);
26
    }
27
28 6
    public function expectFile($args)
29
    {
30 6
        $this->expectArguments(
31 6
            'file-contents',
32 6
            [0 => ['Symbol', 'String']],
33
            $args
34
        );
35 5
    }
36
}
37