Completed
Push — master ( 9b66eb...845b72 )
by Aitor Riba
01:44
created

LaralangController   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 53
Duplicated Lines 7.55 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 0
cbo 0
dl 4
loc 53
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A showLogin() 0 7 3
A login() 4 11 2
A logout() 0 6 1
A showTranslations() 0 4 1
A api() 0 4 1
A deleteTrans() 0 5 1
A editTrans() 0 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Aitor24\Laralang\Controllers;
4
5
use Illuminate\Http\Request;
6
use Aitor24\Laralang\Models\DB_Translation;
7
use App\Http\Controllers\Controller;
8
use Crypt;
9
10
class LaralangController extends Controller
11
{
12
13
    public function showLogin()
14
    {
15
        if (session('laralang.password') && Crypt::decrypt(session('laralang.password')) == config('laralang.default.password')) {
16
            return redirect(Route('laralang::translations'));
17
        }
18
        return view('laralang::login');
19
    }
20
21
    public function login(Request $request)
22
    {
23
        session(['laralang.password' => Crypt::encrypt($request->input('password'))]);
24 View Code Duplication
        if (Crypt::decrypt(session('laralang.password')) != config('laralang.default.password')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
            return redirect(Route('laralang::login'))
26
            ->with('status','Invalid password');
27
        }
28
29
        return redirect(Route('laralang::translations'));
30
31
    }
32
33
    public function logout(Request $request)
34
    {
35
        $request->session()->forget('laralang.password');
36
37
        return redirect(Route('laralang::translations'));
38
    }
39
    public function showTranslations()
40
    {
41
        return view('laralang::translations');
42
    }
43
44
    public function api()
45
    {
46
        return DB_Translation::all();
47
    }
48
49
    public function deleteTrans($id)
50
    {
51
        $trans = DB_Translation::findOrFail($id);
52
        $trans->delete();
53
    }
54
55
    public function editTrans($id, $translation)
56
    {
57
        $trans = DB_Translation::findOrFail($id);
58
        $trans->translation = $translation;
59
        $trans->touch();
60
        $trans->save();
61
    }
62
}
63