MakeEchoServerConfig::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 38

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 38
ccs 20
cts 20
cp 1
crap 1
rs 9.312
c 0
b 0
f 0
1
<?php
2
3
namespace MadWeb\Initializer\Jobs;
4
5
use Illuminate\Bus\Queueable;
6
use Illuminate\Foundation\Bus\Dispatchable;
7
8
class MakeEchoServerConfig
9
{
10
    use Dispatchable, Queueable;
11
12
    /**
13
     * Config for overriding default echo server values.
14
     */
15
    protected $config;
16
17 12
    public function __construct(array $config = [])
18
    {
19 12
        $this->config = $config;
20 12
    }
21
22
    /**
23
     * Execute the job.
24
     *
25
     * @return string
26
     */
27 12
    public function handle()
28
    {
29 12
        $path = base_path('laravel-echo-server.json');
30 12
        file_put_contents(
31 12
            $path,
32 12
            json_encode(array_replace_recursive([
33 12
                'authHost' => url('/'),
34 12
                'authEndpoint' => '/broadcasting/auth',
35 12
                'database' => 'redis',
36
                'databaseConfig' => [
37
                    'redis' => [
38 12
                        'host' => config('database.redis.default.host'),
39 12
                        'port' => config('database.redis.default.port'),
40
                    ],
41
                    'sqlite' => [
42
                        'databasePath' => '/storage/laravel-echo-server.sqlite',
43
                    ],
44
                ],
45 12
                'devMode' => config('app.debug'),
46 12
                'host' => parse_url(url('/'), PHP_URL_HOST),
47 12
                'port' => 6001,
48 12
                'protocol' => 'http',
49
                'socketio' => [],
50 12
                'sslCertPath' => '',
51 12
                'sslKeyPath' => '',
52 12
                'sslCertChainPath' => '',
53 12
                'sslPassphrase' => '',
54
                'apiOriginAllow' => [
55
                    'allowCors' => false,
56
                    'allowOrigin' => '',
57
                    'allowMethods' => '',
58
                    'allowHeaders' => '',
59
                ],
60 12
            ], $this->config), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
61
        );
62
63 12
        return 'Config file for web-socket server created. File: '.$path;
64
    }
65
}
66