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

AdminBlacklistController   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 11
eloc 63
dl 0
loc 102
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B edit() 0 76 10
A index() 0 13 1
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Http\Controllers\BasePageController;
6
use App\Models\Category;
7
use Blacklight\Binaries;
8
use Illuminate\Http\Request;
9
10
class AdminBlacklistController extends BasePageController
11
{
12
    /**
13
     * @throws \Exception
14
     */
15
    public function index()
16
    {
17
        $this->setAdminPrefs();
18
        $binaries = new Binaries();
19
20
        $meta_title = $title = 'Binary Black/White List';
21
22
        $binlist = $binaries->getBlacklist(false);
23
        $this->smarty->assign('binlist', $binlist);
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

23
        $this->smarty->/** @scrutinizer ignore-call */ 
24
                       assign('binlist', $binlist);

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...
24
25
        $content = $this->smarty->fetch('binaryblacklist-list.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

25
        /** @scrutinizer ignore-call */ 
26
        $content = $this->smarty->fetch('binaryblacklist-list.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...
26
        $this->smarty->assign(compact('title', 'meta_title', 'content'));
27
        $this->adminrender();
28
    }
29
30
    /**
31
     * @param \Illuminate\Http\Request $request
32
     *
33
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
34
     * @throws \Exception
35
     */
36
    public function edit(Request $request)
37
    {
38
        $this->setAdminPrefs();
39
        $binaries = new Binaries(['Settings' => null]);
40
        $error = '';
41
        $regex = ['id' => '', 'groupname' => '', 'regex' => '', 'description' => '', 'msgcol' => 1, 'status' => 1, 'optype' => 1];
42
        $meta_title = $title = 'Binary Black/White list';
43
44
        switch ($request->input('action') ?? 'view') {
45
            case 'submit':
46
                if ($request->input('groupname') === '') {
47
                    $error = 'Group must be a valid usenet group';
48
                    break;
49
                }
50
51
                if ($request->input('regex') === '') {
52
                    $error = 'Regex cannot be empty';
53
                    break;
54
                }
55
56
                if (empty($request->input('id'))) {
57
                    $binaries->addBlacklist($request->all());
58
                } else {
59
                    $binaries->updateBlacklist($request->all());
60
                }
61
62
                return redirect('admin/binaryblacklist-list');
63
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
64
65
            case 'addtest':
66
                if ($request->has('regex') && $request->has('groupname')) {
67
                    $regex += [
68
                        'groupname' => $request->input('groupname'),
69
                        'regex'     => $request->input('regex'),
70
                        'ordinal'   => 1,
71
                        'status'    => 1,
72
                    ];
73
                }
74
                break;
75
76
            case 'view':
77
            default:
78
                if ($request->has('id')) {
79
                    $title = 'Binary Black/Whitelist Edit';
80
                    $regex = $binaries->getBlacklistByID($request->input('id'));
81
                } else {
82
                    $title = 'Binary Black/Whitelist Add';
83
                    $regex += [
84
                        'status' => 1,
85
                        'optype' => 1,
86
                        'msgcol' => 1,
87
                    ];
88
                }
89
                break;
90
        }
91
92
        $this->smarty->assign(
93
            [
94
                'error'        => $error,
95
                'regex'        => $regex,
96
                'status_ids'   => [Category::STATUS_ACTIVE, Category::STATUS_INACTIVE],
97
                'status_names' => ['Yes', 'No'],
98
                'optype_ids'   => [1, 2],
99
                'optype_names' => ['Black', 'White'],
100
                'msgcol_ids'   => [
101
                    Binaries::BLACKLIST_FIELD_SUBJECT,
102
                    Binaries::BLACKLIST_FIELD_FROM,
103
                    Binaries::BLACKLIST_FIELD_MESSAGEID,
104
                ],
105
                'msgcol_names' => ['Subject', 'Poster', 'MessageId'],
106
            ]
107
        );
108
109
        $content = $this->smarty->fetch('binaryblacklist-edit.tpl');
110
        $this->smarty->assign(compact('title', 'meta_title', 'content'));
111
        $this->adminrender();
112
    }
113
}
114