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

FileSourceBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A buildSource() 0 7 3
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