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
Pull Request — master (#11)
by TJ
02:18
created

Installer::writeConfig()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 2
nc 3
nop 2
1
<?php
2
3
namespace Honeybadger\HoneybadgerLaravel;
4
5
use InvalidArgumentException;
6
use Honeybadger\Contracts\Reporter;
7
use sixlive\DotenvEditor\DotenvEditor;
8
use Illuminate\Support\Facades\Artisan;
9
use Honeybadger\HoneybadgerLaravel\Exceptions\TestException;
10
use Honeybadger\HoneybadgerLaravel\Contracts\Installer as InstallerContract;
11
12
class Installer implements InstallerContract
13
{
14
    /**
15
     * @var \Honeybadger\Contracts\Reporter
16
     */
17
    protected $honeybadger;
18
19
    /**
20
     * @param  \Honeybadger\Contracts\Reporter  $honeybadger
21
     */
22
    public function __construct(Reporter $honeybadger)
23
    {
24
        $this->honeybadger = $honeybadger;
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function writeConfig(array $config, string $filePath) : bool
31
    {
32
        try {
33
            $env = new DotenvEditor;
34
            $env->load($filePath);
35
        } catch (InvalidArgumentException $e) {
36
            return false;
37
        }
38
39
        collect($config)->each(function ($value, $key) use ($env) {
40
            $env->set($key, $value);
41
        });
42
43
        return $env->save();
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function sendTestException() : array
50
    {
51
        return $this->honeybadger->notify(new TestException);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function publishLaravelConfig() : bool
58
    {
59
        return Artisan::call('vendor:publish', [
60
            '--provider' => HoneybadgerServiceProvider::class,
61
        ]) === 0;
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function shouldPublishConfig(): bool
68
    {
69
        return ! file_exists(base_path('config/honeybadger.php'));
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function publishLumenConfig(string $stubPath = null): bool
76
    {
77
        if (! is_dir(base_path('config'))) {
78
            mkdir(base_path('config'));
79
        }
80
81
        return copy(
82
            $stubPath ?? __DIR__.'/../config/honeybadger.php',
83
            base_path('config/honeybadger.php')
84
        );
85
    }
86
}
87