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

FileContents   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 29
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A id() 0 4 1
A run() 0 10 2
A expectFile() 0 8 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