Passed
Branch master (b06f51)
by John
02:28
created
src/InboxController.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -24,10 +24,10 @@
 block discarded – undo
24 24
     {
25 25
         $conversations = $this->inboxService->fetchAllConversation();
26 26
 
27
-      $users = $this->inboxService->getInboxUsers($conversations);
27
+        $users = $this->inboxService->getInboxUsers($conversations);
28 28
 
29 29
 
30
-     return view('inbox::inbox.index', compact('conversations', 'users'));
30
+        return view('inbox::inbox.index', compact('conversations', 'users'));
31 31
     }
32 32
     /**
33 33
      * Show the form for creating a new resource.
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
      */
66 66
     public function show(Conversation $id)
67 67
     {
68
-        if(auth()->id() == $id->id_to OR auth()->id() == $id->id_from) {
68
+        if (auth()->id() == $id->id_to OR auth()->id() == $id->id_from) {
69 69
             return view('inbox::inbox.show')->with('conversation', $id);
70 70
         }
71 71
         return redirect()->back();
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
                 'message' => 'required|max:10000'
87 87
             ]
88 88
         );
89
-        if(auth()->id() == $id->id_to OR auth()->id() == $id->id_from) {
89
+        if (auth()->id() == $id->id_to OR auth()->id() == $id->id_from) {
90 90
 
91 91
             $this->inboxService->addMessage($request, $id);
92 92
         }
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
      */
102 102
     public function destroy(Conversation $id)
103 103
     {
104
-        if(auth()->id() == $id->id_to OR auth()->id() == $id->id_from) {
104
+        if (auth()->id() == $id->id_to OR auth()->id() == $id->id_from) {
105 105
 
106 106
             $this->inboxService->deleteConversation($id);
107 107
         }
Please login to merge, or discard this patch.
src/Repository/InboxRepository.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@
 block discarded – undo
14 14
 
15 15
 class InboxRepository
16 16
 {
17
-	public function fetchAll()
17
+    public function fetchAll()
18 18
     {
19 19
         return Conversation::where('id_from', auth()->id())->orderBy('id', 'desc')->orWhere('id_to', auth()->id())->orderBy('id', 'desc')->get()->groupBy(function ($data){
20 20
             return Carbon::parse($data->created_at)->format('Y-m-d');
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 {
17 17
 	public function fetchAll()
18 18
     {
19
-        return Conversation::where('id_from', auth()->id())->orderBy('id', 'desc')->orWhere('id_to', auth()->id())->orderBy('id', 'desc')->get()->groupBy(function ($data){
19
+        return Conversation::where('id_from', auth()->id())->orderBy('id', 'desc')->orWhere('id_to', auth()->id())->orderBy('id', 'desc')->get()->groupBy(function($data) {
20 20
             return Carbon::parse($data->created_at)->format('Y-m-d');
21 21
         });
22 22
     }
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
     public function conversationExists($to, $from)
34 34
     {
35 35
         //prevent to pm yourself
36
-        if(auth()->user()->name == $to->name){
36
+        if (auth()->user()->name == $to->name) {
37 37
             return true;
38 38
         }
39 39
         //check if conversation already exists
Please login to merge, or discard this patch.
src/InboxServiceProvider.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@
 block discarded – undo
14 14
     public function boot()
15 15
     {
16 16
         include __DIR__.'/routes.php';
17
-          $this->publishes([
17
+            $this->publishes([
18 18
             __DIR__ . '/migrations' => $this->app->databasePath() . '/migrations'
19 19
         ], 'migrations');
20 20
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@
 block discarded – undo
15 15
     {
16 16
         include __DIR__.'/routes.php';
17 17
           $this->publishes([
18
-            __DIR__ . '/migrations' => $this->app->databasePath() . '/migrations'
18
+            __DIR__.'/migrations' => $this->app->databasePath().'/migrations'
19 19
         ], 'migrations');
20 20
 
21 21
     }
Please login to merge, or discard this patch.
src/Conversation.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
6 6
 
7 7
 class Conversation extends Model
8 8
 {
9
-    public function messages(){
9
+    public function messages() {
10 10
         return $this->hasMany('Evilnet\Inbox\Messages');
11 11
     }
12 12
 }
Please login to merge, or discard this patch.
src/Services/InboxService.php 3 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
         $a->message = $request->get('message');
31 31
         $a->conversation_id = $request->get('conv_id');
32 32
         $a->save();
33
-         return redirect()->back()->send();
33
+            return redirect()->back()->send();
34 34
     }
35 35
 
36 36
     public function addConversation($user,$messg,$subject){
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
         }
57 57
         }
58 58
         else{
59
-         return redirect()->back()->withErrors('User not found')->send();
59
+            return redirect()->back()->withErrors('User not found')->send();
60 60
         }
61 61
     }
62 62
     public  function fetchAllConversation(){
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 use Evilnet\Inbox\Repository\InboxRepository;
13 13
 use Evilnet\Inbox\User;
14 14
 
15
-class InboxService{
15
+class InboxService {
16 16
 
17 17
     protected $inboxRepository;
18 18
     function __construct(InboxRepository $inboxRepository)
@@ -20,8 +20,8 @@  discard block
 block discarded – undo
20 20
         $this->inboxRepository = $inboxRepository;
21 21
     }
22 22
 
23
-    public function addMessage($request, $id){
24
-        if($request->get('conv_id') != $id->id){
23
+    public function addMessage($request, $id) {
24
+        if ($request->get('conv_id') != $id->id) {
25 25
             redirect()->back()->withErrors('Something went wrong...')->send();
26 26
         }
27 27
 
@@ -33,12 +33,12 @@  discard block
 block discarded – undo
33 33
          return redirect()->back()->send();
34 34
     }
35 35
 
36
-    public function addConversation($user,$messg,$subject){
36
+    public function addConversation($user, $messg, $subject) {
37 37
 
38
-        if($this->inboxRepository->userExists($user)){
38
+        if ($this->inboxRepository->userExists($user)) {
39 39
             $from = auth()->id();
40 40
             $to = User::where('name', $user)->first();
41
-            if(!$this->inboxRepository->conversationExists($to,$from)){
41
+            if (!$this->inboxRepository->conversationExists($to, $from)) {
42 42
                 $message = new Messages();
43 43
                 $message->name = auth()->user()->name;
44 44
                 $message->message = $messg;
@@ -51,21 +51,21 @@  discard block
 block discarded – undo
51 51
                 $message->save();
52 52
                 return redirect()->to(url('/').'/conversation/'.$conversation->id)->send();
53 53
             }
54
-        else{
54
+        else {
55 55
                 return redirect()->back()->withErrors('Conversation already exists')->send();
56 56
         }
57 57
         }
58
-        else{
58
+        else {
59 59
          return redirect()->back()->withErrors('User not found')->send();
60 60
         }
61 61
     }
62
-    public  function fetchAllConversation(){
62
+    public  function fetchAllConversation() {
63 63
         return $this->inboxRepository->fetchAll();
64 64
     }
65 65
 
66
-    public  function deleteConversation($conversation){
66
+    public  function deleteConversation($conversation) {
67 67
         //it will delete conversation row and all related rows in messages table
68
-        foreach ($conversation->messages as $messages){
68
+        foreach ($conversation->messages as $messages) {
69 69
             $messages->forceDelete();
70 70
         }
71 71
         $conversation->forceDelete();
@@ -74,14 +74,14 @@  discard block
 block discarded – undo
74 74
 
75 75
     }
76 76
     //return array with users that match to display for logged user
77
-        public function getInboxUsers($conversations){
77
+        public function getInboxUsers($conversations) {
78 78
             $users = [];
79
-            foreach ($conversations as $date => $thread){
80
-                foreach ($thread as $conversation){
81
-                    if( auth()->id() == $conversation->id_to) {
79
+            foreach ($conversations as $date => $thread) {
80
+                foreach ($thread as $conversation) {
81
+                    if (auth()->id() == $conversation->id_to) {
82 82
                         $users[] = \Evilnet\Inbox\User::where('id', $conversation->id_from)->first();
83 83
                     }
84
-                    elseif(auth()->id() == $conversation->id_from)
84
+                    elseif (auth()->id() == $conversation->id_from)
85 85
                         $users[] = \Evilnet\Inbox\User::where('id', $conversation->id_to)->first();
86 86
                 }
87 87
             }
Please login to merge, or discard this patch.
Braces   +4 added lines, -6 removed lines patch added patch discarded remove patch
@@ -50,12 +50,10 @@  discard block
 block discarded – undo
50 50
                 $message->conversation_id = $conversation->id;
51 51
                 $message->save();
52 52
                 return redirect()->to(url('/').'/conversation/'.$conversation->id)->send();
53
-            }
54
-        else{
53
+            } else{
55 54
                 return redirect()->back()->withErrors('Conversation already exists')->send();
56 55
         }
57
-        }
58
-        else{
56
+        } else{
59 57
          return redirect()->back()->withErrors('User not found')->send();
60 58
         }
61 59
     }
@@ -80,9 +78,9 @@  discard block
 block discarded – undo
80 78
                 foreach ($thread as $conversation){
81 79
                     if( auth()->id() == $conversation->id_to) {
82 80
                         $users[] = \Evilnet\Inbox\User::where('id', $conversation->id_from)->first();
81
+                    } elseif(auth()->id() == $conversation->id_from) {
82
+                                            $users[] = \Evilnet\Inbox\User::where('id', $conversation->id_to)->first();
83 83
                     }
84
-                    elseif(auth()->id() == $conversation->id_from)
85
-                        $users[] = \Evilnet\Inbox\User::where('id', $conversation->id_to)->first();
86 84
                 }
87 85
             }
88 86
             return $users;
Please login to merge, or discard this patch.
src/routes.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@
 block discarded – undo
5 5
  * Date: 09.07.2017
6 6
  * Time: 19:37
7 7
  */
8
-Route::group(['middleware' => ['web', 'auth']], function () {
8
+Route::group(['middleware' => ['web', 'auth']], function() {
9 9
     Route::get('conversation', 'Evilnet\Inbox\InboxController@create');
10 10
     Route::post('conversation', 'Evilnet\Inbox\InboxController@store');
11 11
     Route::get('conversation/{id}', 'Evilnet\Inbox\InboxController@show');
Please login to merge, or discard this patch.
src/migrations/2017_07_06_200205_create_conversations_table.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
      */
14 14
     public function up()
15 15
     {
16
-        Schema::create('conversations', function (Blueprint $table) {
16
+        Schema::create('conversations', function(Blueprint $table) {
17 17
             $table->increments('id');
18 18
             $table->text('subject');
19 19
             $table->integer('id_from');
Please login to merge, or discard this patch.
src/migrations/2017_07_06_200352_create_messages_table.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
      */
14 14
     public function up()
15 15
     {
16
-        Schema::create('messages', function (Blueprint $table) {
16
+        Schema::create('messages', function(Blueprint $table) {
17 17
             $table->increments('id');
18 18
             $table->text('name');
19 19
             $table->text('message');
Please login to merge, or discard this patch.