|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Honeybadger\HoneybadgerLaravel; |
|
4
|
|
|
|
|
5
|
|
|
use InvalidArgumentException; |
|
6
|
|
|
use sixlive\DotenvEditor\DotenvEditor; |
|
7
|
|
|
use Illuminate\Support\Facades\Artisan; |
|
8
|
|
|
use Honeybadger\Contracts\Reporter as Honeybadger; |
|
9
|
|
|
use Honeybadger\HoneybadgerLaravel\Exceptions\TestException; |
|
10
|
|
|
use Honeybadger\HoneybadgerLaravel\Contracts\Installer as InstallerContract; |
|
11
|
|
|
|
|
12
|
|
|
class Installer implements InstallerContract |
|
13
|
|
|
{ |
|
14
|
|
|
protected $honeybadger; |
|
15
|
|
|
|
|
16
|
|
|
public function __construct(Honeybadger $honeybadger) |
|
17
|
|
|
{ |
|
18
|
|
|
$this->honeybadger = $honeybadger; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Write the configurations to dotenv files. |
|
23
|
|
|
* |
|
24
|
|
|
* @param array $config |
|
25
|
|
|
* @param string $file |
|
|
|
|
|
|
26
|
|
|
* @return bool |
|
27
|
|
|
*/ |
|
28
|
|
|
public function writeConfig(array $config, string $filePath) : bool |
|
29
|
|
|
{ |
|
30
|
|
|
try { |
|
31
|
|
|
$env = new DotenvEditor; |
|
32
|
|
|
$env->load($filePath); |
|
33
|
|
|
} catch (InvalidArgumentException $e) { |
|
34
|
|
|
return false; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
collect($config)->each(function ($value, $key) use ($env) { |
|
38
|
|
|
$env->set($key, $value); |
|
39
|
|
|
}); |
|
40
|
|
|
|
|
41
|
|
|
return $env->save(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function sendTestException() : array |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->honeybadger->notify(new TestException); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function publishLaravelConfig() : bool |
|
50
|
|
|
{ |
|
51
|
|
|
return Artisan::call('vendor:publish', [ |
|
52
|
|
|
'--provider' => HoneybadgerServiceProvider::class, |
|
53
|
|
|
]) === 0; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function shouldPublishConfig(): bool |
|
57
|
|
|
{ |
|
58
|
|
|
return ! file_exists(base_path('config/honeybadger.php')); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function publishLumenConfig(string $stubPath = ''): bool |
|
62
|
|
|
{ |
|
63
|
|
|
if (! is_dir(base_path('config'))) { |
|
64
|
|
|
mkdir(base_path('config')); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return copy( |
|
68
|
|
|
$stubPath ?? __DIR__.'/../../config/honeybadger.php', |
|
69
|
|
|
base_path('config/honeybadger.php') |
|
70
|
|
|
); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.