Passed
Branch master (9fc252)
by Chris
04:36
created
app/SlashCommandHandlers/Jobs/SearchTDTicketJob.php 3 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -104,10 +104,10 @@
 block discarded – undo
104 104
 
105 105
         if ($opencount > 0) {
106 106
           $this
107
-             ->respondToSlack("
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
     public function handle()
16 16
     {
17 17
         $build = \Tremby\LaravelGitVersion\GitVersionHelper::getVersion();
18
-        if( env('TD_SANDBOX') == 'TRUE') {
18
+        if (env('TD_SANDBOX') == 'TRUE') {
19 19
           $env = 'sandbox';
20 20
         }
21 21
         else {
@@ -23,37 +23,37 @@  discard block
 block discarded – undo
23 23
         }
24 24
 
25 25
         $userSession = TDsession::where('s_user_id', $this->request->userId)->first();
26
-        if($userSession != null ) {
26
+        if ($userSession != null) {
27 27
           Log::info('CP_SearchTDTicketJob: Found user session.');
28
-          if($userSession->td_token){
29
-            $TDinstance = new CP_TDinstance( env('TD_BEID'), env('TD_WEBSERVICESKEY'), env('TD_URLROOT'), env('TD_APPID'), $env, (string)$userSession->td_token );
28
+          if ($userSession->td_token) {
29
+            $TDinstance = new CP_TDinstance(env('TD_BEID'), env('TD_WEBSERVICESKEY'), env('TD_URLROOT'), env('TD_APPID'), $env, (string)$userSession->td_token);
30 30
             Log::info('CP_SearchTDTicketJob: CP_TDinstance initialized with existing JWT.');
31 31
           }
32 32
           else {
33
-            $TDinstance = new CP_TDinstance( env('TD_BEID'), env('TD_WEBSERVICESKEY'), env('TD_URLROOT'), env('TD_APPID'), $env );
33
+            $TDinstance = new CP_TDinstance(env('TD_BEID'), env('TD_WEBSERVICESKEY'), env('TD_URLROOT'), env('TD_APPID'), $env);
34 34
             Log::info('CP_SearchTDTicketJob: CP_TDinstance initialized with new JWT.');
35 35
           }
36 36
 
37 37
           Log::info('CP_SearchTDTicketJob: Updating existing CP_TDsession s_token and td_token.');
38
-          $userSession->s_token =  $this->request->token;
38
+          $userSession->s_token = $this->request->token;
39 39
           $userSession->td_token = $TDinstance;
40 40
           $userSession->save();
41 41
         }
42 42
         else {
43 43
           Log::info('CP_SearchTDTicketJob: No user session.');
44 44
           Log::info('CP_SearchTDTicketJob: Creating new user session.');
45
-          $TDinstance = new CP_TDinstance( env('TD_BEID'), env('TD_WEBSERVICESKEY'), env('TD_URLROOT'), env('TD_APPID'), $env );
45
+          $TDinstance = new CP_TDinstance(env('TD_BEID'), env('TD_WEBSERVICESKEY'), env('TD_URLROOT'), env('TD_APPID'), $env);
46 46
           Log::info('CP_SearchTDTicketJob: New CP_TDinstance initialized.');
47 47
           $userSession = new TDsession;
48 48
           Log::info('CP_SearchTDTicketJob: New CP_TDsession initialized.');
49 49
           Log::info('CP_SearchTDTicketJob: Updating CP_TDsession s_token and td_token.');
50 50
           $userSession->s_user_id = $this->request->userId;
51
-          $userSession->s_token =  $this->request->token;
51
+          $userSession->s_token = $this->request->token;
52 52
           $userSession->td_token = $TDinstance;
53 53
           $userSession->save();
54 54
         }
55 55
 
56
-        if($TDinstance->checkToken()){
56
+        if ($TDinstance->checkToken()) {
57 57
           Log::info('CP_SearchTDTicketJob: There is a token.');
58 58
           $auth = true;
59 59
           $tickets = $TDinstance->searchTicketsName($this->request->text);
@@ -69,12 +69,12 @@  discard block
 block discarded – undo
69 69
         if (!count($tickets) && $auth) {
70 70
             return $this->respondToSlack("
Please login to merge, or discard this patch.
Braces   +7 added lines, -14 removed lines patch added patch discarded remove patch
@@ -17,8 +17,7 @@  discard block
 block discarded – undo
17 17
         $build = \Tremby\LaravelGitVersion\GitVersionHelper::getVersion();
18 18
         if( env('TD_SANDBOX') == 'TRUE') {
19 19
           $env = 'sandbox';
20
-        }
21
-        else {
20
+        } else {
22 21
           $env = 'prod';
23 22
         }
24 23
 
@@ -28,8 +27,7 @@  discard block
 block discarded – undo
28 27
           if($userSession->td_token){
29 28
             $TDinstance = new CP_TDinstance( env('TD_BEID'), env('TD_WEBSERVICESKEY'), env('TD_URLROOT'), env('TD_APPID'), $env, (string)$userSession->td_token );
30 29
             Log::info('CP_SearchTDTicketJob: CP_TDinstance initialized with existing JWT.');
31
-          }
32
-          else {
30
+          } else {
33 31
             $TDinstance = new CP_TDinstance( env('TD_BEID'), env('TD_WEBSERVICESKEY'), env('TD_URLROOT'), env('TD_APPID'), $env );
34 32
             Log::info('CP_SearchTDTicketJob: CP_TDinstance initialized with new JWT.');
35 33
           }
@@ -38,8 +36,7 @@  discard block
 block discarded – undo
38 36
           $userSession->s_token =  $this->request->token;
39 37
           $userSession->td_token = $TDinstance;
40 38
           $userSession->save();
41
-        }
42
-        else {
39
+        } else {
43 40
           Log::info('CP_SearchTDTicketJob: No user session.');
44 41
           Log::info('CP_SearchTDTicketJob: Creating new user session.');
45 42
           $TDinstance = new CP_TDinstance( env('TD_BEID'), env('TD_WEBSERVICESKEY'), env('TD_URLROOT'), env('TD_APPID'), $env );
@@ -58,8 +55,7 @@  discard block
 block discarded – undo
58 55
           $auth = true;
59 56
           $tickets = $TDinstance->searchTicketsName($this->request->text);
60 57
           $userSession->increment('td_searches');
61
-        }
62
-        else {
58
+        } else {
63 59
           Log::info('CP_SearchTDTicketJob: No token.');
64 60
           $auth = false;
65 61
           $tickets = null;
@@ -68,8 +64,7 @@  discard block
 block discarded – undo
68 64
         $opencount = 0;
69 65
         if (!count($tickets) && $auth) {
70 66
             return $this->respondToSlack("
Please login to merge, or discard this patch.
app/SlashCommandHandlers/Jobs/ShowTDTicketJob.php 3 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -90,17 +90,17 @@
 block discarded – undo
90 90
           $attachmentFields[] = AttachmentField::create('Date Opened', $date)->displaySideBySide();
91 91
 
92 92
             $this
93
-               ->respondToSlack("
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
     {
16 16
         $build = \Tremby\LaravelGitVersion\GitVersionHelper::getVersion();
17 17
 
18
-        if( env('TD_SANDBOX') == 'TRUE') {
18
+        if (env('TD_SANDBOX') == 'TRUE') {
19 19
           $env = 'sandbox';
20 20
         }
21 21
         else {
@@ -23,37 +23,37 @@  discard block
 block discarded – undo
23 23
         }
24 24
 
25 25
         $userSession = TDsession::where('s_user_id', $this->request->userId)->first();
26
-        if($userSession != null ) {
26
+        if ($userSession != null) {
27 27
           Log::info('CP_ShowTDTicketJob: Found user session.');
28
-          if($userSession->td_token){
29
-            $TDinstance = new CP_TDinstance( env('TD_BEID'), env('TD_WEBSERVICESKEY'), env('TD_URLROOT'), env('TD_APPID'), $env, (string)$userSession->td_token );
28
+          if ($userSession->td_token) {
29
+            $TDinstance = new CP_TDinstance(env('TD_BEID'), env('TD_WEBSERVICESKEY'), env('TD_URLROOT'), env('TD_APPID'), $env, (string)$userSession->td_token);
30 30
             Log::info('CP_ShowTDTicketJob: CP_TDinstance initialized with existing JWT.');
31 31
           }
32 32
           else {
33
-            $TDinstance = new CP_TDinstance( env('TD_BEID'), env('TD_WEBSERVICESKEY'), env('TD_URLROOT'), env('TD_APPID'), $env );
33
+            $TDinstance = new CP_TDinstance(env('TD_BEID'), env('TD_WEBSERVICESKEY'), env('TD_URLROOT'), env('TD_APPID'), $env);
34 34
             Log::info('CP_ShowTDTicketJob: CP_TDinstance initialized with new JWT.');
35 35
           }
36 36
 
37 37
           Log::info('CP_ShowTDTicketJob: Updating existing CP_TDsession s_token and td_token.');
38
-          $userSession->s_token =  $this->request->token;
38
+          $userSession->s_token = $this->request->token;
39 39
           $userSession->td_token = $TDinstance;
40 40
           $userSession->save();
41 41
         }
42 42
         else {
43 43
           Log::info('CP_ShowTDTicketJob: No user session.');
44 44
           Log::info('CP_ShowTDTicketJob: Creating new user session.');
45
-          $TDinstance = new CP_TDinstance( env('TD_BEID'), env('TD_WEBSERVICESKEY'), env('TD_URLROOT'), env('TD_APPID'), $env );
45
+          $TDinstance = new CP_TDinstance(env('TD_BEID'), env('TD_WEBSERVICESKEY'), env('TD_URLROOT'), env('TD_APPID'), $env);
46 46
           Log::info('CP_ShowTDTicketJob: New CP_TDinstance initialized.');
47 47
           $userSession = new TDsession;
48 48
           Log::info('CP_ShowTDTicketJob: New CP_TDsession initialized.');
49 49
           Log::info('CP_ShowTDTicketJob: Updating CP_TDsession s_token and td_token.');
50 50
           $userSession->s_user_id = $this->request->userId;
51
-          $userSession->s_token =  $this->request->token;
51
+          $userSession->s_token = $this->request->token;
52 52
           $userSession->td_token = $TDinstance;
53 53
           $userSession->save();
54 54
         }
55 55
 
56
-        if($TDinstance->checkToken()){
56
+        if ($TDinstance->checkToken()) {
57 57
           Log::info('CP_ShowTDTicketJob: There is a token.');
58 58
           $auth = true;
59 59
           $ticket = $TDinstance->ticket($this->request->text);
@@ -65,14 +65,14 @@  discard block
 block discarded – undo
65 65
         }
66 66
 
67 67
 
68
-        if($ticket && $auth) {
68
+        if ($ticket && $auth) {
69 69
           $date = date('F jS, Y', strtotime($ticket['CreatedDate']));
70 70
           $ticketURL = (string)$TDinstance->rootAppsUrl() . "Tickets/TicketDet?TicketID=" . $ticket['ID'];
71 71
           $assets = $TDinstance->searchAssets($ticket['ID']);
72 72
           $assetnames = "No Assets";
73 73
           $userSession->increment('td_tickets');
74 74
 
75
-          if(count($assets)){
75
+          if (count($assets)) {
76 76
             $assetnames = '';
77 77
             foreach ($assets as $asset) {
78 78
                 $assetnames = $assetnames . $asset['Name'] . ', ';
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
                ->displayResponseToEveryoneOnChannel()
103 103
                ->send();
104 104
         }
105
-        elseif(!$ticket && $auth) {
105
+        elseif (!$ticket && $auth) {
106 106
           $this->respondToSlack("
Please login to merge, or discard this patch.
Braces   +6 added lines, -12 removed lines patch added patch discarded remove patch
@@ -17,8 +17,7 @@  discard block
 block discarded – undo
17 17
 
18 18
         if( env('TD_SANDBOX') == 'TRUE') {
19 19
           $env = 'sandbox';
20
-        }
21
-        else {
20
+        } else {
22 21
           $env = 'prod';
23 22
         }
24 23
 
@@ -28,8 +27,7 @@  discard block
 block discarded – undo
28 27
           if($userSession->td_token){
29 28
             $TDinstance = new CP_TDinstance( env('TD_BEID'), env('TD_WEBSERVICESKEY'), env('TD_URLROOT'), env('TD_APPID'), $env, (string)$userSession->td_token );
30 29
             Log::info('CP_ShowTDTicketJob: CP_TDinstance initialized with existing JWT.');
31
-          }
32
-          else {
30
+          } else {
33 31
             $TDinstance = new CP_TDinstance( env('TD_BEID'), env('TD_WEBSERVICESKEY'), env('TD_URLROOT'), env('TD_APPID'), $env );
34 32
             Log::info('CP_ShowTDTicketJob: CP_TDinstance initialized with new JWT.');
35 33
           }
@@ -38,8 +36,7 @@  discard block
 block discarded – undo
38 36
           $userSession->s_token =  $this->request->token;
39 37
           $userSession->td_token = $TDinstance;
40 38
           $userSession->save();
41
-        }
42
-        else {
39
+        } else {
43 40
           Log::info('CP_ShowTDTicketJob: No user session.');
44 41
           Log::info('CP_ShowTDTicketJob: Creating new user session.');
45 42
           $TDinstance = new CP_TDinstance( env('TD_BEID'), env('TD_WEBSERVICESKEY'), env('TD_URLROOT'), env('TD_APPID'), $env );
@@ -57,8 +54,7 @@  discard block
 block discarded – undo
57 54
           Log::info('CP_ShowTDTicketJob: There is a token.');
58 55
           $auth = true;
59 56
           $ticket = $TDinstance->ticket($this->request->text);
60
-        }
61
-        else {
57
+        } else {
62 58
           Log::info('CP_ShowTDTicketJob: No token.');
63 59
           $auth = false;
64 60
           $ticket = null;
@@ -101,11 +97,9 @@  discard block
 block discarded – undo
101 97
                )
102 98
                ->displayResponseToEveryoneOnChannel()
103 99
                ->send();
104
-        }
105
-        elseif(!$ticket && $auth) {
100
+        } elseif(!$ticket && $auth) {
106 101
           $this->respondToSlack("
Please login to merge, or discard this patch.
app/SlashCommandHandlers/ShowTDTicket.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -21,9 +21,9 @@  discard block
 block discarded – undo
21 21
     {
22 22
         Log::info('CP_ShowTDTicket: canHandle method called.');
23 23
         Log::info('CP_ShowTDTicket: Request type is ' . gettype($request) . '.');
24
-        if($request->command) {
24
+        if ($request->command) {
25 25
           Log::info('CP_ShowTDTicket: Given command ' . $request->command . '.');
26
-          if($request->text == 'help' || $request->text == 'Help') {
26
+          if ($request->text == 'help' || $request->text == 'Help') {
27 27
             Log::info('CP_ShowTDTicket: User is requesting help. Stepping aside.');
28 28
             return false;
29 29
           }
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
      */
47 47
     public function handle(Request $request): Response
48 48
     {
49
-        if(is_numeric($request->text)) {
49
+        if (is_numeric($request->text)) {
50 50
           $this->dispatch(new ShowTDTicketJob());
51 51
           return $this->respondToSlack("One moment please…");
52 52
         }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -28,8 +28,7 @@  discard block
 block discarded – undo
28 28
             return false;
29 29
           }
30 30
           return true;
31
-        }
32
-        else {
31
+        } else {
33 32
           Log::info('CP_ShowTDTicket: Not given a command, canHandle returning false.');
34 33
           return false;
35 34
         }
@@ -49,8 +48,7 @@  discard block
 block discarded – undo
49 48
         if(is_numeric($request->text)) {
50 49
           $this->dispatch(new ShowTDTicketJob());
51 50
           return $this->respondToSlack("One moment please…");
52
-        }
53
-        else {
51
+        } else {
54 52
           $this->dispatch(new SearchTDTicketJob());
55 53
           return $this->respondToSlack("One moment please…");
56 54
         }
Please login to merge, or discard this patch.
app/Traits/Encryptable.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 
12 12
         if (in_array($key, $this->encryptable)) {
13 13
           try {
14
-            if($value){
14
+            if ($value) {
15 15
               $value = Crypt::decrypt($value);
16 16
             }
17 17
           } catch (DecryptException $e) {
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
     public function setAttribute($key, $value)
27 27
     {
28 28
         if (in_array($key, $this->encryptable)) {
29
-          if($value) {
29
+          if ($value) {
30 30
             $value = Crypt::encrypt($value);
31 31
           }
32 32
         }
Please login to merge, or discard this patch.
app/Http/Controllers/SlackButtonController.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -11,13 +11,13 @@  discard block
 block discarded – undo
11 11
       Log::info('CP_SlackButtonController: processBtn method called.');
12 12
       Log::info('CP_SlackButtonController: Request type is ' . gettype($request) . '.');
13 13
       $data = json_decode($request['payload']);
14
-      if($data) {
14
+      if ($data) {
15 15
         Log::info('CP_SlackButtonController: Controller was given data.');
16 16
       }
17 17
       else {
18 18
         Log::info('CP_SlackButtonController: Controller was called, but no data given.');
19 19
       }
20
-      if($data->token == env('SLACK_SLASH_COMMAND_VERIFICATION_TOKEN')) {
20
+      if ($data->token == env('SLACK_SLASH_COMMAND_VERIFICATION_TOKEN')) {
21 21
         Log::info('CP_SlackButtonController: Token verified. Proceeding.');
22 22
         $this->buttonResponse($data);
23 23
       }
@@ -28,16 +28,16 @@  discard block
 block discarded – undo
28 28
 
29 29
     private function buttonResponse($data) {
30 30
       Log::info('CP_SlackButtonController: buttonResponse method called.');
31
-      $ch = curl_init( $data->response_url );
31
+      $ch = curl_init($data->response_url);
32 32
       $payload = '{"text":"One moment please…"}';
33
-      curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
34
-      curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
35
-      curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
33
+      curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
34
+      curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
35
+      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
36 36
       $result = curl_exec($ch);
37 37
       curl_close($ch);
38 38
 
39 39
       $userSession = TDsession::where('s_user_id', $data->user->id)->first();
40
-      if($userSession != null ) {
40
+      if ($userSession != null) {
41 41
         Log::info('CP_SlackButtonController: Found user session.');
42 42
         $userSession->increment('s_showtickets');
43 43
       }
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
         Log::info('CP_SlackButtonController: New CP_TDsession initialized.');
49 49
         Log::info('CP_SlackButtonController: Updating CP_TDsession s_user_id and s_token.');
50 50
         $userSession->s_user_id = $data->user->id;
51
-        $userSession->s_token =  $data->token;
51
+        $userSession->s_token = $data->token;
52 52
         $userSession->save();
53 53
 
54 54
         $userSession->increment('s_showtickets');
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -13,15 +13,13 @@  discard block
 block discarded – undo
13 13
       $data = json_decode($request['payload']);
14 14
       if($data) {
15 15
         Log::info('CP_SlackButtonController: Controller was given data.');
16
-      }
17
-      else {
16
+      } else {
18 17
         Log::info('CP_SlackButtonController: Controller was called, but no data given.');
19 18
       }
20 19
       if($data->token == env('SLACK_SLASH_COMMAND_VERIFICATION_TOKEN')) {
21 20
         Log::info('CP_SlackButtonController: Token verified. Proceeding.');
22 21
         $this->buttonResponse($data);
23
-      }
24
-      else {
22
+      } else {
25 23
         Log::info('CP_SlackButtonController: Token did not pass verification.');
26 24
       }
27 25
     }
@@ -40,8 +38,7 @@  discard block
 block discarded – undo
40 38
       if($userSession != null ) {
41 39
         Log::info('CP_SlackButtonController: Found user session.');
42 40
         $userSession->increment('s_showtickets');
43
-      }
44
-      else {
41
+      } else {
45 42
         Log::info('CP_SlackButtonController: No user session.');
46 43
         Log::info('CP_SlackButtonController: Creating new user session.');
47 44
         $userSession = new TDsession;
Please login to merge, or discard this patch.
app/Providers/AppServiceProvider.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,8 +14,8 @@
 block discarded – undo
14 14
      */
15 15
     public function boot()
16 16
     {
17
-		//Fix Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
18
-       // Schema::defaultStringLength(191);
17
+    //Fix Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
18
+        // Schema::defaultStringLength(191);
19 19
     }
20 20
 
21 21
     /**
Please login to merge, or discard this patch.
app/Providers/RouteServiceProvider.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
     protected function mapWebRoutes()
53 53
     {
54 54
         Route::middleware('web')
55
-             ->namespace($this->namespace)
56
-             ->group(base_path('routes/web.php'));
55
+              ->namespace($this->namespace)
56
+              ->group(base_path('routes/web.php'));
57 57
     }
58 58
 
59 59
     /**
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
     protected function mapApiRoutes()
67 67
     {
68 68
         Route::prefix('api')
69
-             ->middleware('api')
70
-             ->namespace($this->namespace)
71
-             ->group(base_path('routes/api.php'));
69
+              ->middleware('api')
70
+              ->namespace($this->namespace)
71
+              ->group(base_path('routes/api.php'));
72 72
     }
73 73
 }
Please login to merge, or discard this patch.
app/Classes/CP_TDinstance.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
     public function __construct() {
18 18
       $a = func_get_args();
19 19
       $i = func_num_args();
20
-      if (method_exists($this,$f='__construct'.$i)) {
21
-          call_user_func_array(array($this,$f),$a);
20
+      if (method_exists($this, $f = '__construct' . $i)) {
21
+          call_user_func_array(array($this, $f), $a);
22 22
       }
23 23
     }
24 24
 
@@ -64,17 +64,17 @@  discard block
 block discarded – undo
64 64
       }
65 65
     }
66 66
 
67
-    private function authorize($b, $w, $u){
67
+    private function authorize($b, $w, $u) {
68 68
       Log::info('CP_TDauth: authorize method called.');
69 69
       Log::info('CP_TDauth: authorize requesting at [' . $u . 'auth/loginadmin].');
70
-      $ch = curl_init( $u . 'auth/loginadmin');
71
-      $payload = json_encode( array( "BEID" => $b, "WebServicesKey" => $w ) );
72
-      curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
73
-      curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
74
-      curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
70
+      $ch = curl_init($u . 'auth/loginadmin');
71
+      $payload = json_encode(array("BEID" => $b, "WebServicesKey" => $w));
72
+      curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
73
+      curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
74
+      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
75 75
       $bearer = curl_exec($ch);
76 76
       curl_close($ch);
77
-      if(!$bearer) {
77
+      if (!$bearer) {
78 78
         Log::info('CP_TDauth: Authorization failed.');
79 79
       }
80 80
       else {
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 
89 89
     public function checkToken() {
90 90
       Log::info('CP_TDauth: checkToken method called.');
91
-      if($this->authstring) {
91
+      if ($this->authstring) {
92 92
         if (($this->expires - time()) <= 10) {
93 93
           $this->authorize($this->BEID, $this->WebServicesKey, $this->urlroot);
94 94
           Log::info('CP_TDauth: Token was expired. Replaced with new token.');
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
     Log::info('CP_TDinstance: connect method called.');
125 125
     $this->checkToken();
126 126
     $ch = curl_init($this->urlroot . $point);
127
-    curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json', $this->authstring));
128
-    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
127
+    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json', $this->authstring));
128
+    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
129 129
     if ($type == 'post') {
130 130
       Log::info('CP_TDinstance: connect method POST.');
131 131
       curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
@@ -161,12 +161,12 @@  discard block
 block discarded – undo
161 161
     Log::info('CP_TDinstance: searchTicketsName method called.');
162 162
     $flag = $this->flagCheck($search);
163 163
 
164
-    if(!$flag) {
164
+    if (!$flag) {
165 165
       $people = $this->searchPeople($search);
166 166
       foreach ($people as $person) {
167 167
         $uids[] = $person['UID'];
168 168
       }
169
-      if(isset($uids)) {
169
+      if (isset($uids)) {
170 170
         $tickets = $this->searchResponsibility($uids);
171 171
         return $tickets;
172 172
       }
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
       }
176 176
     }
177 177
     else {
178
-      if($flag = '-r') {
178
+      if ($flag = '-r') {
179 179
         $data = array("RequestorNameSearch" => substr($search, 0, -3));
180 180
         $data_string = json_encode($data);
181 181
         $tickets = $this->connect('post', $this->appid . '/tickets/search', $data_string);
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 
207 207
   public function searchResponsibility($search) {
208 208
     Log::info('CP_TDinstance: searchResponsibility method called.');
209
-    if (! is_array($search)) {
209
+    if (!is_array($search)) {
210 210
       $search = array((string)$search);
211 211
     }
212 212
     $ResponsibilityUids = $search;
Please login to merge, or discard this patch.
Braces   +9 added lines, -18 removed lines patch added patch discarded remove patch
@@ -56,8 +56,7 @@  discard block
 block discarded – undo
56 56
         Log::info('CP_TDauth: Setup for production.');
57 57
         $this->urlroot = $u . 'TDWebApi/api/';
58 58
         $this->appsroot = $u . 'TDNext/Apps/';
59
-      }
60
-      elseif ($e == 'sandbox') {
59
+      } elseif ($e == 'sandbox') {
61 60
         Log::info('CP_TDauth: Setup for sandbox.');
62 61
         $this->urlroot = $u . 'SBTDWebApi/api/';
63 62
         $this->appsroot = $u . 'SBTDNext/Apps/';
@@ -76,8 +75,7 @@  discard block
 block discarded – undo
76 75
       curl_close($ch);
77 76
       if(!$bearer) {
78 77
         Log::info('CP_TDauth: Authorization failed.');
79
-      }
80
-      else {
78
+      } else {
81 79
         Log::info('CP_TDauth: Authorization successful.');
82 80
         list($JWTheader, $JWTpayload, $JWTsig) = explode('.', $bearer);
83 81
         $this->auth = $bearer;
@@ -92,14 +90,12 @@  discard block
 block discarded – undo
92 90
         if (($this->expires - time()) <= 10) {
93 91
           $this->authorize($this->BEID, $this->WebServicesKey, $this->urlroot);
94 92
           Log::info('CP_TDauth: Token was expired. Replaced with new token.');
95
-        }
96
-        else {
93
+        } else {
97 94
           $remain = $this->expires - time();
98 95
           Log::info('CP_TDauth: Token ok, time remaining: ' . $remain);
99 96
         }
100 97
         return true;
101
-      }
102
-      else {
98
+      } else {
103 99
         Log::info('CP_TDauth: No token.');
104 100
         return false;
105 101
       }
@@ -130,8 +126,7 @@  discard block
 block discarded – undo
130 126
       Log::info('CP_TDinstance: connect method POST.');
131 127
       curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
132 128
       curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
133
-    }
134
-    else {
129
+    } else {
135 130
       Log::info('CP_TDinstance: connect method GET.');
136 131
     }
137 132
     $result = curl_exec($ch);
@@ -145,8 +140,7 @@  discard block
 block discarded – undo
145 140
       $flag = substr($check, 1, 2);
146 141
       Log::info('CP_TDinstance: flagCheck given flag ' . $flag);
147 142
       return $flag;
148
-    }
149
-    else {
143
+    } else {
150 144
       return null;
151 145
     }
152 146
   }
@@ -169,19 +163,16 @@  discard block
 block discarded – undo
169 163
       if(isset($uids)) {
170 164
         $tickets = $this->searchResponsibility($uids);
171 165
         return $tickets;
172
-      }
173
-      else {
166
+      } else {
174 167
         return null;
175 168
       }
176
-    }
177
-    else {
169
+    } else {
178 170
       if($flag = '-r') {
179 171
         $data = array("RequestorNameSearch" => substr($search, 0, -3));
180 172
         $data_string = json_encode($data);
181 173
         $tickets = $this->connect('post', $this->appid . '/tickets/search', $data_string);
182 174
         return $tickets;
183
-      }
184
-      else {
175
+      } else {
185 176
         return null;
186 177
       }
187 178
     }
Please login to merge, or discard this patch.