GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 636f6e...ab1dd8 )
by Drew
04:13
created

EnvWriter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
namespace Dbtlr\PHPEnvBuilder;
3
4
use Dbtlr\PHPEnvBuilder\Exception\WritableException;
5
6
class EnvWriter
7
{
8
    /** @var string */
9
    protected $directory;
10
11
    /** @var string */
12
    protected $file;
13
14
    /**
15
     * EnvWriter constructor.
16
     *
17
     * @param string $directory
18
     * @param string $file
19
     */
20
    public function __construct($directory, $file = '.env')
21
    {
22
        $this->directory = $directory;
23
        $this->file = $file;
24
    }
25
26
    /**
27
     * Save the given answers to the env file.
28
     *
29
     * @throws WritableException
30
     * @param array $answers
31
     */
32
    public function save(array $answers)
33
    {
34
        $path = $this->directory . DIRECTORY_SEPARATOR . $this->file;
35
36
        if (!file_exists($path)) {
37
            if (!is_writable($this->directory)) {
38
                throw new WritableException(sprintf('The env file is not present and the directory `%s` is not writeable!', $this->directory));
39
            }
40
41
            touch($path);
42
        }
43
44
        if (!is_writable($path)) {
45
            throw new WritableException(sprintf('The env file `%s` is not writeable!', $path));
46
        }
47
48
        $text = '';
49
        foreach ($answers as $key => $value) {
50
            $text .= sprintf("%s=%s\n", $key, $value);
51
        }
52
53
        file_put_contents($path, $text);
54
    }
55
}
56