SettingController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 6
c 0
b 0
f 0
dl 0
loc 31
ccs 7
cts 7
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A store() 0 9 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