Passed
Push — dev ( c55b95...34fb50 )
by Darko
06:54
created

AdminSharingController::index()   C

Complexity

Conditions 12
Paths 34

Size

Total Lines 46
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 46
rs 6.9666
c 0
b 0
f 0
cc 12
nc 34
nop 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Http\Controllers\BasePageController;
6
use App\Models\Sharing;
7
use App\Models\SharingSite;
8
use Illuminate\Http\Request;
9
10
class AdminSharingController extends BasePageController
11
{
12
    /**
13
     * @param \Illuminate\Http\Request $request
14
     *
15
     * @throws \Exception
16
     */
17
    public function index(Request $request)
18
    {
19
        $this->setAdminPrefs();
20
21
        $meta_title = $title = 'Sharing Settings';
22
23
        $allSites = SharingSite::query()->orderByDesc('id')->paginate(config('nntmux.items_per_cover_page'));
24
        if ($allSites->total() === 0) {
25
            $allSites = false;
26
        }
27
28
        $ourSite = Sharing::query()->first();
29
30
        if (! empty($request->all())) {
31
            if (! empty($request->input('sharing_name')) && ! preg_match('/\s+/', $request->input('sharing_name')) && strlen($request->input('sharing_name')) < 255) {
32
                $site_name = trim($request->input('sharing_name'));
33
            } else {
34
                $site_name = $ourSite['site_name'];
35
            }
36
            if (! empty($request->input('sharing_maxpush')) && is_numeric($request->input('sharing_maxpush'))) {
37
                $max_push = trim($request->input('sharing_maxpush'));
38
            } else {
39
                $max_push = $ourSite['max_push'];
40
            }
41
            if (! empty($request->input('sharing_maxpoll')) && is_numeric($request->input('sharing_maxpush'))) {
42
                $max_pull = trim($request->input('sharing_maxpoll'));
43
            } else {
44
                $max_pull = $ourSite['max_pull'];
45
            }
46
            if (! empty($request->input('sharing_maxdownload')) && is_numeric($request->input('sharing_maxdownload'))) {
47
                $max_download = trim($request->input('sharing_maxdownload'));
48
            } else {
49
                $max_download = $ourSite['max_download'];
50
            }
51
            Sharing::query()
52
                ->update(compact('site_name', 'max_push', 'max_pull', 'max_download'));
53
54
            $ourSite = $ourSite = Sharing::query()->first();
0 ignored issues
show
Unused Code introduced by
The assignment to $ourSite is dead and can be removed.
Loading history...
55
        }
56
57
        $this->smarty->assign(['local' => $ourSite, 'sites' => $allSites]);
0 ignored issues
show
Bug introduced by
The method assign() does not exist on Illuminate\Foundation\Application. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
        $this->smarty->/** @scrutinizer ignore-call */ 
58
                       assign(['local' => $ourSite, 'sites' => $allSites]);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
58
59
        $content = $this->smarty->fetch('sharing.tpl');
0 ignored issues
show
Bug introduced by
The method fetch() does not exist on Illuminate\Foundation\Application. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
        /** @scrutinizer ignore-call */ 
60
        $content = $this->smarty->fetch('sharing.tpl');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
60
61
        $this->smarty->assign(compact('title', 'meta_title', 'content'));
62
        $this->adminrender();
63
    }
64
}
65