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.

EnvWriter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 55
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A save() 0 28 5
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 42
    public function __construct($directory, $file = '.env')
21
    {
22 42
        $this->directory = $directory;
23 42
        $this->file = $file;
24 42
    }
25
26
    /**
27
     * Save the given answers to the env file.
28
     *
29
     * @throws WritableException
30
     * @param array $answers
31
     */
32 8
    public function save(array $answers)
33
    {
34 8
        $path = $this->directory . DIRECTORY_SEPARATOR . $this->file;
35
36 8
        if (!file_exists($path)) {
37 6
            if (!is_writable($this->directory)) {
38 4
                throw new WritableException(
39 4
                    sprintf(
40 4
                        'The env file is not present and the directory `%s` is not writeable!',
41 4
                        $this->directory
42
                    )
43
                );
44
            }
45
46 2
            touch($path);
47
        }
48
49 4
        if (!is_writable($path)) {
50 2
            throw new WritableException(sprintf('The env file `%s` is not writeable!', $path));
51
        }
52
53 2
        $text = '';
54 2
        foreach ($answers as $key => $value) {
55 2
            $text .= sprintf("%s=%s\n", $key, $value);
56
        }
57
58 2
        file_put_contents($path, $text);
59 2
    }
60
}
61