SettingController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace App\Http\Controllers\API;
4
5
use App\Http\Requests\API\SettingRequest;
6
use App\Models\Setting;
7
use App\Services\MediaSyncService;
8
use Exception;
9
use Illuminate\Http\JsonResponse;
10
11
/**
12
 * @group 8. Settings
13
 */
14
class SettingController extends Controller
15
{
16
    private $mediaSyncService;
17
18 1
    public function __construct(MediaSyncService $mediaSyncService)
19
    {
20 1
        $this->mediaSyncService = $mediaSyncService;
21 1
    }
22
23
    /**
24
     * Save the application settings.
25
     *
26
     * Save the application settings. Right now there's only one setting to be saved (`media_path`).
27
     *
28
     * @bodyParam media_path string required Absolute path to the media folder. Example: /var/www/media/
29
     *
30
     * @response []
31
     *
32
     * @throws Exception
33
     *
34
     * @return JsonResponse
35
     */
36 1
    public function store(SettingRequest $request)
37
    {
38 1
        Setting::set('media_path', rtrim(trim($request->media_path), '/'));
39
40
        // In a next version we should opt for a "MediaPathChanged" event,
41
        // but let's just do this async now.
42 1
        $this->mediaSyncService->sync();
43
44 1
        return response()->json();
45
    }
46
}
47