LaravelSlackController::sendSlackInvite()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 17
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 17
loc 17
rs 9.4285
cc 2
eloc 10
nc 2
nop 1
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