LaravelSlackController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 4
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
/*
13
 *   This controller is to be published
14
 *   to App\Http\Controllers folder
15
 */
16
17
namespace App\Http\Controllers;
18
19
use Illuminate\Http\Request;
20
use GuzzleHttp\Client;
21
use Validator;
22
23 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...
24
{
25
    public function __construct()
26
    {
27
        $this->client = new Client();
28
    }
29
30
    /**
31
     *  Shows the landing page of
32
     *  Laravel Slack Package
33
     *
34
    */
35
    public function slackPage()
36
    {
37
        return view('slack.slack');
38
    }
39
40
    /**
41
     *  Get Email, Validate and Send
42
     *  Invite to User
43
     *
44
    */
45
    public function sendSlackInvite(Request $request)
46
    {
47
        $validator= Validator::make($request->all(),[
48
            'email'=>'required|email'
49
            ]);
50
51
        if ($validator->fails())
52
        {
53
            return redirect()->back()->with('error','Sorry! Please enter a valid mail or you have used this mail here');
54
        }else{
55
            $email = $request->input('email');
56
            $this->client->request('POST',
57
                config('LaravelSlack.slack_team_url').'/api/users.admin.invite?t='.time().'&email='.$email.'&token='.config('LaravelSlack.slack_api_token').'&set_active=true&_attempts=1'
58
                );
59
            return redirect()->back()->with('alert','Congratulation! Your Invite has been sent successfully to your mail');
60
        }
61
    }
62
}
63