Passed
Pull Request — master (#267)
by Sam
02:32
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\FileNotFoundException;
6
use Digia\GraphQL\Error\InvariantException;
7
8
/**
9
 * Class FileSourceBuilder
10
 * @package Digia\GraphQL\Language
11
 */
12
class FileSourceBuilder implements SourceBuilderInterface
13
{
14
    /**
15
     * @var string
16
     */
17
    private $filePath;
18
19
    /**
20
     * FileSourceBuilder constructor.
21
     * @param string $filePath
22
     */
23
    public function __construct(string $filePath)
24
    {
25
        $this->filePath = $filePath;
26
    }
27
28
    /**
29
     * @inheritdoc
30
     *
31
     * @throws FileNotFoundException
32
     * @throws InvariantException
33
     */
34
    public function build(): Source
35
    {
36
        if (!\file_exists($this->filePath) || !\is_readable($this->filePath)) {
37
            throw new FileNotFoundException(sprintf('The file %s cannot be found or is not readable', $this->filePath));
38
        }
39
40
        return new Source(\file_get_contents($this->filePath));
41
    }
42
}
43