LaravelSlackController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A slackPage() 4 4 1
A sendSlackInvite() 17 17 2

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
/*
4
 * This file is part of the Laravel Slack package.
5
 *
6
 * (c) Gooodness Toluwanimi Kayode <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace GoodnessKay\LaravelSlack;
13
14
use App\Http\Controllers\Controller;
15
use Illuminate\Http\Request;
16
use GuzzleHttp\Client;
17
use Validator;
18
19
20 View Code Duplication
class LaravelSlackController extends Controller
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
21
{
22
    public function __construct()
23
    {
24
        $this->client = new Client();
25
    }
26
27
    /**
28
     *  Shows the landing page of
29
     *  Laravel Slack Package
30
     *
31
    */
32
    public function slackPage()
33
    {
34
        return view('slack.slack');
35
    }
36
37
    /**
38
     *  Get Email, Validate and Send
39
     *  Invite to User
40
     *
41
    */
42
    public function sendSlackInvite(Request $request)
43
    {
44
        $validator= Validator::make($request->all(),[
45
            'email'=>'required|email'
46
            ]);
47
48
        if ($validator->fails())
49
        {
50
            return redirect()->back()->with('error','Sorry! Please enter a valid mail or you have used this mail here');
51
        }else{
52
            $email = $request->input('email');
53
            $this->client->request('POST',
54
                config('LaravelSlack.slack_team_url').'/api/users.admin.invite?t='.time().'&email='.$email.'&token='.config('LaravelSlack.slack_api_token').'&set_active=true&_attempts=1'
55
                );
56
            return redirect()->back()->with('alert','Congratulation! Your Invite has been sent successfully to your mail');
57
        }
58
    }
59
}
60