Passed
Pull Request — master (#267)
by Sam
02:06
created

FileSourceBuilder::buildSource()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Digia\GraphQL\Language;
4
5
use Digia\GraphQL\Error\InvariantException;
6
7
/**
8
 * Class FileSourceBuilder
9
 * @package Digia\GraphQL\Language
10
 */
11
class FileSourceBuilder implements SourceBuilderInterface
12
{
13
    /**
14
     * @var string
15
     */
16
    private $filePath;
17
18
    /**
19
     * FileSourceBuilder constructor.
20
     * @param string $filePath
21
     */
22
    public function __construct(string $filePath)
23
    {
24
        $this->filePath = $filePath;
25
    }
26
27
    /**
28
     * @inheritdoc
29
     * 
30
     * @throws InvariantException
31
     */
32
    public function buildSource(): Source
33
    {
34
        if (!\file_exists($this->filePath) || !\is_readable($this->filePath)) {
35
            throw new InvariantException(sprintf('The file %s cannot be found or is not readable', $this->filePath));
36
        }
37
38
        return new Source(\file_get_contents($this->filePath));
39
    }
40
}
41