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

FileSourceBuilder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
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